APIntify this pass.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34863 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Reid Spencer
2007-03-03 00:48:31 +00:00
parent 239e4021ce
commit af3e9468dc

View File

@@ -377,7 +377,7 @@ namespace {
RHS.first->getType()->getBitWidth()) RHS.first->getType()->getBitWidth())
return LHS.first->getType()->getBitWidth() < return LHS.first->getType()->getBitWidth() <
RHS.first->getType()->getBitWidth(); RHS.first->getType()->getBitWidth();
return LHS.first->getZExtValue() < RHS.first->getZExtValue(); return LHS.first->getValue().ult(RHS.first->getValue());
} }
}; };
@@ -407,40 +407,43 @@ namespace {
iULT = (iUGT == begin || begin == end) ? end : iUGT - 1; iULT = (iUGT == begin || begin == end) ? end : iUGT - 1;
if (iUGT != end && iULT != end && if (iUGT != end && iULT != end &&
(iULT->first->getSExtValue() >> 63) == iULT->first->getValue().isNegative() ==
(iUGT->first->getSExtValue() >> 63)) { // signs match iUGT->first->getValue().isNegative()) { // signs match
iSGT = iUGT; iSGT = iUGT;
iSLT = iULT; iSLT = iULT;
} else { } else {
if (iULT == end || iUGT == end) { if (iULT == end || iUGT == end) {
if (iULT == end) iSLT = last; else iSLT = iULT; if (iULT == end) iSLT = last; else iSLT = iULT;
if (iUGT == end) iSGT = begin; else iSGT = iUGT; if (iUGT == end) iSGT = begin; else iSGT = iUGT;
} else if (iULT->first->getSExtValue() < 0) { } else if (iULT->first->getValue().isNegative()) {
assert(iUGT->first->getSExtValue() >= 0 && "Bad sign comparison."); assert(iUGT->first->getValue().isPositive() &&
"Bad sign comparison.");
iSGT = iUGT; iSGT = iUGT;
iSLT = iULT; iSLT = iULT;
} else { } else {
assert(iULT->first->getSExtValue() >= 0 && assert(iULT->first->getValue().isPositive() >= 0 &&
iUGT->first->getSExtValue() < 0 && "Bad sign comparison."); iUGT->first->getValue().isNegative() &&"Bad sign comparison.");
iSGT = iULT; iSGT = iULT;
iSLT = iUGT; iSLT = iUGT;
} }
if (iSGT != end && if (iSGT != end &&
iSGT->first->getSExtValue() < CI->getSExtValue()) iSGT = end; iSGT->first->getValue().slt(CI->getValue()))
iSGT = end;
if (iSLT != end && if (iSLT != end &&
iSLT->first->getSExtValue() > CI->getSExtValue()) iSLT = end; iSLT->first->getValue().sgt(CI->getValue()))
iSLT = end;
if (begin != end) { if (begin != end) {
if (begin->first->getSExtValue() < CI->getSExtValue()) if (begin->first->getValue().slt(CI->getValue()))
if (iSLT == end || if (iSLT == end ||
begin->first->getSExtValue() > iSLT->first->getSExtValue()) begin->first->getValue().sgt(iSLT->first->getValue()))
iSLT = begin; iSLT = begin;
} }
if (last != end) { if (last != end) {
if (last->first->getSExtValue() > CI->getSExtValue()) if (last->first->getValue().sgt(CI->getValue()))
if (iSGT == end || if (iSGT == end ||
last->first->getSExtValue() < iSGT->first->getSExtValue()) last->first->getValue().slt(iSGT->first->getValue()))
iSGT = last; iSGT = last;
} }
} }
@@ -1201,8 +1204,7 @@ namespace {
if (ConstantInt *CI = dyn_cast<ConstantInt>(Canonical)) { if (ConstantInt *CI = dyn_cast<ConstantInt>(Canonical)) {
if (ConstantInt *Arg = dyn_cast<ConstantInt>(LHS)) { if (ConstantInt *Arg = dyn_cast<ConstantInt>(LHS)) {
add(RHS, ConstantInt::get(CI->getType(), CI->getZExtValue() ^ add(RHS, ConstantInt::get(CI->getValue() ^ Arg->getValue()),
Arg->getZExtValue()),
ICmpInst::ICMP_EQ, NewContext); ICmpInst::ICMP_EQ, NewContext);
} }
} }
@@ -1454,21 +1456,22 @@ namespace {
if (ConstantInt *CI = dyn_cast<ConstantInt>(O.RHS)) { if (ConstantInt *CI = dyn_cast<ConstantInt>(O.RHS)) {
// xform doesn't apply to i1 // xform doesn't apply to i1
if (CI->getType()->getBitWidth() > 1) { if (CI->getType()->getBitWidth() > 1) {
if (LV == SLT && CI->getSExtValue() < 0) { if (LV == SLT && CI->getValue().isNegative()) {
// i8 %x s< -5 implies %x < -5 and %x u> 127 // i8 %x s< -5 implies %x < -5 and %x u> 127
const IntegerType *Ty = CI->getType(); const IntegerType *Ty = CI->getType();
LV = LT; LV = LT;
add(O.LHS, ConstantInt::get(Ty, Ty->getBitMask() >> 1), add(O.LHS, ConstantInt::get(Ty->getMask().lshr(1)),
ICmpInst::ICMP_UGT); ICmpInst::ICMP_UGT);
} else if (LV == SGT && CI->getSExtValue() >= 0) { } else if (LV == SGT && CI->getValue().isPositive()) {
// i8 %x s> 5 implies %x > 5 and %x u< 128 // i8 %x s> 5 implies %x > 5 and %x u< 128
const IntegerType *Ty = CI->getType(); const IntegerType *Ty = CI->getType();
LV = LT; LV = LT;
add(O.LHS, ConstantInt::get(Ty, 1 << Ty->getBitWidth()), add(O.LHS, ConstantInt::get(
APInt::getSignedMinValue(Ty->getBitWidth())),
ICmpInst::ICMP_ULT); ICmpInst::ICMP_ULT);
} else if (CI->getSExtValue() >= 0) { } else if (CI->getValue().isPositive()) {
if (LV == ULT || LV == SLT) LV = LT; if (LV == ULT || LV == SLT) LV = LT;
if (LV == UGT || LV == SGT) LV = GT; if (LV == UGT || LV == SGT) LV = GT;
} }
@@ -1772,19 +1775,24 @@ namespace {
void PredicateSimplifier::Forwards::visitSExtInst(SExtInst &SI) { void PredicateSimplifier::Forwards::visitSExtInst(SExtInst &SI) {
VRPSolver VRP(IG, UB, PS->Forest, PS->modified, &SI); VRPSolver VRP(IG, UB, PS->Forest, PS->modified, &SI);
const IntegerType *Ty = cast<IntegerType>(SI.getSrcTy()); uint32_t SrcBitWidth = cast<IntegerType>(SI.getSrcTy())->getBitWidth();
VRP.add(ConstantInt::get(SI.getDestTy(), ~(Ty->getBitMask() >> 1)), uint32_t DstBitWidth = cast<IntegerType>(SI.getDestTy())->getBitWidth();
&SI, ICmpInst::ICMP_SLE); APInt Min(APInt::getSignedMinValue(SrcBitWidth));
VRP.add(ConstantInt::get(SI.getDestTy(), (1 << (Ty->getBitWidth()-1)) - 1), APInt Max(APInt::getSignedMaxValue(SrcBitWidth));
&SI, ICmpInst::ICMP_SGE); Min.sext(DstBitWidth);
Max.sext(DstBitWidth);
VRP.add(ConstantInt::get(Min), &SI, ICmpInst::ICMP_SLE);
VRP.add(ConstantInt::get(Max), &SI, ICmpInst::ICMP_SGE);
VRP.solve(); VRP.solve();
} }
void PredicateSimplifier::Forwards::visitZExtInst(ZExtInst &ZI) { void PredicateSimplifier::Forwards::visitZExtInst(ZExtInst &ZI) {
VRPSolver VRP(IG, UB, PS->Forest, PS->modified, &ZI); VRPSolver VRP(IG, UB, PS->Forest, PS->modified, &ZI);
const IntegerType *Ty = cast<IntegerType>(ZI.getSrcTy()); uint32_t SrcBitWidth = cast<IntegerType>(ZI.getSrcTy())->getBitWidth();
VRP.add(ConstantInt::get(ZI.getDestTy(), Ty->getBitMask()), uint32_t DstBitWidth = cast<IntegerType>(ZI.getDestTy())->getBitWidth();
&ZI, ICmpInst::ICMP_UGE); APInt Max(APInt::getMaxValue(SrcBitWidth));
Max.zext(DstBitWidth);
VRP.add(ConstantInt::get(Max), &ZI, ICmpInst::ICMP_UGE);
VRP.solve(); VRP.solve();
} }