[llvm] 0c8d3db - [AggressiveInstCombine] Fold strcmp for short string literals with size 2 tests
Maksim Kita via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 27 08:45:40 PDT 2023
Author: Maksim Kita
Date: 2023-07-27T18:45:21+03:00
New Revision: 0c8d3db5d27701cfab4665e52c53c83673f069d5
URL: https://github.com/llvm/llvm-project/commit/0c8d3db5d27701cfab4665e52c53c83673f069d5
DIFF: https://github.com/llvm/llvm-project/commit/0c8d3db5d27701cfab4665e52c53c83673f069d5.diff
LOG: [AggressiveInstCombine] Fold strcmp for short string literals with size 2 tests
Precommit tests for D155743.
Differential Revision: https://reviews.llvm.org/D155742
Added:
Modified:
llvm/test/Transforms/AggressiveInstCombine/strcmp.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/AggressiveInstCombine/strcmp.ll b/llvm/test/Transforms/AggressiveInstCombine/strcmp.ll
index 1955a5857e2946..b8ab551f052484 100644
--- a/llvm/test/Transforms/AggressiveInstCombine/strcmp.ll
+++ b/llvm/test/Transforms/AggressiveInstCombine/strcmp.ll
@@ -9,7 +9,7 @@ declare i32 @strcmp(ptr, ptr)
@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 @@ define i32 @expand_strcmp_s1_fail_3(ptr %C) {
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 @@ define i1 @expand_strcmp_s2(ptr %C) {
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)
More information about the llvm-commits
mailing list