Index: llvm/lib/Analysis/ScalarEvolution.cpp =================================================================== --- llvm/lib/Analysis/ScalarEvolution.cpp +++ llvm/lib/Analysis/ScalarEvolution.cpp @@ -14039,7 +14039,7 @@ SmallPtrSet ReachableBlocks; SE2.getReachableBlocks(ReachableBlocks, F); - auto GetDelta = [&](const SCEV *Old, const SCEV *New) -> const SCEV * { + auto GetNonZeroDelta = [&](const SCEV *Old, const SCEV *New) -> const SCEV * { if (containsUndefs(Old) || containsUndefs(New)) { // SCEV treats "undef" as an unknown but consistent value (i.e. it does // not propagate undef aggressively). This means we can (and do) fail @@ -14049,12 +14049,13 @@ return nullptr; } - // Unless VerifySCEVStrict is set, we only compare constant deltas. const SCEV *Delta = SE2.getMinusSCEV(Old, New); - if (!VerifySCEVStrict && !isa(Delta)) - return nullptr; - - return Delta; + // By default, only report cases where we can prove the expressions are not + // the same. In VerifySCEVStrict mode, report cases where we cannot prove + // that the expressions are the same. + if (VerifySCEVStrict ? !Delta->isZero() : SE2.isKnownNonZero(Delta)) + return Delta; + return nullptr; }; while (!LoopStack.empty()) { @@ -14093,8 +14094,8 @@ SE.getTypeSizeInBits(NewBECount->getType())) CurBECount = SE2.getZeroExtendExpr(CurBECount, NewBECount->getType()); - const SCEV *Delta = GetDelta(CurBECount, NewBECount); - if (Delta && !Delta->isZero()) { + const SCEV *Delta = GetNonZeroDelta(CurBECount, NewBECount); + if (Delta) { dbgs() << "Trip Count for " << *L << " Changed!\n"; dbgs() << "Old: " << *CurBECount << "\n"; dbgs() << "New: " << *NewBECount << "\n"; @@ -14133,8 +14134,8 @@ continue; const SCEV *OldSCEV = SCM.visit(KV.second); const SCEV *NewSCEV = SE2.getSCEV(I); - const SCEV *Delta = GetDelta(OldSCEV, NewSCEV); - if (Delta && !Delta->isZero()) { + const SCEV *Delta = GetNonZeroDelta(OldSCEV, NewSCEV); + if (Delta) { dbgs() << "SCEV for value " << *I << " changed!\n" << "Old: " << *OldSCEV << "\n" << "New: " << *NewSCEV << "\n"