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

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


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

(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.)

>From 0e89596af66b9382c39c2248a5fe8a17c1562f3a Mon Sep 17 00:00:00 2001
From: natedal <natedalbert at gmail.com>
Date: Sun, 5 Jan 2025 18:11:55 -0500
Subject: [PATCH] [AggressiveInstCombine] Add tests for  inline threshold (if
 l=2, memchr is called)

---
 .../Transforms/AggressiveInstCombine/memchr.ll     | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

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
+}



More information about the llvm-commits mailing list