[PATCH] D155742: [AggressiveInstCombine] Fold strcmp for short string literals with size 2 tests

Maksim Kita via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 19 12:53:39 PDT 2023


kitaisreal created this revision.
kitaisreal added reviewers: nikic, goldstein.w.n.
kitaisreal added projects: All, LLVM.
Herald added a subscriber: StephenFan.
kitaisreal requested review of this revision.
Herald added a subscriber: llvm-commits.

https://reviews.llvm.org/D155742

Files:
  llvm/test/Transforms/AggressiveInstCombine/strcmp.ll


Index: llvm/test/Transforms/AggressiveInstCombine/strcmp.ll
===================================================================
--- llvm/test/Transforms/AggressiveInstCombine/strcmp.ll
+++ llvm/test/Transforms/AggressiveInstCombine/strcmp.ll
@@ -9,7 +9,7 @@
 @s3 = constant [4 x i8] c"012\00"
 @s4 = constant [5 x i8] c"0123\00"
 
-; Expand strcmp(C, "x").
+; Expand strcmp(C, "x"), strcmp(C, "xy").
 
 define i1 @expand_strcmp_s0(ptr %C) {
 ; CHECK-LABEL: @expand_strcmp_s0(
@@ -207,8 +207,8 @@
   ret i32 %call
 }
 
-define i1 @expand_strcmp_s2(ptr %C) {
-; CHECK-LABEL: @expand_strcmp_s2(
+define i1 @expand_strcmp_eq_s2(ptr %C) {
+; CHECK-LABEL: @expand_strcmp_eq_s2(
 ; CHECK-NEXT:    [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s2)
 ; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i32 [[CALL]], 0
 ; CHECK-NEXT:    ret i1 [[CMP]]
@@ -218,6 +218,61 @@
   ret i1 %cmp
 }
 
+define i1 @expand_strcmp_ne_s2(ptr %C) {
+; CHECK-LABEL: @expand_strcmp_ne_s2(
+; CHECK-NEXT:    [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s2)
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[CALL]], 0
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %call = call i32 @strcmp(ptr %C, ptr @s2)
+  %cmp = icmp ne i32 %call, 0
+  ret i1 %cmp
+}
+
+define i1 @expand_strcmp_sgt_s2(ptr %C) {
+; CHECK-LABEL: @expand_strcmp_sgt_s2(
+; CHECK-NEXT:    [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s2)
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i32 [[CALL]], 0
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %call = call i32 @strcmp(ptr %C, ptr @s2)
+  %cmp = icmp sgt i32 %call, 0
+  ret i1 %cmp
+}
+
+define i1 @expand_strcmp_sge_s2(ptr %C) {
+; CHECK-LABEL: @expand_strcmp_sge_s2(
+; CHECK-NEXT:    [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s2)
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sge i32 [[CALL]], 0
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %call = call i32 @strcmp(ptr %C, ptr @s2)
+  %cmp = icmp sge i32 %call, 0
+  ret i1 %cmp
+}
+
+define i1 @expand_strcmp_slt_s2(ptr %C) {
+; CHECK-LABEL: @expand_strcmp_slt_s2(
+; CHECK-NEXT:    [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s2)
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[CALL]], 0
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %call = call i32 @strcmp(ptr %C, ptr @s2)
+  %cmp = icmp slt i32 %call, 0
+  ret i1 %cmp
+}
+
+define i1 @expand_strcmp_sle_s2(ptr %C) {
+; CHECK-LABEL: @expand_strcmp_sle_s2(
+; CHECK-NEXT:    [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s2)
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sle i32 [[CALL]], 0
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %call = call i32 @strcmp(ptr %C, ptr @s2)
+  %cmp = icmp sle i32 %call, 0
+  ret i1 %cmp
+}
+
 define i1 @expand_strcmp_s3(ptr %C) {
 ; CHECK-LABEL: @expand_strcmp_s3(
 ; CHECK-NEXT:    [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr @s3)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155742.542160.patch
Type: text/x-patch
Size: 2750 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230719/66f32428/attachment.bin>


More information about the llvm-commits mailing list