[PATCH] D133777: [SelectOpti] Fix lifetime intrinsic bug

Sotiris Apostolakis via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 13 07:45:11 PDT 2022


apostolakis created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
apostolakis requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133777

Files:
  llvm/lib/CodeGen/SelectOptimize.cpp


Index: llvm/lib/CodeGen/SelectOptimize.cpp
===================================================================
--- llvm/lib/CodeGen/SelectOptimize.cpp
+++ llvm/lib/CodeGen/SelectOptimize.cpp
@@ -29,6 +29,7 @@
 #include "llvm/IR/Function.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/Instruction.h"
+#include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/ProfDataUtils.h"
 #include "llvm/InitializePasses.h"
 #include "llvm/Pass.h"
@@ -425,6 +426,21 @@
     // Delete the unconditional branch that was just created by the split.
     StartBlock->getTerminator()->eraseFromParent();
 
+    // Move any lifetime-end intrinsic calls found in the StartBlock to the
+    // newly-created end block to ensure sound lifetime info after sinking (in
+    // case any use is sinked).
+    SmallVector<Instruction *, 2> EndLifetimeCalls;
+    for (Instruction &I : *StartBlock) {
+      if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(&I)) {
+        if (II->getIntrinsicID() == Intrinsic::lifetime_end) {
+          EndLifetimeCalls.push_back(&I);
+        }
+      }
+    }
+    for (auto *LC : EndLifetimeCalls) {
+      LC->moveBefore(&*EndBlock->getFirstInsertionPt());
+    }
+
     // Move any debug/pseudo instructions that were in-between the select
     // group to the newly-created end block.
     SmallVector<Instruction *, 2> DebugPseudoINS;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133777.459747.patch
Type: text/x-patch
Size: 1351 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220913/245b576a/attachment.bin>


More information about the llvm-commits mailing list