Value *IndVar,
BasicBlock *ExitingBlock,
BranchInst *BI,
- SCEVExpander &Rewriter,
- bool SignExtendTripCount);
+ SCEVExpander &Rewriter);
void RewriteLoopExitValues(Loop *L, SCEV *IterationCount);
void DeleteTriviallyDeadInstructions(SmallPtrSet<Instruction*, 16> &Insts);
Value *IndVar,
BasicBlock *ExitingBlock,
BranchInst *BI,
- SCEVExpander &Rewriter,
- bool SignExtendTripCount) {
+ SCEVExpander &Rewriter) {
// If the exiting block is not the same as the backedge block, we must compare
// against the preincremented value, otherwise we prefer to compare against
// the post-incremented value.
if ((isa<SCEVConstant>(N) && !N->isZero()) ||
SE->isLoopGuardedByCond(L, ICmpInst::ICMP_NE, N, Zero)) {
// No overflow. Cast the sum.
- if (SignExtendTripCount)
- IterationCount = SE->getTruncateOrSignExtend(N, IndVar->getType());
- else
- IterationCount = SE->getTruncateOrZeroExtend(N, IndVar->getType());
+ IterationCount = SE->getTruncateOrZeroExtend(N, IndVar->getType());
} else {
// Potential overflow. Cast before doing the add.
- if (SignExtendTripCount)
- IterationCount = SE->getTruncateOrSignExtend(IterationCount,
- IndVar->getType());
- else
- IterationCount = SE->getTruncateOrZeroExtend(IterationCount,
- IndVar->getType());
+ IterationCount = SE->getTruncateOrZeroExtend(IterationCount,
+ IndVar->getType());
IterationCount =
SE->getAddExpr(IterationCount,
SE->getIntegerSCEV(1, IndVar->getType()));
CmpIndVar = L->getCanonicalInductionVariableIncrement();
} else {
// We have to use the preincremented value...
- if (SignExtendTripCount)
- IterationCount = SE->getTruncateOrSignExtend(IterationCount,
- IndVar->getType());
- else
- IterationCount = SE->getTruncateOrZeroExtend(IterationCount,
- IndVar->getType());
+ IterationCount = SE->getTruncateOrZeroExtend(IterationCount,
+ IndVar->getType());
CmpIndVar = IndVar;
}
/// whether an induction variable in the same type that starts
/// at 0 would undergo signed overflow.
///
-/// In addition to setting the NoSignedWrap, NoUnsignedWrap, and
-/// SignExtendTripCount variables, return the PHI for this induction
-/// variable.
+/// In addition to setting the NoSignedWrap, and NoUnsignedWrap,
+/// variables, return the PHI for this induction variable.
///
/// TODO: This duplicates a fair amount of ScalarEvolution logic.
/// Perhaps this can be merged with ScalarEvolution::getIterationCount
const BranchInst *BI,
const Instruction *OrigCond,
bool &NoSignedWrap,
- bool &NoUnsignedWrap,
- bool &SignExtendTripCount) {
+ bool &NoUnsignedWrap) {
// Verify that the loop is sane and find the exit condition.
const ICmpInst *Cmp = dyn_cast<ICmpInst>(OrigCond);
if (!Cmp) return 0;
// less than some value in the same type. As such, it will never wrap.
if (isSigned && !InitialVal->getValue().isMaxSignedValue()) {
NoSignedWrap = true;
- // If the original induction variable starts at zero or greater,
- // the trip count can be considered signed.
- if (InitialVal->getValue().isNonNegative())
- SignExtendTripCount = true;
} else if (!isSigned && !InitialVal->getValue().isMaxValue())
NoUnsignedWrap = true;
return PN;
// using it. We can currently only handle loops with a single exit.
bool NoSignedWrap = false;
bool NoUnsignedWrap = false;
- bool SignExtendTripCount = false;
const PHINode *OrigControllingPHI = 0;
if (!isa<SCEVCouldNotCompute>(IterationCount) && ExitingBlock)
// Can't rewrite non-branch yet.
// Determine if the OrigIV will ever undergo overflow.
OrigControllingPHI =
TestOrigIVForWrap(L, BI, OrigCond,
- NoSignedWrap, NoUnsignedWrap,
- SignExtendTripCount);
+ NoSignedWrap, NoUnsignedWrap);
// We'll be replacing the original condition, so it'll be dead.
DeadInsts.insert(OrigCond);
}
LinearFunctionTestReplace(L, IterationCount, IndVar,
- ExitingBlock, BI, Rewriter,
- SignExtendTripCount);
+ ExitingBlock, BI, Rewriter);
}
// Now that we have a canonical induction variable, we can rewrite any