1+ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
12; Test that the strcmp library call simplifier works correctly.
23; RUN: opt < %s -instcombine -S | FileCheck %s
34
@@ -13,10 +14,11 @@ declare i32 @strcmp(i8*, i8*)
1314; strcmp("", x) -> -*x
1415define arm_aapcscc i32 @test1 (i8* %str2 ) {
1516; CHECK-LABEL: @test1(
16- ; CHECK: %strcmpload = load i8, i8* %str
17- ; CHECK: %1 = zext i8 %strcmpload to i32
18- ; CHECK: %2 = sub nsw i32 0, %1
19- ; CHECK: ret i32 %2
17+ ; CHECK-NEXT: [[STRCMPLOAD:%.*]] = load i8, i8* [[STR2:%.*]], align 1
18+ ; CHECK-NEXT: [[TMP1:%.*]] = zext i8 [[STRCMPLOAD]] to i32
19+ ; CHECK-NEXT: [[TMP2:%.*]] = sub nsw i32 0, [[TMP1]]
20+ ; CHECK-NEXT: ret i32 [[TMP2]]
21+ ;
2022
2123 %str1 = getelementptr inbounds [1 x i8 ], [1 x i8 ]* @null , i32 0 , i32 0
2224 %temp1 = call arm_apcscc i32 @strcmp (i8* %str1 , i8* %str2 )
@@ -27,9 +29,10 @@ define arm_aapcscc i32 @test1(i8* %str2) {
2729; strcmp(x, "") -> *x
2830define arm_aapcscc i32 @test2 (i8* %str1 ) {
2931; CHECK-LABEL: @test2(
30- ; CHECK: %strcmpload = load i8, i8* %str
31- ; CHECK: %1 = zext i8 %strcmpload to i32
32- ; CHECK: ret i32 %1
32+ ; CHECK-NEXT: [[STRCMPLOAD:%.*]] = load i8, i8* [[STR1:%.*]], align 1
33+ ; CHECK-NEXT: [[TMP1:%.*]] = zext i8 [[STRCMPLOAD]] to i32
34+ ; CHECK-NEXT: ret i32 [[TMP1]]
35+ ;
3336
3437 %str2 = getelementptr inbounds [1 x i8 ], [1 x i8 ]* @null , i32 0 , i32 0
3538 %temp1 = call arm_aapcscc i32 @strcmp (i8* %str1 , i8* %str2 )
@@ -39,7 +42,8 @@ define arm_aapcscc i32 @test2(i8* %str1) {
3942; strcmp(x, y) -> cnst
4043define arm_aapcscc i32 @test3 () {
4144; CHECK-LABEL: @test3(
42- ; CHECK: ret i32 -1
45+ ; CHECK-NEXT: ret i32 -1
46+ ;
4347
4448 %str1 = getelementptr inbounds [5 x i8 ], [5 x i8 ]* @hell , i32 0 , i32 0
4549 %str2 = getelementptr inbounds [6 x i8 ], [6 x i8 ]* @hello , i32 0 , i32 0
@@ -49,7 +53,8 @@ define arm_aapcscc i32 @test3() {
4953
5054define arm_aapcscc i32 @test4 () {
5155; CHECK-LABEL: @test4(
52- ; CHECK: ret i32 1
56+ ; CHECK-NEXT: ret i32 1
57+ ;
5358
5459 %str1 = getelementptr inbounds [5 x i8 ], [5 x i8 ]* @hell , i32 0 , i32 0
5560 %str2 = getelementptr inbounds [1 x i8 ], [1 x i8 ]* @null , i32 0 , i32 0
@@ -61,8 +66,10 @@ define arm_aapcscc i32 @test4() {
6166; (This transform is rather difficult to trigger in a useful manner)
6267define arm_aapcscc i32 @test5 (i1 %b ) {
6368; CHECK-LABEL: @test5(
64- ; CHECK: %memcmp = call i32 @memcmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @hello, i32 0, i32 0), i8* %str2, i32 5)
65- ; CHECK: ret i32 %memcmp
69+ ; CHECK-NEXT: [[STR2:%.*]] = select i1 [[B:%.*]], i8* getelementptr inbounds ([5 x i8], [5 x i8]* @hell, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @bell, i32 0, i32 0)
70+ ; CHECK-NEXT: [[MEMCMP:%.*]] = call i32 @memcmp(i8* dereferenceable(5) getelementptr inbounds ([6 x i8], [6 x i8]* @hello, i32 0, i32 0), i8* dereferenceable(5) [[STR2]], i32 5)
71+ ; CHECK-NEXT: ret i32 [[MEMCMP]]
72+ ;
6673
6774 %str1 = getelementptr inbounds [6 x i8 ], [6 x i8 ]* @hello , i32 0 , i32 0
6875 %temp1 = getelementptr inbounds [5 x i8 ], [5 x i8 ]* @hell , i32 0 , i32 0
@@ -75,7 +82,8 @@ define arm_aapcscc i32 @test5(i1 %b) {
7582; strcmp(x,x) -> 0
7683define arm_aapcscc i32 @test6 (i8* %str ) {
7784; CHECK-LABEL: @test6(
78- ; CHECK: ret i32 0
85+ ; CHECK-NEXT: ret i32 0
86+ ;
7987
8088 %temp1 = call arm_aapcscc i32 @strcmp (i8* %str , i8* %str )
8189 ret i32 %temp1
@@ -84,10 +92,11 @@ define arm_aapcscc i32 @test6(i8* %str) {
8492; strcmp("", x) -> -*x
8593define arm_aapcs_vfpcc i32 @test1_vfp (i8* %str2 ) {
8694; CHECK-LABEL: @test1_vfp(
87- ; CHECK: %strcmpload = load i8, i8* %str
88- ; CHECK: %1 = zext i8 %strcmpload to i32
89- ; CHECK: %2 = sub nsw i32 0, %1
90- ; CHECK: ret i32 %2
95+ ; CHECK-NEXT: [[STRCMPLOAD:%.*]] = load i8, i8* [[STR2:%.*]], align 1
96+ ; CHECK-NEXT: [[TMP1:%.*]] = zext i8 [[STRCMPLOAD]] to i32
97+ ; CHECK-NEXT: [[TMP2:%.*]] = sub nsw i32 0, [[TMP1]]
98+ ; CHECK-NEXT: ret i32 [[TMP2]]
99+ ;
91100
92101 %str1 = getelementptr inbounds [1 x i8 ], [1 x i8 ]* @null , i32 0 , i32 0
93102 %temp1 = call arm_aapcs_vfpcc i32 @strcmp (i8* %str1 , i8* %str2 )
@@ -98,9 +107,10 @@ define arm_aapcs_vfpcc i32 @test1_vfp(i8* %str2) {
98107; strcmp(x, "") -> *x
99108define arm_aapcs_vfpcc i32 @test2_vfp (i8* %str1 ) {
100109; CHECK-LABEL: @test2_vfp(
101- ; CHECK: %strcmpload = load i8, i8* %str
102- ; CHECK: %1 = zext i8 %strcmpload to i32
103- ; CHECK: ret i32 %1
110+ ; CHECK-NEXT: [[STRCMPLOAD:%.*]] = load i8, i8* [[STR1:%.*]], align 1
111+ ; CHECK-NEXT: [[TMP1:%.*]] = zext i8 [[STRCMPLOAD]] to i32
112+ ; CHECK-NEXT: ret i32 [[TMP1]]
113+ ;
104114
105115 %str2 = getelementptr inbounds [1 x i8 ], [1 x i8 ]* @null , i32 0 , i32 0
106116 %temp1 = call arm_aapcs_vfpcc i32 @strcmp (i8* %str1 , i8* %str2 )
@@ -110,7 +120,8 @@ define arm_aapcs_vfpcc i32 @test2_vfp(i8* %str1) {
110120; strcmp(x, y) -> cnst
111121define arm_aapcs_vfpcc i32 @test3_vfp () {
112122; CHECK-LABEL: @test3_vfp(
113- ; CHECK: ret i32 -1
123+ ; CHECK-NEXT: ret i32 -1
124+ ;
114125
115126 %str1 = getelementptr inbounds [5 x i8 ], [5 x i8 ]* @hell , i32 0 , i32 0
116127 %str2 = getelementptr inbounds [6 x i8 ], [6 x i8 ]* @hello , i32 0 , i32 0
@@ -120,7 +131,8 @@ define arm_aapcs_vfpcc i32 @test3_vfp() {
120131
121132define arm_aapcs_vfpcc i32 @test4_vfp () {
122133; CHECK-LABEL: @test4_vfp(
123- ; CHECK: ret i32 1
134+ ; CHECK-NEXT: ret i32 1
135+ ;
124136
125137 %str1 = getelementptr inbounds [5 x i8 ], [5 x i8 ]* @hell , i32 0 , i32 0
126138 %str2 = getelementptr inbounds [1 x i8 ], [1 x i8 ]* @null , i32 0 , i32 0
@@ -132,8 +144,10 @@ define arm_aapcs_vfpcc i32 @test4_vfp() {
132144; (This transform is rather difficult to trigger in a useful manner)
133145define arm_aapcs_vfpcc i32 @test5_vfp (i1 %b ) {
134146; CHECK-LABEL: @test5_vfp(
135- ; CHECK: %memcmp = call i32 @memcmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @hello, i32 0, i32 0), i8* %str2, i32 5)
136- ; CHECK: ret i32 %memcmp
147+ ; CHECK-NEXT: [[STR2:%.*]] = select i1 [[B:%.*]], i8* getelementptr inbounds ([5 x i8], [5 x i8]* @hell, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @bell, i32 0, i32 0)
148+ ; CHECK-NEXT: [[MEMCMP:%.*]] = call i32 @memcmp(i8* dereferenceable(5) getelementptr inbounds ([6 x i8], [6 x i8]* @hello, i32 0, i32 0), i8* dereferenceable(5) [[STR2]], i32 5)
149+ ; CHECK-NEXT: ret i32 [[MEMCMP]]
150+ ;
137151
138152 %str1 = getelementptr inbounds [6 x i8 ], [6 x i8 ]* @hello , i32 0 , i32 0
139153 %temp1 = getelementptr inbounds [5 x i8 ], [5 x i8 ]* @hell , i32 0 , i32 0
@@ -146,7 +160,8 @@ define arm_aapcs_vfpcc i32 @test5_vfp(i1 %b) {
146160; strcmp(x,x) -> 0
147161define arm_aapcs_vfpcc i32 @test6_vfp (i8* %str ) {
148162; CHECK-LABEL: @test6_vfp(
149- ; CHECK: ret i32 0
163+ ; CHECK-NEXT: ret i32 0
164+ ;
150165
151166 %temp1 = call arm_aapcs_vfpcc i32 @strcmp (i8* %str , i8* %str )
152167 ret i32 %temp1
0 commit comments