From 2a52583d670046f05053fcd7da978e060205b372 Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Fri, 23 Aug 2019 04:03:23 +0000 Subject: [IndVars] Fix a bug noticed by inspection We were computing the loop exit value, but not ensuring the addrec belonged to the loop whose exit value we were computing. I couldn't actually trip this; the test case shows the basic setup which *might* trip this, but none of the variations I've tried actually do. llvm-svn: 369730 --- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp index bb524f7ad69..aa35fa11f67 100644 --- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -644,7 +644,8 @@ bool IndVarSimplify::rewriteLoopExitValues(Loop *L, SCEVExpander &Rewriter) { if (isa(ExitCount)) continue; if (auto *AddRec = dyn_cast(SE->getSCEV(Inst))) - ExitValue = AddRec->evaluateAtIteration(ExitCount, *SE); + if (AddRec->getLoop() == L) + ExitValue = AddRec->evaluateAtIteration(ExitCount, *SE); if (isa(ExitValue) || !SE->isLoopInvariant(ExitValue, L) || !isSafeToExpand(ExitValue, *SE)) -- cgit v1.2.3