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

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 16 08:39:35 PDT 2025


sharkautarch wrote:

> > The goal is that for.inc295 gets merged to for.end297 since it only contains an unconditional jump.
> 
> I was not able to get that done. I would have had multiple values from the same bb and I am not sure whether that would be correct. So I just focused on not having the infinity loop.
> 
> I've added a check when no values have been redirected then `return false`. I had to update a few more tests. In some cases, it just reordered the phi values. I hope that's ok.


In the mentioned infinity loop case, I don’t think the for.inc295 block is mergeable in this case, due to the interaction with the phi node in for.end297
Technically ig the phi node could be removed (which would thereby allow for.inc295 to be merged) by converting the phi node into a select:
```
define void @func_143(i32 %0, ptr %g_329) {
entry:
  switch i32 %0, label %common.ret [
    i32 0, label %for.end297
    i32 1, label %for.end297
    i32 33, label %for.end297
  ]

common.ret:                                       ; preds = %for.end297, %entry
  ret void

for.end297:                                       ; preds = %entry, %entry, %entry
  %1 = icmp eq i32 %0, 1
  %storemerge739.lcssa761 = select i1 %1, i64 0, i64 1
  store i8 0, ptr %g_329, align 1
  br label %common.ret
}
```
Not sure if this simplification may already happen with a pass outside simplifycfg (probably not)?
Either way, that’s probably out of scope for this PR?

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


More information about the llvm-commits mailing list