[SimplifyCFG] Infinite loop of transformations on branch on widenable condition #57221
Labels
bug
Indicates an unexpected problem or unintended behavior
llvm:hang
Compiler hang (infinite loop)
llvm:optimizations
I was investigating an xfailed test
llvm/test/Transforms/SimplifyCFG/pr52290.ll
. Running SimplifyCFG on it results in assert crash:opt: llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp:240: bool iterativelySimplifyCFG(llvm::Function&, const llvm::TargetTransformInfo&, llvm::DomTreeUpdater*, const llvm::SimplifyCFGOptions&): Assertion `IterCnt++ < 1000 && "Iterative simplification didn't converge!"' failed.
Here is the IR:
SimplifyCFG applies some certain set of transformations, and then applying another one reverts the IR to the state before those first transformations. It continues until the assert fails.
Here are the transformations applied step by step:
bb6
:bb2
to branch tobb1
on true condition (this is done bytryWidenCondBranchToCondBranch
inSimplifyCFG.cpp
):bb1
) decide thatbb2
should branch tobb7
on true condition (through a newbb7.critedge
block):Then repeat the same thing starting from step 1 over and over again.
Step 3 is done because SimplifyCFG looks at branch condition in
bb1
which isundef
and tries to find a "known value" for it in its predecessors. I think it supposes that if we came tobb1
frombb2
, which also has a branch onundef
, then it can assumeundef
inbb1
is true too, so it changes thebr
inbb2
to branch tobb7
on taken path.Disabling step 2 transformation from here solves the issue and the infinite loop is gone.
Does anyone have ideas on how to resolve this? Maybe we should consider disabling the conditional br to conditional br widening?
The text was updated successfully, but these errors were encountered: