[llvm] [SROA] Rewrite invariant group intrinsics after splitting alloca (PR #107557)

Antonio Frighetto via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 29 08:57:25 PDT 2024


================
@@ -3531,8 +3531,19 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> {
       return true;
     }
 
-    if (II.isLaunderOrStripInvariantGroup())
+    if (II.isLaunderOrStripInvariantGroup()) {
+      Value *AdjustedPtr = getNewAllocaSlicePtr(IRB, OldPtr->getType());
+      Value *New = nullptr;
+      if (II.getIntrinsicID() == Intrinsic::launder_invariant_group)
+        New = IRB.CreateLaunderInvariantGroup(AdjustedPtr);
+      else if (II.getIntrinsicID() == Intrinsic::strip_invariant_group)
+        New = IRB.CreateStripInvariantGroup(AdjustedPtr);
+
+      New->takeName(&II);
+      II.replaceAllUsesWith(New);
----------------
antoniofrighetto wrote:

Updated this by considering whether we need to rewrite memory intrinsics as well when rewriting the invariant group one. Tried to keep everything self-contained in visitIntrinsicInst, but code was getting duplicated fast, and the memcpys were later being visited anyways. Thus, as the alloca may get split at each AllocaSliceRewriter iteration, if some of the users of the invariant group are memory intrinsics, we track the launder so as to use this one as ptr destination, instead of the new alloca.

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


More information about the llvm-commits mailing list