mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-09 11:25:55 +00:00
Switch lowering: remove unnecessary ConstantInt casts. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232729 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -1694,7 +1694,7 @@ void SelectionDAGBuilder::visitSwitchCase(CaseBlock &CB,
|
|||||||
assert(CB.CC == ISD::SETLE && "Can handle only LE ranges now");
|
assert(CB.CC == ISD::SETLE && "Can handle only LE ranges now");
|
||||||
|
|
||||||
const APInt& Low = cast<ConstantInt>(CB.CmpLHS)->getValue();
|
const APInt& Low = cast<ConstantInt>(CB.CmpLHS)->getValue();
|
||||||
const APInt& High = cast<ConstantInt>(CB.CmpRHS)->getValue();
|
const APInt& High = cast<ConstantInt>(CB.CmpRHS)->getValue();
|
||||||
|
|
||||||
SDValue CmpOp = getValue(CB.CmpMHS);
|
SDValue CmpOp = getValue(CB.CmpMHS);
|
||||||
EVT VT = CmpOp.getValueType();
|
EVT VT = CmpOp.getValueType();
|
||||||
@@ -2165,8 +2165,8 @@ bool SelectionDAGBuilder::handleSmallSwitchRange(CaseRec& CR,
|
|||||||
Case &Big = *(CR.Range.second-1);
|
Case &Big = *(CR.Range.second-1);
|
||||||
|
|
||||||
if (Small.Low == Small.High && Big.Low == Big.High && Small.BB == Big.BB) {
|
if (Small.Low == Small.High && Big.Low == Big.High && Small.BB == Big.BB) {
|
||||||
const APInt& SmallValue = cast<ConstantInt>(Small.Low)->getValue();
|
const APInt& SmallValue = Small.Low->getValue();
|
||||||
const APInt& BigValue = cast<ConstantInt>(Big.Low)->getValue();
|
const APInt& BigValue = Big.Low->getValue();
|
||||||
|
|
||||||
// Check that there is only one bit different.
|
// Check that there is only one bit different.
|
||||||
if (BigValue.countPopulation() == SmallValue.countPopulation() + 1 &&
|
if (BigValue.countPopulation() == SmallValue.countPopulation() + 1 &&
|
||||||
@@ -2306,8 +2306,8 @@ bool SelectionDAGBuilder::handleJTSwitchCase(CaseRec &CR,
|
|||||||
Case& FrontCase = *CR.Range.first;
|
Case& FrontCase = *CR.Range.first;
|
||||||
Case& BackCase = *(CR.Range.second-1);
|
Case& BackCase = *(CR.Range.second-1);
|
||||||
|
|
||||||
const APInt &First = cast<ConstantInt>(FrontCase.Low)->getValue();
|
const APInt &First = FrontCase.Low->getValue();
|
||||||
const APInt &Last = cast<ConstantInt>(BackCase.High)->getValue();
|
const APInt &Last = BackCase.High->getValue();
|
||||||
|
|
||||||
APInt TSize(First.getBitWidth(), 0);
|
APInt TSize(First.getBitWidth(), 0);
|
||||||
for (CaseItr I = CR.Range.first, E = CR.Range.second; I != E; ++I)
|
for (CaseItr I = CR.Range.first, E = CR.Range.second; I != E; ++I)
|
||||||
@@ -2357,8 +2357,8 @@ bool SelectionDAGBuilder::handleJTSwitchCase(CaseRec &CR,
|
|||||||
std::vector<MachineBasicBlock*> DestBBs;
|
std::vector<MachineBasicBlock*> DestBBs;
|
||||||
APInt TEI = First;
|
APInt TEI = First;
|
||||||
for (CaseItr I = CR.Range.first, E = CR.Range.second; I != E; ++TEI) {
|
for (CaseItr I = CR.Range.first, E = CR.Range.second; I != E; ++TEI) {
|
||||||
const APInt &Low = cast<ConstantInt>(I->Low)->getValue();
|
const APInt &Low = I->Low->getValue();
|
||||||
const APInt &High = cast<ConstantInt>(I->High)->getValue();
|
const APInt &High = I->High->getValue();
|
||||||
|
|
||||||
if (Low.sle(TEI) && TEI.sle(High)) {
|
if (Low.sle(TEI) && TEI.sle(High)) {
|
||||||
DestBBs.push_back(I->BB);
|
DestBBs.push_back(I->BB);
|
||||||
@@ -2422,8 +2422,8 @@ bool SelectionDAGBuilder::handleBTSplitSwitchCase(CaseRec& CR,
|
|||||||
// Size is the number of Cases represented by this range.
|
// Size is the number of Cases represented by this range.
|
||||||
unsigned Size = CR.Range.second - CR.Range.first;
|
unsigned Size = CR.Range.second - CR.Range.first;
|
||||||
|
|
||||||
const APInt &First = cast<ConstantInt>(FrontCase.Low)->getValue();
|
const APInt &First = FrontCase.Low->getValue();
|
||||||
const APInt &Last = cast<ConstantInt>(BackCase.High)->getValue();
|
const APInt &Last = BackCase.High->getValue();
|
||||||
double FMetric = 0;
|
double FMetric = 0;
|
||||||
CaseItr Pivot = CR.Range.first + Size/2;
|
CaseItr Pivot = CR.Range.first + Size/2;
|
||||||
|
|
||||||
@@ -2442,8 +2442,8 @@ bool SelectionDAGBuilder::handleBTSplitSwitchCase(CaseRec& CR,
|
|||||||
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
|
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
|
||||||
for (CaseItr I = CR.Range.first, J=I+1, E = CR.Range.second;
|
for (CaseItr I = CR.Range.first, J=I+1, E = CR.Range.second;
|
||||||
J!=E; ++I, ++J) {
|
J!=E; ++I, ++J) {
|
||||||
const APInt &LEnd = cast<ConstantInt>(I->High)->getValue();
|
const APInt &LEnd = I->High->getValue();
|
||||||
const APInt &RBegin = cast<ConstantInt>(J->Low)->getValue();
|
const APInt &RBegin = J->Low->getValue();
|
||||||
APInt Range = ComputeRange(LEnd, RBegin);
|
APInt Range = ComputeRange(LEnd, RBegin);
|
||||||
assert((Range - 2ULL).isNonNegative() &&
|
assert((Range - 2ULL).isNonNegative() &&
|
||||||
"Invalid case distance");
|
"Invalid case distance");
|
||||||
@@ -2498,7 +2498,7 @@ void SelectionDAGBuilder::splitSwitchCase(CaseRec &CR, CaseItr Pivot,
|
|||||||
|
|
||||||
CaseRange LHSR(CR.Range.first, Pivot);
|
CaseRange LHSR(CR.Range.first, Pivot);
|
||||||
CaseRange RHSR(Pivot, CR.Range.second);
|
CaseRange RHSR(Pivot, CR.Range.second);
|
||||||
const Constant *C = Pivot->Low;
|
const ConstantInt *C = Pivot->Low;
|
||||||
MachineBasicBlock *FalseBB = nullptr, *TrueBB = nullptr;
|
MachineBasicBlock *FalseBB = nullptr, *TrueBB = nullptr;
|
||||||
|
|
||||||
// We know that we branch to the LHS if the Value being switched on is
|
// We know that we branch to the LHS if the Value being switched on is
|
||||||
@@ -2508,8 +2508,7 @@ void SelectionDAGBuilder::splitSwitchCase(CaseRec &CR, CaseItr Pivot,
|
|||||||
// Pivot's Value, then we can branch directly to the LHS's Target,
|
// Pivot's Value, then we can branch directly to the LHS's Target,
|
||||||
// rather than creating a leaf node for it.
|
// rather than creating a leaf node for it.
|
||||||
if ((LHSR.second - LHSR.first) == 1 && LHSR.first->High == CR.GE &&
|
if ((LHSR.second - LHSR.first) == 1 && LHSR.first->High == CR.GE &&
|
||||||
cast<ConstantInt>(C)->getValue() ==
|
C->getValue() == (CR.GE->getValue() + 1LL)) {
|
||||||
(cast<ConstantInt>(CR.GE)->getValue() + 1LL)) {
|
|
||||||
TrueBB = LHSR.first->BB;
|
TrueBB = LHSR.first->BB;
|
||||||
} else {
|
} else {
|
||||||
TrueBB = CurMF->CreateMachineBasicBlock(LLVMBB);
|
TrueBB = CurMF->CreateMachineBasicBlock(LLVMBB);
|
||||||
@@ -2525,8 +2524,7 @@ void SelectionDAGBuilder::splitSwitchCase(CaseRec &CR, CaseItr Pivot,
|
|||||||
// is CR.LT - 1, then we can branch directly to the target block for
|
// is CR.LT - 1, then we can branch directly to the target block for
|
||||||
// the current Case Value, rather than emitting a RHS leaf node for it.
|
// the current Case Value, rather than emitting a RHS leaf node for it.
|
||||||
if ((RHSR.second - RHSR.first) == 1 && CR.LT &&
|
if ((RHSR.second - RHSR.first) == 1 && CR.LT &&
|
||||||
cast<ConstantInt>(RHSR.first->Low)->getValue() ==
|
RHSR.first->Low->getValue() == (CR.LT->getValue() - 1LL)) {
|
||||||
(cast<ConstantInt>(CR.LT)->getValue() - 1LL)) {
|
|
||||||
FalseBB = RHSR.first->BB;
|
FalseBB = RHSR.first->BB;
|
||||||
} else {
|
} else {
|
||||||
FalseBB = CurMF->CreateMachineBasicBlock(LLVMBB);
|
FalseBB = CurMF->CreateMachineBasicBlock(LLVMBB);
|
||||||
@@ -2590,8 +2588,8 @@ bool SelectionDAGBuilder::handleBitTestsSwitchCase(CaseRec& CR,
|
|||||||
<< "Total number of comparisons: " << numCmps << '\n');
|
<< "Total number of comparisons: " << numCmps << '\n');
|
||||||
|
|
||||||
// Compute span of values.
|
// Compute span of values.
|
||||||
const APInt& minValue = cast<ConstantInt>(FrontCase.Low)->getValue();
|
const APInt& minValue = FrontCase.Low->getValue();
|
||||||
const APInt& maxValue = cast<ConstantInt>(BackCase.High)->getValue();
|
const APInt& maxValue = BackCase.High->getValue();
|
||||||
APInt cmpRange = maxValue - minValue;
|
APInt cmpRange = maxValue - minValue;
|
||||||
|
|
||||||
DEBUG(dbgs() << "Compare range: " << cmpRange << '\n'
|
DEBUG(dbgs() << "Compare range: " << cmpRange << '\n'
|
||||||
@@ -2631,8 +2629,8 @@ bool SelectionDAGBuilder::handleBitTestsSwitchCase(CaseRec& CR,
|
|||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
const APInt& lowValue = cast<ConstantInt>(I->Low)->getValue();
|
const APInt& lowValue = I->Low->getValue();
|
||||||
const APInt& highValue = cast<ConstantInt>(I->High)->getValue();
|
const APInt& highValue = I->High->getValue();
|
||||||
|
|
||||||
uint64_t lo = (lowValue - lowBound).getZExtValue();
|
uint64_t lo = (lowValue - lowBound).getZExtValue();
|
||||||
uint64_t hi = (highValue - lowBound).getZExtValue();
|
uint64_t hi = (highValue - lowBound).getZExtValue();
|
||||||
@@ -2705,8 +2703,8 @@ void SelectionDAGBuilder::Clusterify(CaseVector& Cases,
|
|||||||
// invalidated by erase if we hold on to it
|
// invalidated by erase if we hold on to it
|
||||||
for (CaseItr I = Cases.begin(), J = std::next(Cases.begin());
|
for (CaseItr I = Cases.begin(), J = std::next(Cases.begin());
|
||||||
J != Cases.end(); ) {
|
J != Cases.end(); ) {
|
||||||
const APInt& nextValue = cast<ConstantInt>(J->Low)->getValue();
|
const APInt& nextValue = J->Low->getValue();
|
||||||
const APInt& currentValue = cast<ConstantInt>(I->High)->getValue();
|
const APInt& currentValue = I->High->getValue();
|
||||||
MachineBasicBlock* nextBB = J->BB;
|
MachineBasicBlock* nextBB = J->BB;
|
||||||
MachineBasicBlock* currentBB = I->BB;
|
MachineBasicBlock* currentBB = I->BB;
|
||||||
|
|
||||||
|
@@ -137,19 +137,19 @@ private:
|
|||||||
/// Case - A struct to record the Value for a switch case, and the
|
/// Case - A struct to record the Value for a switch case, and the
|
||||||
/// case's target basic block.
|
/// case's target basic block.
|
||||||
struct Case {
|
struct Case {
|
||||||
const Constant *Low;
|
const ConstantInt *Low;
|
||||||
const Constant *High;
|
const ConstantInt *High;
|
||||||
MachineBasicBlock* BB;
|
MachineBasicBlock* BB;
|
||||||
uint32_t ExtraWeight;
|
uint32_t ExtraWeight;
|
||||||
|
|
||||||
Case() : Low(nullptr), High(nullptr), BB(nullptr), ExtraWeight(0) { }
|
Case() : Low(nullptr), High(nullptr), BB(nullptr), ExtraWeight(0) { }
|
||||||
Case(const Constant *low, const Constant *high, MachineBasicBlock *bb,
|
Case(const ConstantInt *low, const ConstantInt *high, MachineBasicBlock *bb,
|
||||||
uint32_t extraweight) : Low(low), High(high), BB(bb),
|
uint32_t extraweight) : Low(low), High(high), BB(bb),
|
||||||
ExtraWeight(extraweight) { }
|
ExtraWeight(extraweight) { }
|
||||||
|
|
||||||
APInt size() const {
|
APInt size() const {
|
||||||
const APInt &rHigh = cast<ConstantInt>(High)->getValue();
|
const APInt &rHigh = High->getValue();
|
||||||
const APInt &rLow = cast<ConstantInt>(Low)->getValue();
|
const APInt &rLow = Low->getValue();
|
||||||
return (rHigh - rLow + 1ULL);
|
return (rHigh - rLow + 1ULL);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -173,7 +173,7 @@ private:
|
|||||||
/// CaseRec - A struct with ctor used in lowering switches to a binary tree
|
/// CaseRec - A struct with ctor used in lowering switches to a binary tree
|
||||||
/// of conditional branches.
|
/// of conditional branches.
|
||||||
struct CaseRec {
|
struct CaseRec {
|
||||||
CaseRec(MachineBasicBlock *bb, const Constant *lt, const Constant *ge,
|
CaseRec(MachineBasicBlock *bb, const ConstantInt *lt, const ConstantInt *ge,
|
||||||
CaseRange r) :
|
CaseRange r) :
|
||||||
CaseBB(bb), LT(lt), GE(ge), Range(r) {}
|
CaseBB(bb), LT(lt), GE(ge), Range(r) {}
|
||||||
|
|
||||||
@@ -181,8 +181,8 @@ private:
|
|||||||
MachineBasicBlock *CaseBB;
|
MachineBasicBlock *CaseBB;
|
||||||
/// LT, GE - If nonzero, we know the current case value must be less-than or
|
/// LT, GE - If nonzero, we know the current case value must be less-than or
|
||||||
/// greater-than-or-equal-to these Constants.
|
/// greater-than-or-equal-to these Constants.
|
||||||
const Constant *LT;
|
const ConstantInt *LT;
|
||||||
const Constant *GE;
|
const ConstantInt *GE;
|
||||||
/// Range - A pair of iterators representing the range of case values to be
|
/// Range - A pair of iterators representing the range of case values to be
|
||||||
/// processed at this point in the binary search tree.
|
/// processed at this point in the binary search tree.
|
||||||
CaseRange Range;
|
CaseRange Range;
|
||||||
@@ -194,10 +194,7 @@ private:
|
|||||||
/// WARNING: Case ranges should be disjoint!
|
/// WARNING: Case ranges should be disjoint!
|
||||||
struct CaseCmp {
|
struct CaseCmp {
|
||||||
bool operator()(const Case &C1, const Case &C2) {
|
bool operator()(const Case &C1, const Case &C2) {
|
||||||
assert(isa<ConstantInt>(C1.Low) && isa<ConstantInt>(C2.High));
|
return C1.Low->getValue().slt(C2.High->getValue());
|
||||||
const ConstantInt* CI1 = cast<const ConstantInt>(C1.Low);
|
|
||||||
const ConstantInt* CI2 = cast<const ConstantInt>(C2.High);
|
|
||||||
return CI1->getValue().slt(CI2->getValue());
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user