summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp40
1 files changed, 17 insertions, 23 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 4a94d351b98..ff6358b442a 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -2622,11 +2622,17 @@ void SelectionDAGBuilder::visitBitTestHeader(BitTestBlock &B,
// Subtract the minimum value.
SDValue SwitchOp = getValue(B.SValue);
EVT VT = SwitchOp.getValueType();
- SDValue RangeSub =
- DAG.getNode(ISD::SUB, dl, VT, SwitchOp, DAG.getConstant(B.First, dl, VT));
+ SDValue Sub = DAG.getNode(ISD::SUB, dl, VT, SwitchOp,
+ DAG.getConstant(B.First, dl, VT));
- // Determine the type of the test operands.
+ // Check range.
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
+ SDValue RangeCmp = DAG.getSetCC(
+ dl, TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(),
+ Sub.getValueType()),
+ Sub, DAG.getConstant(B.Range, dl, VT), ISD::SETUGT);
+
+ // Determine the type of the test operands.
bool UsePtrType = false;
if (!TLI.isTypeLegal(VT)) {
UsePtrType = true;
@@ -2639,7 +2645,6 @@ void SelectionDAGBuilder::visitBitTestHeader(BitTestBlock &B,
break;
}
}
- SDValue Sub = RangeSub;
if (UsePtrType) {
VT = TLI.getPointerTy(DAG.getDataLayout());
Sub = DAG.getZExtOrTrunc(Sub, dl, VT);
@@ -2655,24 +2660,16 @@ void SelectionDAGBuilder::visitBitTestHeader(BitTestBlock &B,
addSuccessorWithProb(SwitchBB, MBB, B.Prob);
SwitchBB->normalizeSuccProbs();
- SDValue Root = CopyTo;
- if (!B.OmitRangeCheck) {
- // Conditional branch to the default block.
- SDValue RangeCmp = DAG.getSetCC(dl,
- TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(),
- RangeSub.getValueType()),
- RangeSub, DAG.getConstant(B.Range, dl, RangeSub.getValueType()),
- ISD::SETUGT);
-
- Root = DAG.getNode(ISD::BRCOND, dl, MVT::Other, Root, RangeCmp,
- DAG.getBasicBlock(B.Default));
- }
+ SDValue BrRange = DAG.getNode(ISD::BRCOND, dl,
+ MVT::Other, CopyTo, RangeCmp,
+ DAG.getBasicBlock(B.Default));
// Avoid emitting unnecessary branches to the next block.
if (MBB != NextBlock(SwitchBB))
- Root = DAG.getNode(ISD::BR, dl, MVT::Other, Root, DAG.getBasicBlock(MBB));
+ BrRange = DAG.getNode(ISD::BR, dl, MVT::Other, BrRange,
+ DAG.getBasicBlock(MBB));
- DAG.setRoot(Root);
+ DAG.setRoot(BrRange);
}
/// visitBitTestCase - this function produces one "bit test"
@@ -10167,6 +10164,8 @@ void SelectionDAGBuilder::lowerWorkItem(SwitchWorkListItem W, Value *Cond,
break;
}
case CC_BitTests: {
+ // FIXME: If Fallthrough is unreachable, skip the range check.
+
// FIXME: Optimize away range check based on pivot comparisons.
BitTestBlock *BTB = &SL->BitTestCases[I->BTCasesIndex];
@@ -10187,11 +10186,6 @@ void SelectionDAGBuilder::lowerWorkItem(SwitchWorkListItem W, Value *Cond,
BTB->DefaultProb -= DefaultProb / 2;
}
- if (FallthroughUnreachable) {
- // Skip the range check if the fallthrough block is unreachable.
- BTB->OmitRangeCheck = true;
- }
-
// If we're in the right place, emit the bit test header right now.
if (CurMBB == SwitchMBB) {
visitBitTestHeader(*BTB, SwitchMBB);
OpenPOWER on IntegriCloud