[PATCH] D155053: [AggressiveInstCombine] Fold strcmp for short string literals tests

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


kitaisreal updated this revision to Diff 539491.
kitaisreal added a comment.

Added tests for different string sizes.


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

https://reviews.llvm.org/D155053

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


Index: llvm/test/Transforms/AggressiveInstCombine/strcmp.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/AggressiveInstCombine/strcmp.ll
@@ -0,0 +1,92 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; TODO: Test that ...
+; RUN: opt < %s -passes=aggressive-instcombine -S | FileCheck %s
+
+declare i32 @strcmp(ptr, ptr)
+
+ at s1 = constant [2 x i8] c"0\00"
+ at s2 = constant [3 x i8] c"01\00", align 1
+ at s3 = constant [4 x i8] c"012\00", align 1
+ at s4 = constant [5 x i8] c"0123\00", align 1
+
+; Expand strcmp(C, "x").
+
+define i1 @expand_strcmp_s1_1(ptr %C) {
+; CHECK-LABEL: @expand_strcmp_s1_1(
+; CHECK-NEXT:    [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr noundef @s1)
+; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i32 [[CALL]], 0
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %call = call i32 @strcmp(ptr %C, ptr noundef @s1)
+  %cmp = icmp eq i32 %call, 0
+  ret i1 %cmp
+}
+
+define i32 @expand_strcmp_s1_2(ptr %C) {
+; CHECK-LABEL: @expand_strcmp_s1_2(
+; CHECK-NEXT:    [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr noundef @s1)
+; CHECK-NEXT:    ret i32 [[CALL]]
+;
+  %call = call i32 @strcmp(ptr %C, ptr noundef @s1)
+  ret i32 %call
+}
+
+define i1 @expand_strcmp_s2_1(ptr %C) {
+; CHECK-LABEL: @expand_strcmp_s2_1(
+; CHECK-NEXT:    [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr noundef @s2)
+; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i32 [[CALL]], 0
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %call = call i32 @strcmp(ptr %C, ptr noundef @s2)
+  %cmp = icmp eq i32 %call, 0
+  ret i1 %cmp
+}
+
+define i32 @expand_strcmp_s2_2(ptr %C) {
+; CHECK-LABEL: @expand_strcmp_s2_2(
+; CHECK-NEXT:    [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr noundef @s2)
+; CHECK-NEXT:    ret i32 [[CALL]]
+;
+  %call = call i32 @strcmp(ptr %C, ptr noundef @s2)
+  ret i32 %call
+}
+
+define i1 @expand_strcmp_s3_1(ptr %C) {
+; CHECK-LABEL: @expand_strcmp_s3_1(
+; CHECK-NEXT:    [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr noundef @s3)
+; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i32 [[CALL]], 0
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %call = call i32 @strcmp(ptr %C, ptr noundef @s3)
+  %cmp = icmp eq i32 %call, 0
+  ret i1 %cmp
+}
+
+define i32 @expand_strcmp_s3_2(ptr %C) {
+; CHECK-LABEL: @expand_strcmp_s3_2(
+; CHECK-NEXT:    [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr noundef @s3)
+; CHECK-NEXT:    ret i32 [[CALL]]
+;
+  %call = call i32 @strcmp(ptr %C, ptr noundef @s3)
+  ret i32 %call
+}
+
+define i1 @expand_strcmp_s4_1(ptr %C) {
+; CHECK-LABEL: @expand_strcmp_s4_1(
+; CHECK-NEXT:    [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr noundef @s4)
+; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i32 [[CALL]], 0
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %call = call i32 @strcmp(ptr %C, ptr noundef @s4)
+  %cmp = icmp eq i32 %call, 0
+  ret i1 %cmp
+}
+
+define i32 @expand_strcmp_s4_2(ptr %C) {
+; CHECK-LABEL: @expand_strcmp_s4_2(
+; CHECK-NEXT:    [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr noundef @s4)
+; CHECK-NEXT:    ret i32 [[CALL]]
+;
+  %call = call i32 @strcmp(ptr %C, ptr noundef @s4)
+  ret i32 %call
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155053.539491.patch
Type: text/x-patch
Size: 3128 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230712/5bc84668/attachment.bin>


More information about the llvm-commits mailing list