[llvm] [CodeGenPrepare] Handle address sinking obtained from invoke (PR #143566)

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 11 14:28:14 PDT 2025


================
@@ -5790,7 +5790,8 @@ static BasicBlock::iterator findInsertPos(Value *Addr, Instruction *MemoryInst,
   // instruction after it.
   if (SunkAddr) {
     if (Instruction *AddrInst = dyn_cast<Instruction>(SunkAddr))
-      return std::next(AddrInst->getIterator());
+      return AddrInst->isTerminator() ? MemoryInst->getIterator()
+                                      : std::next(AddrInst->getIterator());
----------------
rnk wrote:

I think I agree with @weiguozhi . From looking at the test case, why are we trying to sink the GEP upwards toward the entry block? It seems like something has gone wrong earlier.

The proposed fix is like adding a null check when the correct fix was to avoid passing null at a higher level.

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


More information about the llvm-commits mailing list