indvars: minor cleanup in preparation for sign/zero extend elimination.

llvm-svn: 131716
This commit is contained in:
Andrew Trick 2011-05-20 03:37:48 +00:00
parent 5fe15d2d52
commit b75279cbbd
1 changed files with 11 additions and 18 deletions

View File

@ -113,7 +113,7 @@ namespace {
void EliminateIVComparison(ICmpInst *ICmp, Value *IVOperand); void EliminateIVComparison(ICmpInst *ICmp, Value *IVOperand);
void EliminateIVRemainder(BinaryOperator *Rem, void EliminateIVRemainder(BinaryOperator *Rem,
Value *IVOperand, Value *IVOperand,
bool isSigned); bool IsSigned);
void RewriteNonIntegerIVs(Loop *L); void RewriteNonIntegerIVs(Loop *L);
const Type *WidenIVs(Loop *L, SCEVExpander &Rewriter); const Type *WidenIVs(Loop *L, SCEVExpander &Rewriter);
@ -468,9 +468,9 @@ void IndVarSimplify::SimplifyIVUsers() {
} }
if (BinaryOperator *Rem = dyn_cast<BinaryOperator>(UseInst)) { if (BinaryOperator *Rem = dyn_cast<BinaryOperator>(UseInst)) {
bool isSigned = Rem->getOpcode() == Instruction::SRem; bool IsSigned = Rem->getOpcode() == Instruction::SRem;
if (isSigned || Rem->getOpcode() == Instruction::URem) { if (IsSigned || Rem->getOpcode() == Instruction::URem) {
EliminateIVRemainder(Rem, IVOperand, isSigned); EliminateIVRemainder(Rem, IVOperand, IsSigned);
continue; continue;
} }
} }
@ -506,12 +506,13 @@ void IndVarSimplify::EliminateIVComparison(ICmpInst *ICmp, Value *IVOperand) {
return; return;
DEBUG(dbgs() << "INDVARS: Eliminated comparison: " << *ICmp << '\n'); DEBUG(dbgs() << "INDVARS: Eliminated comparison: " << *ICmp << '\n');
Changed = true;
DeadInsts.push_back(ICmp); DeadInsts.push_back(ICmp);
} }
void IndVarSimplify::EliminateIVRemainder(BinaryOperator *Rem, void IndVarSimplify::EliminateIVRemainder(BinaryOperator *Rem,
Value *IVOperand, Value *IVOperand,
bool isSigned) { bool IsSigned) {
// We're only interested in the case where we know something about // We're only interested in the case where we know something about
// the numerator. // the numerator.
if (IVOperand != Rem->getOperand(0)) if (IVOperand != Rem->getOperand(0))
@ -527,18 +528,18 @@ void IndVarSimplify::EliminateIVRemainder(BinaryOperator *Rem,
X = SE->getSCEVAtScope(X, ICmpLoop); X = SE->getSCEVAtScope(X, ICmpLoop);
// i % n --> i if i is in [0,n). // i % n --> i if i is in [0,n).
if ((!isSigned || SE->isKnownNonNegative(S)) && if ((!IsSigned || SE->isKnownNonNegative(S)) &&
SE->isKnownPredicate(isSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT, SE->isKnownPredicate(IsSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
S, X)) S, X))
Rem->replaceAllUsesWith(Rem->getOperand(0)); Rem->replaceAllUsesWith(Rem->getOperand(0));
else { else {
// (i+1) % n --> (i+1)==n?0:(i+1) if i is in [0,n). // (i+1) % n --> (i+1)==n?0:(i+1) if i is in [0,n).
const SCEV *LessOne = const SCEV *LessOne =
SE->getMinusSCEV(S, SE->getConstant(S->getType(), 1)); SE->getMinusSCEV(S, SE->getConstant(S->getType(), 1));
if (isSigned && !SE->isKnownNonNegative(LessOne)) if (IsSigned && !SE->isKnownNonNegative(LessOne))
return; return;
if (!SE->isKnownPredicate(isSigned ? if (!SE->isKnownPredicate(IsSigned ?
ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT, ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
LessOne, X)) LessOne, X))
return; return;
@ -558,6 +559,7 @@ void IndVarSimplify::EliminateIVRemainder(BinaryOperator *Rem,
IU->AddUsersIfInteresting(I); IU->AddUsersIfInteresting(I);
DEBUG(dbgs() << "INDVARS: Simplified rem: " << *Rem << '\n'); DEBUG(dbgs() << "INDVARS: Simplified rem: " << *Rem << '\n');
Changed = true;
DeadInsts.push_back(Rem); DeadInsts.push_back(Rem);
} }
@ -624,15 +626,6 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) {
SE->getTypeSizeInBits(LargestType)) SE->getTypeSizeInBits(LargestType))
LargestType = SE->getEffectiveSCEVType(Ty); LargestType = SE->getEffectiveSCEVType(Ty);
} }
for (IVUsers::const_iterator I = IU->begin(), E = IU->end(); I != E; ++I) {
NeedCannIV = true;
const Type *Ty =
SE->getEffectiveSCEVType(I->getOperandValToReplace()->getType());
if (!LargestType ||
SE->getTypeSizeInBits(Ty) >
SE->getTypeSizeInBits(LargestType))
LargestType = SE->getEffectiveSCEVType(Ty);
}
if (!DisableIVRewrite) { if (!DisableIVRewrite) {
for (IVUsers::const_iterator I = IU->begin(), E = IU->end(); I != E; ++I) { for (IVUsers::const_iterator I = IU->begin(), E = IU->end(); I != E; ++I) {
NeedCannIV = true; NeedCannIV = true;