[llvm] [FixIrreducible][UnifyLoopExits] Support switch statements (PR #206567)
Robert Imschweiler via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 2 03:53:37 PDT 2026
================
@@ -309,20 +309,23 @@ static bool fixIrreducible(Cycle &C, CycleInfo &CI, DominatorTree &DT,
<< " -> " << printBasicBlock(Succ0)
<< (Succ0 && Succ1 ? " " : "") << printBasicBlock(Succ1)
<< '\n');
- } else if (CallBrInst *CallBr = dyn_cast<CallBrInst>(P->getTerminator())) {
- for (unsigned I = 0; I < CallBr->getNumSuccessors(); ++I) {
- BasicBlock *Succ = CallBr->getSuccessor(I);
+ } else if (isa<CallBrInst>(P->getTerminator()) ||
+ isa<SwitchInst>(P->getTerminator())) {
+ Instruction *Term = P->getTerminator();
+ for (unsigned I = 0; I < Term->getNumSuccessors(); ++I) {
+ BasicBlock *Succ = Term->getSuccessor(I);
if (Succ != Header)
continue;
- BasicBlock *NewSucc = SplitCallBrEdge(P, Succ, I, &DTU, &CI, LI);
+ BasicBlock *NewSucc = SplitMultiBrEdge(P, Succ, I, &DTU, &CI, LI);
CHub.addBranch(NewSucc, Succ);
----------------
ro-i wrote:
uhm, yeah. It's not exactly the same issue as in the other PR since that only dealt with conditional branches (sorry, I mixed that up in my head), but it's also related to a subset of the duplicate successor situation, I think. I guess that there is a testing gap (for callbr/switch) for the duplicate successor + phi node situation. Do you want to handle this (probably best in a separate PR)? (Otherwise, I can also fix the callbr situation first if you want.)
https://github.com/llvm/llvm-project/pull/206567
More information about the llvm-commits
mailing list