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

Evgenii Kudriashov via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 11 14:15:38 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());
----------------
e-kud wrote:

> We should make sure ResultPtr is in current BB before directly using it as SunkAddr.

We use global pointers safely because we can't get iterator in a BB for them. Do we want to handle them similarly to instructions in other blocks?

> If ResultPtr is not in current BB we can clone it as the SunkAddr in current BB.

Clone -- do you mean create GEP with 0?

> Invoke instruction is not a good candidate for SunkAddr.

Not obvious to me, why is it different from instructions in other blocks or from globals?

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


More information about the llvm-commits mailing list