1
+ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1
2
; Test that the strcmp library call simplifier works correctly.
2
3
; RUN: opt < %s -instcombine -S | FileCheck %s
3
4
@@ -13,10 +14,11 @@ declare i32 @strcmp(i8*, i8*)
13
14
; strcmp("", x) -> -*x
14
15
define arm_aapcscc i32 @test1 (i8* %str2 ) {
15
16
; 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
+ ;
20
22
21
23
%str1 = getelementptr inbounds [1 x i8 ], [1 x i8 ]* @null , i32 0 , i32 0
22
24
%temp1 = call arm_apcscc i32 @strcmp (i8* %str1 , i8* %str2 )
@@ -27,9 +29,10 @@ define arm_aapcscc i32 @test1(i8* %str2) {
27
29
; strcmp(x, "") -> *x
28
30
define arm_aapcscc i32 @test2 (i8* %str1 ) {
29
31
; 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
+ ;
33
36
34
37
%str2 = getelementptr inbounds [1 x i8 ], [1 x i8 ]* @null , i32 0 , i32 0
35
38
%temp1 = call arm_aapcscc i32 @strcmp (i8* %str1 , i8* %str2 )
@@ -39,7 +42,8 @@ define arm_aapcscc i32 @test2(i8* %str1) {
39
42
; strcmp(x, y) -> cnst
40
43
define arm_aapcscc i32 @test3 () {
41
44
; CHECK-LABEL: @test3(
42
- ; CHECK: ret i32 -1
45
+ ; CHECK-NEXT: ret i32 -1
46
+ ;
43
47
44
48
%str1 = getelementptr inbounds [5 x i8 ], [5 x i8 ]* @hell , i32 0 , i32 0
45
49
%str2 = getelementptr inbounds [6 x i8 ], [6 x i8 ]* @hello , i32 0 , i32 0
@@ -49,7 +53,8 @@ define arm_aapcscc i32 @test3() {
49
53
50
54
define arm_aapcscc i32 @test4 () {
51
55
; CHECK-LABEL: @test4(
52
- ; CHECK: ret i32 1
56
+ ; CHECK-NEXT: ret i32 1
57
+ ;
53
58
54
59
%str1 = getelementptr inbounds [5 x i8 ], [5 x i8 ]* @hell , i32 0 , i32 0
55
60
%str2 = getelementptr inbounds [1 x i8 ], [1 x i8 ]* @null , i32 0 , i32 0
@@ -61,8 +66,10 @@ define arm_aapcscc i32 @test4() {
61
66
; (This transform is rather difficult to trigger in a useful manner)
62
67
define arm_aapcscc i32 @test5 (i1 %b ) {
63
68
; 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
+ ;
66
73
67
74
%str1 = getelementptr inbounds [6 x i8 ], [6 x i8 ]* @hello , i32 0 , i32 0
68
75
%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) {
75
82
; strcmp(x,x) -> 0
76
83
define arm_aapcscc i32 @test6 (i8* %str ) {
77
84
; CHECK-LABEL: @test6(
78
- ; CHECK: ret i32 0
85
+ ; CHECK-NEXT: ret i32 0
86
+ ;
79
87
80
88
%temp1 = call arm_aapcscc i32 @strcmp (i8* %str , i8* %str )
81
89
ret i32 %temp1
@@ -84,10 +92,11 @@ define arm_aapcscc i32 @test6(i8* %str) {
84
92
; strcmp("", x) -> -*x
85
93
define arm_aapcs_vfpcc i32 @test1_vfp (i8* %str2 ) {
86
94
; 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
+ ;
91
100
92
101
%str1 = getelementptr inbounds [1 x i8 ], [1 x i8 ]* @null , i32 0 , i32 0
93
102
%temp1 = call arm_aapcs_vfpcc i32 @strcmp (i8* %str1 , i8* %str2 )
@@ -98,9 +107,10 @@ define arm_aapcs_vfpcc i32 @test1_vfp(i8* %str2) {
98
107
; strcmp(x, "") -> *x
99
108
define arm_aapcs_vfpcc i32 @test2_vfp (i8* %str1 ) {
100
109
; 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
+ ;
104
114
105
115
%str2 = getelementptr inbounds [1 x i8 ], [1 x i8 ]* @null , i32 0 , i32 0
106
116
%temp1 = call arm_aapcs_vfpcc i32 @strcmp (i8* %str1 , i8* %str2 )
@@ -110,7 +120,8 @@ define arm_aapcs_vfpcc i32 @test2_vfp(i8* %str1) {
110
120
; strcmp(x, y) -> cnst
111
121
define arm_aapcs_vfpcc i32 @test3_vfp () {
112
122
; CHECK-LABEL: @test3_vfp(
113
- ; CHECK: ret i32 -1
123
+ ; CHECK-NEXT: ret i32 -1
124
+ ;
114
125
115
126
%str1 = getelementptr inbounds [5 x i8 ], [5 x i8 ]* @hell , i32 0 , i32 0
116
127
%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() {
120
131
121
132
define arm_aapcs_vfpcc i32 @test4_vfp () {
122
133
; CHECK-LABEL: @test4_vfp(
123
- ; CHECK: ret i32 1
134
+ ; CHECK-NEXT: ret i32 1
135
+ ;
124
136
125
137
%str1 = getelementptr inbounds [5 x i8 ], [5 x i8 ]* @hell , i32 0 , i32 0
126
138
%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() {
132
144
; (This transform is rather difficult to trigger in a useful manner)
133
145
define arm_aapcs_vfpcc i32 @test5_vfp (i1 %b ) {
134
146
; 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
+ ;
137
151
138
152
%str1 = getelementptr inbounds [6 x i8 ], [6 x i8 ]* @hello , i32 0 , i32 0
139
153
%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) {
146
160
; strcmp(x,x) -> 0
147
161
define arm_aapcs_vfpcc i32 @test6_vfp (i8* %str ) {
148
162
; CHECK-LABEL: @test6_vfp(
149
- ; CHECK: ret i32 0
163
+ ; CHECK-NEXT: ret i32 0
164
+ ;
150
165
151
166
%temp1 = call arm_aapcs_vfpcc i32 @strcmp (i8* %str , i8* %str )
152
167
ret i32 %temp1
0 commit comments