mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-15 06:29:05 +00:00
Make the operations of APInt variables more efficient.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36260 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -747,35 +747,34 @@ namespace {
|
|||||||
case ICmpInst::ICMP_SLT:
|
case ICmpInst::ICMP_SLT:
|
||||||
return ConstantRange(APInt::getSignedMinValue(W), CR.getSignedMax());
|
return ConstantRange(APInt::getSignedMinValue(W), CR.getSignedMax());
|
||||||
case ICmpInst::ICMP_ULE: {
|
case ICmpInst::ICMP_ULE: {
|
||||||
APInt UMax = CR.getUnsignedMax();
|
APInt UMax(CR.getUnsignedMax());
|
||||||
if (UMax == APInt::getMaxValue(W))
|
if (UMax == APInt::getMaxValue(W))
|
||||||
return ConstantRange(W);
|
return ConstantRange(W);
|
||||||
return ConstantRange(APInt::getMinValue(W), UMax + 1);
|
return ConstantRange(APInt::getMinValue(W), UMax + 1);
|
||||||
}
|
}
|
||||||
case ICmpInst::ICMP_SLE: {
|
case ICmpInst::ICMP_SLE: {
|
||||||
APInt SMax = CR.getSignedMax();
|
APInt SMax(CR.getSignedMax());
|
||||||
if (SMax == APInt::getSignedMaxValue(W) ||
|
if (SMax == APInt::getSignedMaxValue(W) ||
|
||||||
SMax + 1 == APInt::getSignedMaxValue(W))
|
SMax + 1 == APInt::getSignedMaxValue(W))
|
||||||
return ConstantRange(W);
|
return ConstantRange(W);
|
||||||
return ConstantRange(APInt::getSignedMinValue(W), SMax + 1);
|
return ConstantRange(APInt::getSignedMinValue(W), SMax + 1);
|
||||||
}
|
}
|
||||||
case ICmpInst::ICMP_UGT:
|
case ICmpInst::ICMP_UGT:
|
||||||
return ConstantRange(CR.getUnsignedMin() + 1,
|
return ConstantRange(CR.getUnsignedMin() + 1, APInt::getNullValue(W));
|
||||||
APInt::getMaxValue(W) + 1);
|
|
||||||
case ICmpInst::ICMP_SGT:
|
case ICmpInst::ICMP_SGT:
|
||||||
return ConstantRange(CR.getSignedMin() + 1,
|
return ConstantRange(CR.getSignedMin() + 1,
|
||||||
APInt::getSignedMaxValue(W) + 1);
|
APInt::getSignedMinValue(W));
|
||||||
case ICmpInst::ICMP_UGE: {
|
case ICmpInst::ICMP_UGE: {
|
||||||
APInt UMin = CR.getUnsignedMin();
|
APInt UMin(CR.getUnsignedMin());
|
||||||
if (UMin == APInt::getMinValue(W))
|
if (UMin == APInt::getMinValue(W))
|
||||||
return ConstantRange(W);
|
return ConstantRange(W);
|
||||||
return ConstantRange(UMin, APInt::getMaxValue(W) + 1);
|
return ConstantRange(UMin, APInt::getNullValue(W));
|
||||||
}
|
}
|
||||||
case ICmpInst::ICMP_SGE: {
|
case ICmpInst::ICMP_SGE: {
|
||||||
APInt SMin = CR.getSignedMin();
|
APInt SMin(CR.getSignedMin());
|
||||||
if (SMin == APInt::getSignedMinValue(W))
|
if (SMin == APInt::getSignedMinValue(W))
|
||||||
return ConstantRange(W);
|
return ConstantRange(W);
|
||||||
return ConstantRange(SMin, APInt::getSignedMaxValue(W) + 1);
|
return ConstantRange(SMin, APInt::getSignedMinValue(W));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -969,16 +968,16 @@ namespace {
|
|||||||
ConstantRange NewCR2(CR1.getUpper(), CR1.getLower());
|
ConstantRange NewCR2(CR1.getUpper(), CR1.getLower());
|
||||||
applyRange(V2, NewCR2, Subtree, VRP);
|
applyRange(V2, NewCR2, Subtree, VRP);
|
||||||
} else if (*I == CR2.getLower()) {
|
} else if (*I == CR2.getLower()) {
|
||||||
APInt NewLower = CR2.getLower() + 1,
|
APInt NewLower(CR2.getLower() + 1),
|
||||||
NewUpper = CR2.getUpper();
|
NewUpper(CR2.getUpper());
|
||||||
if (NewLower == NewUpper)
|
if (NewLower == NewUpper)
|
||||||
NewLower = NewUpper = APInt::getMinValue(W);
|
NewLower = NewUpper = APInt::getMinValue(W);
|
||||||
|
|
||||||
ConstantRange NewCR2(NewLower, NewUpper);
|
ConstantRange NewCR2(NewLower, NewUpper);
|
||||||
applyRange(V2, NewCR2, Subtree, VRP);
|
applyRange(V2, NewCR2, Subtree, VRP);
|
||||||
} else if (*I == CR2.getUpper() - 1) {
|
} else if (*I == CR2.getUpper() - 1) {
|
||||||
APInt NewLower = CR2.getLower(),
|
APInt NewLower(CR2.getLower()),
|
||||||
NewUpper = CR2.getUpper() - 1;
|
NewUpper(CR2.getUpper() - 1);
|
||||||
if (NewLower == NewUpper)
|
if (NewLower == NewUpper)
|
||||||
NewLower = NewUpper = APInt::getMinValue(W);
|
NewLower = NewUpper = APInt::getMinValue(W);
|
||||||
|
|
||||||
@@ -992,16 +991,16 @@ namespace {
|
|||||||
ConstantRange NewCR1(CR2.getUpper(), CR2.getLower());
|
ConstantRange NewCR1(CR2.getUpper(), CR2.getLower());
|
||||||
applyRange(V1, NewCR1, Subtree, VRP);
|
applyRange(V1, NewCR1, Subtree, VRP);
|
||||||
} else if (*I == CR1.getLower()) {
|
} else if (*I == CR1.getLower()) {
|
||||||
APInt NewLower = CR1.getLower() + 1,
|
APInt NewLower(CR1.getLower() + 1),
|
||||||
NewUpper = CR1.getUpper();
|
NewUpper(CR1.getUpper());
|
||||||
if (NewLower == NewUpper)
|
if (NewLower == NewUpper)
|
||||||
NewLower = NewUpper = APInt::getMinValue(W);
|
NewLower = NewUpper = APInt::getMinValue(W);
|
||||||
|
|
||||||
ConstantRange NewCR1(NewLower, NewUpper);
|
ConstantRange NewCR1(NewLower, NewUpper);
|
||||||
applyRange(V1, NewCR1, Subtree, VRP);
|
applyRange(V1, NewCR1, Subtree, VRP);
|
||||||
} else if (*I == CR1.getUpper() - 1) {
|
} else if (*I == CR1.getUpper() - 1) {
|
||||||
APInt NewLower = CR1.getLower(),
|
APInt NewLower(CR1.getLower()),
|
||||||
NewUpper = CR1.getUpper() - 1;
|
NewUpper(CR1.getUpper() - 1);
|
||||||
if (NewLower == NewUpper)
|
if (NewLower == NewUpper)
|
||||||
NewLower = NewUpper = APInt::getMinValue(W);
|
NewLower = NewUpper = APInt::getMinValue(W);
|
||||||
|
|
||||||
@@ -2242,10 +2241,8 @@ namespace {
|
|||||||
VRPSolver VRP(IG, UB, VR, PS->Forest, PS->modified, &SI);
|
VRPSolver VRP(IG, UB, VR, PS->Forest, PS->modified, &SI);
|
||||||
uint32_t SrcBitWidth = cast<IntegerType>(SI.getSrcTy())->getBitWidth();
|
uint32_t SrcBitWidth = cast<IntegerType>(SI.getSrcTy())->getBitWidth();
|
||||||
uint32_t DstBitWidth = cast<IntegerType>(SI.getDestTy())->getBitWidth();
|
uint32_t DstBitWidth = cast<IntegerType>(SI.getDestTy())->getBitWidth();
|
||||||
APInt Min(APInt::getSignedMinValue(SrcBitWidth));
|
APInt Min(APInt::getHighBitsSet(DstBitWidth, DstBitWidth-SrcBitWidth+1));
|
||||||
APInt Max(APInt::getSignedMaxValue(SrcBitWidth));
|
APInt Max(APInt::getLowBitsSet(DstBitWidth, SrcBitWidth-1));
|
||||||
Min.sext(DstBitWidth);
|
|
||||||
Max.sext(DstBitWidth);
|
|
||||||
VRP.add(ConstantInt::get(Min), &SI, ICmpInst::ICMP_SLE);
|
VRP.add(ConstantInt::get(Min), &SI, ICmpInst::ICMP_SLE);
|
||||||
VRP.add(ConstantInt::get(Max), &SI, ICmpInst::ICMP_SGE);
|
VRP.add(ConstantInt::get(Max), &SI, ICmpInst::ICMP_SGE);
|
||||||
VRP.solve();
|
VRP.solve();
|
||||||
@@ -2255,8 +2252,7 @@ namespace {
|
|||||||
VRPSolver VRP(IG, UB, VR, PS->Forest, PS->modified, &ZI);
|
VRPSolver VRP(IG, UB, VR, PS->Forest, PS->modified, &ZI);
|
||||||
uint32_t SrcBitWidth = cast<IntegerType>(ZI.getSrcTy())->getBitWidth();
|
uint32_t SrcBitWidth = cast<IntegerType>(ZI.getSrcTy())->getBitWidth();
|
||||||
uint32_t DstBitWidth = cast<IntegerType>(ZI.getDestTy())->getBitWidth();
|
uint32_t DstBitWidth = cast<IntegerType>(ZI.getDestTy())->getBitWidth();
|
||||||
APInt Max(APInt::getMaxValue(SrcBitWidth));
|
APInt Max(APInt::getLowBitsSet(DstBitWidth, SrcBitWidth));
|
||||||
Max.zext(DstBitWidth);
|
|
||||||
VRP.add(ConstantInt::get(Max), &ZI, ICmpInst::ICMP_UGE);
|
VRP.add(ConstantInt::get(Max), &ZI, ICmpInst::ICMP_UGE);
|
||||||
VRP.solve();
|
VRP.solve();
|
||||||
}
|
}
|
||||||
@@ -2353,14 +2349,12 @@ namespace {
|
|||||||
case ICmpInst::ICMP_SLT:
|
case ICmpInst::ICMP_SLT:
|
||||||
case ICmpInst::ICMP_ULT:
|
case ICmpInst::ICMP_ULT:
|
||||||
if (Op1->getValue() != 0)
|
if (Op1->getValue() != 0)
|
||||||
NextVal = cast<ConstantInt>(ConstantExpr::getSub(
|
NextVal = ConstantInt::get(Op1->getValue()-1);
|
||||||
Op1, ConstantInt::get(Op1->getType(), 1)));
|
|
||||||
break;
|
break;
|
||||||
case ICmpInst::ICMP_SGT:
|
case ICmpInst::ICMP_SGT:
|
||||||
case ICmpInst::ICMP_UGT:
|
case ICmpInst::ICMP_UGT:
|
||||||
if (!Op1->getValue().isAllOnesValue())
|
if (!Op1->getValue().isAllOnesValue())
|
||||||
NextVal = cast<ConstantInt>(ConstantExpr::getAdd(
|
NextVal = ConstantInt::get(Op1->getValue()+1);
|
||||||
Op1, ConstantInt::get(Op1->getType(), 1)));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user