[llvm] [AggressiveInstCombine] Inline strcmp/strncmp (PR #89371)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu May 2 18:43:33 PDT 2024


================
@@ -0,0 +1,147 @@
+; RUN: opt -S -passes=aggressive-instcombine -strncmp-inline-threshold=3 < %s | FileCheck --check-prefixes=CHECK,TH-3 %s
+; RUN: opt -S -passes=aggressive-instcombine -strncmp-inline-threshold=2 < %s | FileCheck --check-prefixes=CHECK,TH-2 %s
+; RUN: opt -S -passes=aggressive-instcombine -strncmp-inline-threshold=1 < %s | FileCheck --check-prefixes=CHECK,TH-1 %s
+; RUN: opt -S -passes=aggressive-instcombine -strncmp-inline-threshold=0 < %s | FileCheck --check-prefixes=CHECK,TH-0 %s
+
+declare i32 @strcmp(ptr nocapture, ptr nocapture)
+declare i32 @strncmp(ptr nocapture, ptr nocapture, i64)
+
+ at s1 = constant [1 x i8] c"\00", align 1
+ at s2n = constant [2 x i8] c"aa", align 1
+ at s3 = constant [3 x i8] c"aa\00", align 1
+ at s4 = constant [4 x i8] c"aab\00", align 1
+
+; strncmp(s, "aa", 1)
+define i1 @test_strncmp_0(i8* %s) {
+entry:
+  %call = tail call i32 @strncmp(ptr nonnull dereferenceable(1) %s, ptr nonnull dereferenceable(3) @s3, i64 1)
+  %cmp = icmp eq i32 %call, 0
+  ret i1 %cmp
+}
+; CHECK-LABEL: @test_strncmp_0(
+; TH-3: @strncmp
----------------
nikic wrote:

```suggestion
; CHECK: @strncmp
```
I think? If the point is that we should never expand this strncmp regardless of threshold.

Similar for other cases.

https://github.com/llvm/llvm-project/pull/89371


More information about the llvm-commits mailing list