This fixes an infinite loop of transformations in SimplifyCFG (GItHub issue - https://github.com/llvm/llvm-project/issues/57221).
The problem is that there are two transforms in SimplifyCFG that do absolutely opposite things.
First, there is tryWidenCondBranchToCondBranch which does the following.
When it sees a branch on widenable condition followed by another conditional branch like here:
bb: %tmp = call i1 @llvm.experimental.widenable.condition() br i1 %tmp, label %bb2, label %bb1 bb1: ; preds = %bb br i1 undef, label %bb7, label %bb5 bb2: ; preds = %bb br i1 undef, label %bb7, label %bb4
it thinks that it's profitable for bb2 to branch to bb1 instead of bb7 on true condition.
The IR after the transform:
bb: %tmp = call i1 @llvm.experimental.widenable.condition() br i1 %tmp, label %bb2, label %bb1 bb1: ; preds = %bb br i1 undef, label %bb7, label %bb5 bb2: ; preds = %bb br i1 undef, label %bb1, label %bb4
Then, there is another transformation SimplifyCondBranchToCondBranch. It sees that bb2 branches to bb1 if the condition is true and that bb1 has the same condition. So instead of bb2->bb1->bb7 branches, it makes it just bb2->bb7 - the exact same IR before the first transform.
This patch limits the tryWidenCondBranchToCondBranch transform making it work only if the false block of widenable condition branch has no successors.
If that block has successors, then the possible impact of the transform is complicated. SimplifyCFG may apply other transforms after this one and produce unexpected results.
As far as I can see this transform only has impact when the no succesors condition stands.
Unless you know of any other transformation cycles, just say that we prevent a cyclic transformation with SimplifyCondBranchToCondBranch.