[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 02:25:29 PDT 2023


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

Precommit tests for D154725 <https://reviews.llvm.org/D154725>.


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,29 @@
+; 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"
+
+; Fold strcmp(C, "x").
+
+define i1 @fold_strcmp_s1_1(ptr %C) {
+; CHECK-LABEL: @fold_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 @fold_strcmp_s1_2(ptr %C) {
+; CHECK-LABEL: @fold_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
+}


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


More information about the llvm-commits mailing list