Skip to content

Commit 0c8d3db

Browse files
committed
[AggressiveInstCombine] Fold strcmp for short string literals with size 2 tests
Precommit tests for D155743. Differential Revision: https://reviews.llvm.org/D155742
1 parent 0e4c5cc commit 0c8d3db

File tree

1 file changed

+58
-3
lines changed
  • llvm/test/Transforms/AggressiveInstCombine

1 file changed

+58
-3
lines changed

llvm/test/Transforms/AggressiveInstCombine/strcmp.ll

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ declare i32 @strcmp(ptr, ptr)
99
@s3 = constant [4 x i8] c"012\00"
1010
@s4 = constant [5 x i8] c"0123\00"
1111

12-
; Expand strcmp(C, "x").
12+
; Expand strcmp(C, "x"), strcmp(C, "xy").
1313

1414
define i1 @expand_strcmp_s0(ptr %C) {
1515
; CHECK-LABEL: @expand_strcmp_s0(
@@ -207,8 +207,8 @@ define i32 @expand_strcmp_s1_fail_3(ptr %C) {
207207
ret i32 %call
208208
}
209209

210-
define i1 @expand_strcmp_s2(ptr %C) {
211-
; CHECK-LABEL: @expand_strcmp_s2(
210+
define i1 @expand_strcmp_eq_s2(ptr %C) {
211+
; CHECK-LABEL: @expand_strcmp_eq_s2(
212212
; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s2)
213213
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[CALL]], 0
214214
; CHECK-NEXT: ret i1 [[CMP]]
@@ -218,6 +218,61 @@ define i1 @expand_strcmp_s2(ptr %C) {
218218
ret i1 %cmp
219219
}
220220

221+
define i1 @expand_strcmp_ne_s2(ptr %C) {
222+
; CHECK-LABEL: @expand_strcmp_ne_s2(
223+
; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s2)
224+
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[CALL]], 0
225+
; CHECK-NEXT: ret i1 [[CMP]]
226+
;
227+
%call = call i32 @strcmp(ptr %C, ptr @s2)
228+
%cmp = icmp ne i32 %call, 0
229+
ret i1 %cmp
230+
}
231+
232+
define i1 @expand_strcmp_sgt_s2(ptr %C) {
233+
; CHECK-LABEL: @expand_strcmp_sgt_s2(
234+
; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s2)
235+
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[CALL]], 0
236+
; CHECK-NEXT: ret i1 [[CMP]]
237+
;
238+
%call = call i32 @strcmp(ptr %C, ptr @s2)
239+
%cmp = icmp sgt i32 %call, 0
240+
ret i1 %cmp
241+
}
242+
243+
define i1 @expand_strcmp_sge_s2(ptr %C) {
244+
; CHECK-LABEL: @expand_strcmp_sge_s2(
245+
; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s2)
246+
; CHECK-NEXT: [[CMP:%.*]] = icmp sge i32 [[CALL]], 0
247+
; CHECK-NEXT: ret i1 [[CMP]]
248+
;
249+
%call = call i32 @strcmp(ptr %C, ptr @s2)
250+
%cmp = icmp sge i32 %call, 0
251+
ret i1 %cmp
252+
}
253+
254+
define i1 @expand_strcmp_slt_s2(ptr %C) {
255+
; CHECK-LABEL: @expand_strcmp_slt_s2(
256+
; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s2)
257+
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[CALL]], 0
258+
; CHECK-NEXT: ret i1 [[CMP]]
259+
;
260+
%call = call i32 @strcmp(ptr %C, ptr @s2)
261+
%cmp = icmp slt i32 %call, 0
262+
ret i1 %cmp
263+
}
264+
265+
define i1 @expand_strcmp_sle_s2(ptr %C) {
266+
; CHECK-LABEL: @expand_strcmp_sle_s2(
267+
; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s2)
268+
; CHECK-NEXT: [[CMP:%.*]] = icmp sle i32 [[CALL]], 0
269+
; CHECK-NEXT: ret i1 [[CMP]]
270+
;
271+
%call = call i32 @strcmp(ptr %C, ptr @s2)
272+
%cmp = icmp sle i32 %call, 0
273+
ret i1 %cmp
274+
}
275+
221276
define i1 @expand_strcmp_s3(ptr %C) {
222277
; CHECK-LABEL: @expand_strcmp_s3(
223278
; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s3)

0 commit comments

Comments
 (0)