[llvm] [AggressiveInstCombine] Add tests for memchr inline threshold (PR #121711)

via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 5 15:31:49 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: None (natedal)

<details>
<summary>Changes</summary>

(This adds a test checking that, if length=2, memchr is called. This is undesirable as it would be faster to directly compare the two array elements with the target element, rather than calling the external memchr function.)

---
Full diff: https://github.com/llvm/llvm-project/pull/121711.diff


1 Files Affected:

- (modified) llvm/test/Transforms/AggressiveInstCombine/memchr.ll (+14) 


``````````diff
diff --git a/llvm/test/Transforms/AggressiveInstCombine/memchr.ll b/llvm/test/Transforms/AggressiveInstCombine/memchr.ll
index 2601b9f05a97f9..1f1938eecafe69 100644
--- a/llvm/test/Transforms/AggressiveInstCombine/memchr.ll
+++ b/llvm/test/Transforms/AggressiveInstCombine/memchr.ll
@@ -161,3 +161,17 @@ entry:
   %memchr = call ptr @memchr(ptr @str_long, i32 %x, i64 8)
   ret ptr %memchr
 }
+
+
+define ptr @test_memchr_non_constant_length2(i32 %x, i64 %len) {
+; CHECK-LABEL: define ptr @test_memchr_non_constant_length2(
+; CHECK-SAME: i32 [[X:%.*]], i64 [[LEN:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT: ; We want to check that the compiler still calls memchr:
+; CHECK-NEXT:    [[MEMCHR:%.*]] = call ptr @memchr(ptr @str, i32 [[X]], i64 [[LEN]])
+; CHECK-NEXT:    ret ptr [[MEMCHR]]
+;
+entry:
+  %memchr = call ptr @memchr(ptr @str, i32 %x, i64 %len)
+  ret ptr %memchr
+}

``````````

</details>


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


More information about the llvm-commits mailing list