[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
Thu Jul 27 08:45:49 PDT 2023


This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0c8d3db5d277: [AggressiveInstCombine] Fold strcmp for short string literals with size 2 tests (authored by kitaisreal).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155742/new/

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.544791.patch
Type: text/x-patch
Size: 2750 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230727/0e3b885d/attachment.bin>


More information about the llvm-commits mailing list