[llvm] [LoopIdiom] Select llvm.experimental.memset.pattern intrinsic rather than memset_pattern16 libcall (PR #126736)

Alex Bradbury via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 25 07:55:24 PDT 2025


asb wrote:

I've merged in the latest changes and will re-check my comparison.

My methdology has been:
* Apply a patch to make memset_pattern16 be exposed on non-Darwin (so I can test the codepath easily)
* Build llvm-test-suite and diff
* Apply any other needed downstream hacks for diffs that don't appear important but may mask bigger issues

For the last bullet, I've found there is a difference in unrolling behaviour due to TargetTransformInfo::isLoweredToCall not recognising that the intrinsic may be lowered to call (ultimately called via gatherUnrollingPreferences). In general we don't do anything very exhaustive at all here re libcalls so I don't propose to change that. But locally, I work around this with:

```diff
--- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
+++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
@@ -179,6 +179,9 @@ public:
     // ported from existing analysis heuristics here so that such refactorings
     // can take place in the future.

+    if (F->isIntrinsic() && (F->getIntrinsicID() == Intrinsic::experimental_memset_pattern))
+      return true;
+
     if (F->isIntrinsic())
       return false;
```

The hacky patch to expose the libcalls on non-Darwin is:
```diff
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -226,11 +226,12 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
       TLI.setUnavailable(LibFunc_memset_pattern8);
       TLI.setUnavailable(LibFunc_memset_pattern16);
     }
-  } else if (!T.isWatchOS()) {
-    TLI.setUnavailable(LibFunc_memset_pattern4);
-    TLI.setUnavailable(LibFunc_memset_pattern8);
-    TLI.setUnavailable(LibFunc_memset_pattern16);
   }
+//} else if (!T.isWatchOS()) {
+//  TLI.setUnavailable(LibFunc_memset_pattern4);
+//  TLI.setUnavailable(LibFunc_memset_pattern8);
+//  TLI.setUnavailable(LibFunc_memset_pattern16);
+//}

   if (!hasSinCosPiStret(T)) {
     TLI.setUnavailable(LibFunc_sinpi);
```

(Then build llvm-test-suite with -k0 and ignore link errors, diff the .s).

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


More information about the llvm-commits mailing list