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

via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 10 19:17:43 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());
----------------
weiguozhi wrote:

Found Invoke instruction at this position is already wrong. The problem is at

```
      if (!ResultIndex) {
        SunkAddr = ResultPtr;
      } else {
```

1. We should make sure ResultPtr is in current BB before directly using it as SunkAddr.
2. If ResultPtr is not in current BB we can clone it as the SunkAddr in current BB.
3. Invoke instruction is not a good candidate for SunkAddr.


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


More information about the llvm-commits mailing list