[llvm] [SimplifyCFG] Updated early exit in `CanRedirectPredsOfEmptyBBToSucc` (PR #142582)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 4 04:59:44 PDT 2025


kper wrote:

Thanks, more the info!

At the moment, I think that the issue is in [`redirectValuesFromPredecessorsToPhi`](https://github.com/llvm/llvm-project/blob/5e2dcfe42cd4af14d6e6155314aa5d4167710b65/llvm/lib/Transforms/Utils/Local.cpp#L1088).

```
# infinite loop
            +--------+
            | entry  |
            +--------+
             / |  \ \
            /  |   \ \
           v   v    \ \
+-------------+      \ \
| for.inc295  |<--+    \ \
+-------------+   |     \ \
                 v      v  v
           +-------------+  \
           | for.end297  |---+
           +-------------+    \
                 |             \
                 v              v
           +-----------------------+
           |      common.ret       |
           +-----------------------+
```

The goal is that `for.inc295` gets merged to `for.end297` since it only contains an unconditional jump.
In `redirectValuesFromPredecessorsToPhi`, we first remove the reference of `for.inc295` from the PHI in `for.end297`.
It skips the check `if (isa<PHINode>(OldVal) && cast<PHINode>(OldVal)->getParent() == BB) {` and continues in to the else block. The variable `BBPreds` contains the predecessors of `for.inc295` which is `entry`. However, the common predecessor is also `entry`. Since both `PredBB` and `CommonPred` are `entry`. It will [skip](https://github.com/llvm/llvm-project/blob/5e2dcfe42cd4af14d6e6155314aa5d4167710b65/llvm/lib/Transforms/Utils/Local.cpp#L1135) the loop.
Unfortunately, since there is a `CommonPred`, it will [add](https://github.com/llvm/llvm-project/blob/5e2dcfe42cd4af14d6e6155314aa5d4167710b65/llvm/lib/Transforms/Utils/Local.cpp#L1145) the old value to the Phi node which is exactly the same thing again. So, the graph did not change at all but simplifyCFG simplification says that something has changed.

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


More information about the llvm-commits mailing list