1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=aggressive-instcombine -S | FileCheck %s
4 declare i32 @strcmp(ptr, ptr)
6 @s0 = constant [1 x i8] c"\00"
7 @s1 = constant [2 x i8] c"0\00"
8 @s2 = constant [3 x i8] c"01\00"
9 @s3 = constant [4 x i8] c"012\00"
10 @s4 = constant [5 x i8] c"0123\00"
12 ; Expand strcmp(C, "x"), strcmp(C, "xy").
14 define i1 @expand_strcmp_s0(ptr %C) {
15 ; CHECK-LABEL: @expand_strcmp_s0(
16 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s0)
17 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[CALL]], 0
18 ; CHECK-NEXT: ret i1 [[CMP]]
20 %call = call i32 @strcmp(ptr %C, ptr @s0)
21 %cmp = icmp eq i32 %call, 0
25 define i1 @expand_strcmp_eq_s1(ptr %C) {
26 ; CHECK-LABEL: @expand_strcmp_eq_s1(
27 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s1)
28 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[CALL]], 0
29 ; CHECK-NEXT: ret i1 [[CMP]]
31 %call = call i32 @strcmp(ptr %C, ptr @s1)
32 %cmp = icmp eq i32 %call, 0
36 define i1 @expand_strcmp_eq_s1_commuted(ptr %C) {
37 ; CHECK-LABEL: @expand_strcmp_eq_s1_commuted(
38 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr @s1, ptr [[C:%.*]])
39 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[CALL]], 0
40 ; CHECK-NEXT: ret i1 [[CMP]]
42 %call = call i32 @strcmp(ptr @s1, ptr %C)
43 %cmp = icmp eq i32 %call, 0
47 define i1 @expand_strcmp_ne_s1(ptr %C) {
48 ; CHECK-LABEL: @expand_strcmp_ne_s1(
49 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s1)
50 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[CALL]], 0
51 ; CHECK-NEXT: ret i1 [[CMP]]
53 %call = call i32 @strcmp(ptr %C, ptr @s1)
54 %cmp = icmp ne i32 %call, 0
58 define i1 @expand_strcmp_sgt_s1(ptr %C) {
59 ; CHECK-LABEL: @expand_strcmp_sgt_s1(
60 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s1)
61 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[CALL]], 0
62 ; CHECK-NEXT: ret i1 [[CMP]]
64 %call = call i32 @strcmp(ptr %C, ptr @s1)
65 %cmp = icmp sgt i32 %call, 0
69 define i1 @expand_strcmp_sge_s1(ptr %C) {
70 ; CHECK-LABEL: @expand_strcmp_sge_s1(
71 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s1)
72 ; CHECK-NEXT: [[CMP:%.*]] = icmp sge i32 [[CALL]], 0
73 ; CHECK-NEXT: ret i1 [[CMP]]
75 %call = call i32 @strcmp(ptr %C, ptr @s1)
76 %cmp = icmp sge i32 %call, 0
80 define i1 @expand_strcmp_slt_s1(ptr %C) {
81 ; CHECK-LABEL: @expand_strcmp_slt_s1(
82 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s1)
83 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[CALL]], 0
84 ; CHECK-NEXT: ret i1 [[CMP]]
86 %call = call i32 @strcmp(ptr %C, ptr @s1)
87 %cmp = icmp slt i32 %call, 0
91 define i1 @expand_strcmp_sle_s1(ptr %C) {
92 ; CHECK-LABEL: @expand_strcmp_sle_s1(
93 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s1)
94 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i32 [[CALL]], 0
95 ; CHECK-NEXT: ret i1 [[CMP]]
97 %call = call i32 @strcmp(ptr %C, ptr @s1)
98 %cmp = icmp sle i32 %call, 0
102 define i1 @expand_strcmp_s1_fail_1(ptr %C) {
103 ; CHECK-LABEL: @expand_strcmp_s1_fail_1(
104 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s1)
105 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[CALL]], 1
106 ; CHECK-NEXT: ret i1 [[CMP]]
108 %call = call i32 @strcmp(ptr %C, ptr @s1)
109 %cmp = icmp eq i32 %call, 1
113 define i1 @expand_strcmp_s1_fail_2(ptr %C) {
114 ; CHECK-LABEL: @expand_strcmp_s1_fail_2(
115 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr @s1, ptr @s1)
116 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[CALL]], 0
117 ; CHECK-NEXT: ret i1 [[CMP]]
119 %call = call i32 @strcmp(ptr @s1, ptr @s1)
120 %cmp = icmp eq i32 %call, 0
124 define i32 @expand_strcmp_s1_fail_3(ptr %C) {
125 ; CHECK-LABEL: @expand_strcmp_s1_fail_3(
126 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s1)
127 ; CHECK-NEXT: ret i32 [[CALL]]
129 %call = call i32 @strcmp(ptr %C, ptr @s1)
133 define i1 @expand_strcmp_eq_s2(ptr %C) {
134 ; CHECK-LABEL: @expand_strcmp_eq_s2(
135 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s2)
136 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[CALL]], 0
137 ; CHECK-NEXT: ret i1 [[CMP]]
139 %call = call i32 @strcmp(ptr %C, ptr @s2)
140 %cmp = icmp eq i32 %call, 0
144 define i1 @expand_strcmp_ne_s2(ptr %C) {
145 ; CHECK-LABEL: @expand_strcmp_ne_s2(
146 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s2)
147 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[CALL]], 0
148 ; CHECK-NEXT: ret i1 [[CMP]]
150 %call = call i32 @strcmp(ptr %C, ptr @s2)
151 %cmp = icmp ne i32 %call, 0
155 define i1 @expand_strcmp_sgt_s2(ptr %C) {
156 ; CHECK-LABEL: @expand_strcmp_sgt_s2(
157 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s2)
158 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[CALL]], 0
159 ; CHECK-NEXT: ret i1 [[CMP]]
161 %call = call i32 @strcmp(ptr %C, ptr @s2)
162 %cmp = icmp sgt i32 %call, 0
166 define i1 @expand_strcmp_sge_s2(ptr %C) {
167 ; CHECK-LABEL: @expand_strcmp_sge_s2(
168 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s2)
169 ; CHECK-NEXT: [[CMP:%.*]] = icmp sge i32 [[CALL]], 0
170 ; CHECK-NEXT: ret i1 [[CMP]]
172 %call = call i32 @strcmp(ptr %C, ptr @s2)
173 %cmp = icmp sge i32 %call, 0
177 define i1 @expand_strcmp_slt_s2(ptr %C) {
178 ; CHECK-LABEL: @expand_strcmp_slt_s2(
179 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s2)
180 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[CALL]], 0
181 ; CHECK-NEXT: ret i1 [[CMP]]
183 %call = call i32 @strcmp(ptr %C, ptr @s2)
184 %cmp = icmp slt i32 %call, 0
188 define i1 @expand_strcmp_sle_s2(ptr %C) {
189 ; CHECK-LABEL: @expand_strcmp_sle_s2(
190 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s2)
191 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i32 [[CALL]], 0
192 ; CHECK-NEXT: ret i1 [[CMP]]
194 %call = call i32 @strcmp(ptr %C, ptr @s2)
195 %cmp = icmp sle i32 %call, 0
199 define i1 @expand_strcmp_s3(ptr %C) {
200 ; CHECK-LABEL: @expand_strcmp_s3(
201 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s3)
202 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[CALL]], 0
203 ; CHECK-NEXT: ret i1 [[CMP]]
205 %call = call i32 @strcmp(ptr %C, ptr @s3)
206 %cmp = icmp eq i32 %call, 0
210 define i1 @expand_strcmp_s4(ptr %C) {
211 ; CHECK-LABEL: @expand_strcmp_s4(
212 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s4)
213 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[CALL]], 0
214 ; CHECK-NEXT: ret i1 [[CMP]]
216 %call = call i32 @strcmp(ptr %C, ptr @s4)
217 %cmp = icmp eq i32 %call, 0