mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-04 06:09:05 +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:
parent
07121ea974
commit
cd7ece1a89
@ -1694,7 +1694,7 @@ void SelectionDAGBuilder::visitSwitchCase(CaseBlock &CB,
|
||||
assert(CB.CC == ISD::SETLE && "Can handle only LE ranges now");
|
||||
|
||||
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);
|
||||
EVT VT = CmpOp.getValueType();
|
||||
@ -2165,8 +2165,8 @@ bool SelectionDAGBuilder::handleSmallSwitchRange(CaseRec& CR,
|
||||
Case &Big = *(CR.Range.second-1);
|
||||
|
||||
if (Small.Low == Small.High && Big.Low == Big.High && Small.BB == Big.BB) {
|
||||
const APInt& SmallValue = cast<ConstantInt>(Small.Low)->getValue();
|
||||
const APInt& BigValue = cast<ConstantInt>(Big.Low)->getValue();
|
||||
const APInt& SmallValue = Small.Low->getValue();
|
||||
const APInt& BigValue = Big.Low->getValue();
|
||||
|
||||
// Check that there is only one bit different.
|
||||
if (BigValue.countPopulation() == SmallValue.countPopulation() + 1 &&
|
||||
@ -2306,8 +2306,8 @@ bool SelectionDAGBuilder::handleJTSwitchCase(CaseRec &CR,
|
||||
Case& FrontCase = *CR.Range.first;
|
||||
Case& BackCase = *(CR.Range.second-1);
|
||||
|
||||
const APInt &First = cast<ConstantInt>(FrontCase.Low)->getValue();
|
||||
const APInt &Last = cast<ConstantInt>(BackCase.High)->getValue();
|
||||
const APInt &First = FrontCase.Low->getValue();
|
||||
const APInt &Last = BackCase.High->getValue();
|
||||
|
||||
APInt TSize(First.getBitWidth(), 0);
|
||||
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;
|
||||
APInt TEI = First;
|
||||
for (CaseItr I = CR.Range.first, E = CR.Range.second; I != E; ++TEI) {
|
||||
const APInt &Low = cast<ConstantInt>(I->Low)->getValue();
|
||||
const APInt &High = cast<ConstantInt>(I->High)->getValue();
|
||||
const APInt &Low = I->Low->getValue();
|
||||
const APInt &High = I->High->getValue();
|
||||
|
||||
if (Low.sle(TEI) && TEI.sle(High)) {
|
||||
DestBBs.push_back(I->BB);
|
||||
@ -2422,8 +2422,8 @@ bool SelectionDAGBuilder::handleBTSplitSwitchCase(CaseRec& CR,
|
||||
// Size is the number of Cases represented by this range.
|
||||
unsigned Size = CR.Range.second - CR.Range.first;
|
||||
|
||||
const APInt &First = cast<ConstantInt>(FrontCase.Low)->getValue();
|
||||
const APInt &Last = cast<ConstantInt>(BackCase.High)->getValue();
|
||||
const APInt &First = FrontCase.Low->getValue();
|
||||
const APInt &Last = BackCase.High->getValue();
|
||||
double FMetric = 0;
|
||||
CaseItr Pivot = CR.Range.first + Size/2;
|
||||
|
||||
@ -2442,8 +2442,8 @@ bool SelectionDAGBuilder::handleBTSplitSwitchCase(CaseRec& CR,
|
||||
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
|
||||
for (CaseItr I = CR.Range.first, J=I+1, E = CR.Range.second;
|
||||
J!=E; ++I, ++J) {
|
||||
const APInt &LEnd = cast<ConstantInt>(I->High)->getValue();
|
||||
const APInt &RBegin = cast<ConstantInt>(J->Low)->getValue();
|
||||
const APInt &LEnd = I->High->getValue();
|
||||
const APInt &RBegin = J->Low->getValue();
|
||||
APInt Range = ComputeRange(LEnd, RBegin);
|
||||
assert((Range - 2ULL).isNonNegative() &&
|
||||
"Invalid case distance");
|
||||
@ -2498,7 +2498,7 @@ void SelectionDAGBuilder::splitSwitchCase(CaseRec &CR, CaseItr Pivot,
|
||||
|
||||
CaseRange LHSR(CR.Range.first, Pivot);
|
||||
CaseRange RHSR(Pivot, CR.Range.second);
|
||||
const Constant *C = Pivot->Low;
|
||||
const ConstantInt *C = Pivot->Low;
|
||||
MachineBasicBlock *FalseBB = nullptr, *TrueBB = nullptr;
|
||||
|
||||
// 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,
|
||||
// rather than creating a leaf node for it.
|
||||
if ((LHSR.second - LHSR.first) == 1 && LHSR.first->High == CR.GE &&
|
||||
cast<ConstantInt>(C)->getValue() ==
|
||||
(cast<ConstantInt>(CR.GE)->getValue() + 1LL)) {
|
||||
C->getValue() == (CR.GE->getValue() + 1LL)) {
|
||||
TrueBB = LHSR.first->BB;
|
||||
} else {
|
||||
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
|
||||
// the current Case Value, rather than emitting a RHS leaf node for it.
|
||||
if ((RHSR.second - RHSR.first) == 1 && CR.LT &&
|
||||
cast<ConstantInt>(RHSR.first->Low)->getValue() ==
|
||||
(cast<ConstantInt>(CR.LT)->getValue() - 1LL)) {
|
||||
RHSR.first->Low->getValue() == (CR.LT->getValue() - 1LL)) {
|
||||
FalseBB = RHSR.first->BB;
|
||||
} else {
|
||||
FalseBB = CurMF->CreateMachineBasicBlock(LLVMBB);
|
||||
@ -2590,8 +2588,8 @@ bool SelectionDAGBuilder::handleBitTestsSwitchCase(CaseRec& CR,
|
||||
<< "Total number of comparisons: " << numCmps << '\n');
|
||||
|
||||
// Compute span of values.
|
||||
const APInt& minValue = cast<ConstantInt>(FrontCase.Low)->getValue();
|
||||
const APInt& maxValue = cast<ConstantInt>(BackCase.High)->getValue();
|
||||
const APInt& minValue = FrontCase.Low->getValue();
|
||||
const APInt& maxValue = BackCase.High->getValue();
|
||||
APInt cmpRange = maxValue - minValue;
|
||||
|
||||
DEBUG(dbgs() << "Compare range: " << cmpRange << '\n'
|
||||
@ -2631,8 +2629,8 @@ bool SelectionDAGBuilder::handleBitTestsSwitchCase(CaseRec& CR,
|
||||
count++;
|
||||
}
|
||||
|
||||
const APInt& lowValue = cast<ConstantInt>(I->Low)->getValue();
|
||||
const APInt& highValue = cast<ConstantInt>(I->High)->getValue();
|
||||
const APInt& lowValue = I->Low->getValue();
|
||||
const APInt& highValue = I->High->getValue();
|
||||
|
||||
uint64_t lo = (lowValue - 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
|
||||
for (CaseItr I = Cases.begin(), J = std::next(Cases.begin());
|
||||
J != Cases.end(); ) {
|
||||
const APInt& nextValue = cast<ConstantInt>(J->Low)->getValue();
|
||||
const APInt& currentValue = cast<ConstantInt>(I->High)->getValue();
|
||||
const APInt& nextValue = J->Low->getValue();
|
||||
const APInt& currentValue = I->High->getValue();
|
||||
MachineBasicBlock* nextBB = J->BB;
|
||||
MachineBasicBlock* currentBB = I->BB;
|
||||
|
||||
|
@ -137,19 +137,19 @@ private:
|
||||
/// Case - A struct to record the Value for a switch case, and the
|
||||
/// case's target basic block.
|
||||
struct Case {
|
||||
const Constant *Low;
|
||||
const Constant *High;
|
||||
const ConstantInt *Low;
|
||||
const ConstantInt *High;
|
||||
MachineBasicBlock* BB;
|
||||
uint32_t ExtraWeight;
|
||||
|
||||
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),
|
||||
ExtraWeight(extraweight) { }
|
||||
|
||||
APInt size() const {
|
||||
const APInt &rHigh = cast<ConstantInt>(High)->getValue();
|
||||
const APInt &rLow = cast<ConstantInt>(Low)->getValue();
|
||||
const APInt &rHigh = High->getValue();
|
||||
const APInt &rLow = Low->getValue();
|
||||
return (rHigh - rLow + 1ULL);
|
||||
}
|
||||
};
|
||||
@ -173,7 +173,7 @@ private:
|
||||
/// CaseRec - A struct with ctor used in lowering switches to a binary tree
|
||||
/// of conditional branches.
|
||||
struct CaseRec {
|
||||
CaseRec(MachineBasicBlock *bb, const Constant *lt, const Constant *ge,
|
||||
CaseRec(MachineBasicBlock *bb, const ConstantInt *lt, const ConstantInt *ge,
|
||||
CaseRange r) :
|
||||
CaseBB(bb), LT(lt), GE(ge), Range(r) {}
|
||||
|
||||
@ -181,8 +181,8 @@ private:
|
||||
MachineBasicBlock *CaseBB;
|
||||
/// LT, GE - If nonzero, we know the current case value must be less-than or
|
||||
/// greater-than-or-equal-to these Constants.
|
||||
const Constant *LT;
|
||||
const Constant *GE;
|
||||
const ConstantInt *LT;
|
||||
const ConstantInt *GE;
|
||||
/// Range - A pair of iterators representing the range of case values to be
|
||||
/// processed at this point in the binary search tree.
|
||||
CaseRange Range;
|
||||
@ -194,10 +194,7 @@ private:
|
||||
/// WARNING: Case ranges should be disjoint!
|
||||
struct CaseCmp {
|
||||
bool operator()(const Case &C1, const Case &C2) {
|
||||
assert(isa<ConstantInt>(C1.Low) && isa<ConstantInt>(C2.High));
|
||||
const ConstantInt* CI1 = cast<const ConstantInt>(C1.Low);
|
||||
const ConstantInt* CI2 = cast<const ConstantInt>(C2.High);
|
||||
return CI1->getValue().slt(CI2->getValue());
|
||||
return C1.Low->getValue().slt(C2.High->getValue());
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user