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

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 18 08:56:37 PDT 2025


dtcxzyw wrote:

> > 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:
> 
> ah ok, nice to know, thanks :)
> 
> > 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?
> 
> ~I think it doesn't. At least when running `opt` without any passes as argument, it didn't change.~ I would prefer to make a separate issue because I am not quite sure how to detect whether I can transform the phi into the select.
> 
> EDIT:
> 
> I've forgot to run `-O3`. It seems that the EarlyCSEPass drops the merge and afterwards the SimplifyCFG pass is executed and removes the `for.inc295` block.
> 
> ```
> define void @func_143(i32 %0, ptr writeonly captures(none) %g_329) local_unnamed_addr #0 {
> 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
>   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?

The reproducer is reduced from the IR just before SimplifyCFGPass. So you cannot rely on other passes to perform the cleanup.




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


More information about the llvm-commits mailing list