Index: llvm/lib/Analysis/ScalarEvolution.cpp =================================================================== --- llvm/lib/Analysis/ScalarEvolution.cpp +++ llvm/lib/Analysis/ScalarEvolution.cpp @@ -12898,6 +12898,30 @@ assert(ValidLoops.contains(AR->getLoop()) && "AddRec references invalid loop"); } + + // Verify intergity of SCEV users. + for (const auto &S : UniqueSCEVs) { + SmallPtrSet Ops; + if (const auto *NS = dyn_cast(&S)) + Ops.insert(NS->op_begin(), NS->op_end()); + else if (const auto *CS = dyn_cast(&S)) + Ops.insert(CS->getOperand()); + else if (const auto *DS = dyn_cast(&S)) { + Ops.insert(DS->getLHS()); + Ops.insert(DS->getRHS()); + } + for (auto *Op : Ops) { + // We do not store dependencies of constants. + if (isa(Op)) + continue; + auto It = SCEVUsers.find(Op); + if (It == SCEVUsers.end() || !It->second.count(&S)) { + dbgs() << "Use of operand " << *Op << " by user " << S + << " is not being tracked!\n"; + std::abort(); + } + } + } } bool ScalarEvolution::invalidate(