Index: llvm/lib/Transforms/Utils/SCCPSolver.cpp =================================================================== --- llvm/lib/Transforms/Utils/SCCPSolver.cpp +++ llvm/lib/Transforms/Utils/SCCPSolver.cpp @@ -1509,81 +1509,58 @@ // we force the branch to go one way or the other to make the successor // values live. It doesn't really matter which way we force it. Instruction *TI = BB.getTerminator(); - if (auto *BI = dyn_cast(TI)) { - if (!BI->isConditional()) - continue; - if (!getValueState(BI->getCondition()).isUnknownOrUndef()) - continue; - - // If the input to SCCP is actually branch on undef, fix the undef to - // false. - if (isa(BI->getCondition())) { - BI->setCondition(ConstantInt::getFalse(BI->getContext())); - markEdgeExecutable(&BB, TI->getSuccessor(1)); - MadeChange = true; - continue; - } - - // Otherwise, it is a branch on a symbolic value which is currently - // considered to be undef. Make sure some edge is executable, so a - // branch on "undef" always flows somewhere. - // FIXME: Distinguish between dead code and an LLVM "undef" value. - BasicBlock *DefaultSuccessor = TI->getSuccessor(1); - if (markEdgeExecutable(&BB, DefaultSuccessor)) - MadeChange = true; - - continue; - } - - if (auto *IBR = dyn_cast(TI)) { - // Indirect branch with no successor ?. Its ok to assume it branches - // to no target. - if (IBR->getNumSuccessors() < 1) - continue; - - if (!getValueState(IBR->getAddress()).isUnknownOrUndef()) - continue; - - // If the input to SCCP is actually branch on undef, fix the undef to - // the first successor of the indirect branch. - if (isa(IBR->getAddress())) { - IBR->setAddress(BlockAddress::get(IBR->getSuccessor(0))); - markEdgeExecutable(&BB, IBR->getSuccessor(0)); - MadeChange = true; - continue; - } + auto* BI = dyn_cast(TI); + auto* IBR = dyn_cast(TI); + auto* SI = dyn_cast(TI); + if (BI || IBR || SI) { + BasicBlock *DefaultSuccessor = nullptr; + if (BI) { + if (!BI->isConditional() || + !getValueState(BI->getCondition()).isUnknownOrUndef()) + continue; - // Otherwise, it is a branch on a symbolic value which is currently - // considered to be undef. Make sure some edge is executable, so a - // branch on "undef" always flows somewhere. - // FIXME: IndirectBr on "undef" doesn't actually need to go anywhere: - // we can assume the branch has undefined behavior instead. - BasicBlock *DefaultSuccessor = IBR->getSuccessor(0); - if (markEdgeExecutable(&BB, DefaultSuccessor)) - MadeChange = true; + // If the input to SCCP is actually branch on undef, fix the undef to + // false. + if (isa(BI->getCondition())) { + BI->setCondition(ConstantInt::getFalse(BI->getContext())); + MadeChange = true; + } + DefaultSuccessor = TI->getSuccessor(1); + } else if (IBR) { + // Indirect branch with no successor? It's ok to assume it branches + // to no target. + if (IBR->getNumSuccessors() < 1 || + !getValueState(IBR->getAddress()).isUnknownOrUndef()) + continue; - continue; - } + // If the input to SCCP is actually branch on undef, fix the undef to + // the first successor of the indirect branch. + if (isa(IBR->getAddress())) { + IBR->setAddress(BlockAddress::get(IBR->getSuccessor(0))); + MadeChange = true; + } + DefaultSuccessor = IBR->getSuccessor(0); + } else if (SI) { + if (!SI->getNumCases() || + !getValueState(SI->getCondition()).isUnknownOrUndef()) + continue; - if (auto *SI = dyn_cast(TI)) { - if (!SI->getNumCases() || - !getValueState(SI->getCondition()).isUnknownOrUndef()) - continue; + // If the input to SCCP is actually switch on undef, fix the undef to + // the first constant. + if (isa(SI->getCondition())) { + SI->setCondition(SI->case_begin()->getCaseValue()); + MadeChange = true; + } + DefaultSuccessor = SI->case_begin()->getCaseSuccessor(); + } else + llvm_unreachable("Unexpected branch type."); - // If the input to SCCP is actually switch on undef, fix the undef to - // the first constant. - if (isa(SI->getCondition())) { - SI->setCondition(SI->case_begin()->getCaseValue()); - markEdgeExecutable(&BB, SI->case_begin()->getCaseSuccessor()); - MadeChange = true; - continue; - } + assert(DefaultSuccessor && "Default successor unset."); // Otherwise, it is a branch on a symbolic value which is currently // considered to be undef. Make sure some edge is executable, so a // branch on "undef" always flows somewhere. // FIXME: Distinguish between dead code and an LLVM "undef" value. - BasicBlock *DefaultSuccessor = SI->case_begin()->getCaseSuccessor(); if (markEdgeExecutable(&BB, DefaultSuccessor)) MadeChange = true;