Index: lib/Analysis/ScalarEvolution.cpp =================================================================== --- lib/Analysis/ScalarEvolution.cpp +++ lib/Analysis/ScalarEvolution.cpp @@ -112,6 +112,7 @@ #include "llvm/IR/Use.h" #include "llvm/IR/User.h" #include "llvm/IR/Value.h" +#include "llvm/IR/Verifier.h" #include "llvm/Pass.h" #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" @@ -9375,6 +9376,11 @@ // (interprocedural conditions notwithstanding). if (!L) return true; +#ifdef EXPENSIVE_CHECKS + assert(!verifyFunction(*L->getHeader()->getParent(), &dbgs()) && + "This cannot be done on broken IR!"); +#endif + if (isKnownViaNonRecursiveReasoning(Pred, LHS, RHS)) return true; @@ -9480,6 +9486,11 @@ // (interprocedural conditions notwithstanding). if (!L) return false; +#ifdef EXPENSIVE_CHECKS + assert(!verifyFunction(*L->getHeader()->getParent(), &dbgs()) && + "This cannot be done on broken IR!"); +#endif + // Both LHS and RHS must be available at loop entry. assert(isAvailableAtLoopEntry(LHS, L) && "LHS is not available at Loop Entry"); Index: unittests/Analysis/ScalarEvolutionTest.cpp =================================================================== --- unittests/Analysis/ScalarEvolutionTest.cpp +++ unittests/Analysis/ScalarEvolutionTest.cpp @@ -701,7 +701,7 @@ PN->addIncoming(Dec, IncBB); BranchInst::Create(CondBB, IncBB); - Accum = GetElementPtrInst::Create(I8Ty, Accum, Dec, "gep", EndBB); + Accum = GetElementPtrInst::Create(I8Ty, Accum, PN, "gep", EndBB); PrevBB = CondBB; CondBB = NextBB;