Ops.push_back(Add->getOperand(i));
const SCEV *Accum = getAddExpr(Ops);
- bool InvariantF = isLoopInvariant(Accum, L);
-
- if (!InvariantF && Accum->getSCEVType() == scZeroExtend) {
- const SCEV *Op = dyn_cast<SCEVZeroExtendExpr>(Accum)->getOperand();
- const SCEVUnknown *Un = dyn_cast<SCEVUnknown>(Op);
- if (Un && Un->getValue() && isa<Instruction>(Un->getValue()) &&
- dyn_cast<Instruction>(Un->getValue())->getOpcode() ==
- Instruction::ICmp) {
- const SCEV *ICmpSC = evaluateForICmp(cast<ICmpInst>(Un->getValue()));
- bool IsConstSC = ICmpSC->getSCEVType() == scConstant;
- Accum =
- IsConstSC ? getZeroExtendExpr(ICmpSC, Accum->getType()) : Accum;
- InvariantF = IsConstSC ? true : false;
- }
- }
-
// This is not a valid addrec if the step amount is varying each
// loop iteration, but is not itself an addrec in this loop.
- if (InvariantF || (isa<SCEVAddRecExpr>(Accum) &&
- cast<SCEVAddRecExpr>(Accum)->getLoop() == L)) {
+ if (isLoopInvariant(Accum, L) ||
+ (isa<SCEVAddRecExpr>(Accum) &&
+ cast<SCEVAddRecExpr>(Accum)->getLoop() == L)) {
SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap;
if (auto BO = MatchBinaryOp(BEValueV, DT)) {
}
}
-
-const SCEV *ScalarEvolution::evaluateForICmp(ICmpInst *IC) {
- BasicBlock *Latch = nullptr;
- const Loop *L = LI.getLoopFor(IC->getParent());
-
- // If compare instruction is same or inverse of the compare in the
- // branch of the loop latch, then return a constant evolution
- // node. This shall facilitate computations of loop exit counts
- // in cases where compare appears in the evolution chain of induction
- // variables.
- if (L && (Latch = L->getLoopLatch())) {
- BranchInst *BI = dyn_cast<BranchInst>(Latch->getTerminator());
- if (BI && BI->isConditional() && BI->getCondition() == IC) {
- if (BI->getSuccessor(0) != L->getHeader())
- return getZero(Type::getInt1Ty(getContext()));
- else
- return getOne(Type::getInt1Ty(getContext()));
- }
- }
-
- return getUnknown(IC);
-}
-
-
void ScalarEvolution::forgetValue(Value *V) {
Instruction *I = dyn_cast<Instruction>(V);
if (!I) return;
// Ignore users that are part of a SCEV expression. This way we only
// consider leaf IV Users. This effectively rediscovers a portion of
// IVUsers analysis but in program order this time.
- if (SE.isSCEVable(I.getType())) {
- const SCEV *SI = SE.getSCEV(&I);
- if (!isa<SCEVUnknown>(SI) && !isa<SCEVConstant>(SI))
- continue;
- }
+ if (SE.isSCEVable(I.getType()) && !isa<SCEVUnknown>(SE.getSCEV(&I)))
+ continue;
// Remove this instruction from any NearUsers set it may be in.
for (unsigned ChainIdx = 0, NChains = IVChainVec.size();
+++ /dev/null
-; RUN: opt -S -scalar-evolution -loop-deletion -simplifycfg -analyze < %s | FileCheck %s --check-prefix=CHECK-ANALYSIS
-
-define i32 @foo() local_unnamed_addr #0 {
-; CHECK-ANALYSIS: Loop %do.body: backedge-taken count is 10000
-; CHECK-ANALYSIS: Loop %do.body: max backedge-taken count is 10000
-; CHECK-ANALYSIS: Loop %do.body: Predicated backedge-taken count is 10000
-entry:
- br label %do.body
-
-do.body: ; preds = %do.body, %entry
- %start.0 = phi i32 [ 0, %entry ], [ %inc.start.0, %do.body ]
- %cmp = icmp slt i32 %start.0, 10000
- %inc = zext i1 %cmp to i32
- %inc.start.0 = add nsw i32 %start.0, %inc
- br i1 %cmp, label %do.body, label %do.end
-
-do.end: ; preds = %do.body
- ret i32 0
-}