diff --git a/llvm/include/llvm/CodeGen/SwitchLoweringUtils.h b/llvm/include/llvm/CodeGen/SwitchLoweringUtils.h --- a/llvm/include/llvm/CodeGen/SwitchLoweringUtils.h +++ b/llvm/include/llvm/CodeGen/SwitchLoweringUtils.h @@ -183,12 +183,12 @@ const Value *SValue; MachineBasicBlock *HeaderBB; bool Emitted; - bool OmitRangeCheck; + bool FallthroughUnreachable; JumpTableHeader(APInt F, APInt L, const Value *SV, MachineBasicBlock *H, bool E = false) : First(std::move(F)), Last(std::move(L)), SValue(SV), HeaderBB(H), - Emitted(E), OmitRangeCheck(false) {} + Emitted(E), FallthroughUnreachable(false) {} }; using JumpTableBlock = std::pair; @@ -218,14 +218,14 @@ BitTestInfo Cases; BranchProbability Prob; BranchProbability DefaultProb; - bool OmitRangeCheck; + bool FallthroughUnreachable; BitTestBlock(APInt F, APInt R, const Value *SV, unsigned Rg, MVT RgVT, bool E, bool CR, MachineBasicBlock *P, MachineBasicBlock *D, BitTestInfo C, BranchProbability Pr) : First(std::move(F)), Range(std::move(R)), SValue(SV), Reg(Rg), RegVT(RgVT), Emitted(E), ContiguousRange(CR), Parent(P), Default(D), - Cases(std::move(C)), Prob(Pr), OmitRangeCheck(false) {} + Cases(std::move(C)), Prob(Pr), FallthroughUnreachable(false) {} }; /// Return the range of values within a range. diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp --- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -785,7 +785,7 @@ JT.Reg = Sub.getReg(0); - if (JTH.OmitRangeCheck) { + if (JTH.FallthroughUnreachable) { if (JT.MBB != HeaderBB->getNextNode()) MIB.buildBr(*JT.MBB); return true; @@ -937,11 +937,10 @@ } } - // Skip the range check if the fallthrough block is unreachable. if (FallthroughUnreachable) - JTH->OmitRangeCheck = true; + JTH->FallthroughUnreachable = true; - if (!JTH->OmitRangeCheck) + if (!JTH->FallthroughUnreachable) addSuccessorWithProb(CurMBB, Fallthrough, FallthroughProb); addSuccessorWithProb(CurMBB, JumpMBB, JumpProb); CurMBB->normalizeSuccProbs(); @@ -1024,13 +1023,13 @@ MachineBasicBlock *MBB = B.Cases[0].ThisBB; - if (!B.OmitRangeCheck) + if (!B.FallthroughUnreachable) addSuccessorWithProb(SwitchBB, B.Default, B.DefaultProb); addSuccessorWithProb(SwitchBB, MBB, B.Prob); SwitchBB->normalizeSuccProbs(); - if (!B.OmitRangeCheck) { + if (!B.FallthroughUnreachable) { // Conditional branch to the default block. auto RangeCst = MIB.buildConstant(SwitchOpTy, B.Range); auto RangeCmp = MIB.buildICmp(CmpInst::Predicate::ICMP_UGT, LLT::scalar(1), @@ -1130,10 +1129,8 @@ BTB->DefaultProb -= DefaultProb / 2; } - if (FallthroughUnreachable) { - // Skip the range check if the fallthrough block is unreachable. - BTB->OmitRangeCheck = true; - } + if (FallthroughUnreachable) + BTB->FallthroughUnreachable = true; // If we're in the right place, emit the bit test header right now. if (CurMBB == SwitchMBB) { @@ -3019,7 +3016,7 @@ // test, and delete the last bit test. MachineBasicBlock *NextMBB; - if ((BTB.ContiguousRange || BTB.OmitRangeCheck) && j + 2 == ej) { + if ((BTB.ContiguousRange || BTB.FallthroughUnreachable) && j + 2 == ej) { // Second-to-last bit-test with contiguous range: fall through to the // target of the final bit test. NextMBB = BTB.Cases[j + 1].TargetBB; @@ -3033,7 +3030,7 @@ emitBitTestCase(BTB, NextMBB, UnhandledProb, BTB.Reg, BTB.Cases[j], MBB); - if ((BTB.ContiguousRange || BTB.OmitRangeCheck) && j + 2 == ej) { + if ((BTB.ContiguousRange || BTB.FallthroughUnreachable) && j + 2 == ej) { // We need to record the replacement phi edge here that normally // happens in emitBitTestCase before we delete the case, otherwise the // phi edge will be lost. diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -2572,7 +2572,7 @@ JumpTableReg, SwitchOp); JT.Reg = JumpTableReg; - if (!JTH.OmitRangeCheck) { + if (!JTH.FallthroughUnreachable) { // Emit the range check for the jump table, and branch to the default block // for the switch statement if the value being switched on exceeds the // largest case in the switch. @@ -2784,13 +2784,13 @@ MachineBasicBlock* MBB = B.Cases[0].ThisBB; - if (!B.OmitRangeCheck) + if (!B.FallthroughUnreachable) addSuccessorWithProb(SwitchBB, B.Default, B.DefaultProb); addSuccessorWithProb(SwitchBB, MBB, B.Prob); SwitchBB->normalizeSuccProbs(); SDValue Root = CopyTo; - if (!B.OmitRangeCheck) { + if (!B.FallthroughUnreachable) { // Conditional branch to the default block. SDValue RangeCmp = DAG.getSetCC(dl, TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), @@ -10826,12 +10826,10 @@ } } - if (FallthroughUnreachable) { - // Skip the range check if the fallthrough block is unreachable. - JTH->OmitRangeCheck = true; - } + if (FallthroughUnreachable) + JTH->FallthroughUnreachable = true; - if (!JTH->OmitRangeCheck) + if (!JTH->FallthroughUnreachable) addSuccessorWithProb(CurMBB, Fallthrough, FallthroughProb); addSuccessorWithProb(CurMBB, JumpMBB, JumpProb); CurMBB->normalizeSuccProbs(); @@ -10869,9 +10867,8 @@ BTB->DefaultProb -= DefaultProb / 2; } - // Skip the range check if the fallthrough block is unreachable. if (FallthroughUnreachable) - BTB->OmitRangeCheck = true; + BTB->FallthroughUnreachable = true; // If we're in the right place, emit the bit test header right now. if (CurMBB == SwitchMBB) { diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -1864,7 +1864,7 @@ // test, and delete the last bit test. MachineBasicBlock *NextMBB; - if ((BTB.ContiguousRange || BTB.OmitRangeCheck) && j + 2 == ej) { + if ((BTB.ContiguousRange || BTB.FallthroughUnreachable) && j + 2 == ej) { // Second-to-last bit-test with contiguous range or omitted range // check: fall through to the target of the final bit test. NextMBB = BTB.Cases[j + 1].TargetBB; @@ -1883,7 +1883,7 @@ SDB->clear(); CodeGenAndEmitDAG(); - if ((BTB.ContiguousRange || BTB.OmitRangeCheck) && j + 2 == ej) { + if ((BTB.ContiguousRange || BTB.FallthroughUnreachable) && j + 2 == ej) { // Since we're not going to use the final bit test, remove it. BTB.Cases.pop_back(); break;