Index: llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp =================================================================== --- llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp +++ llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp @@ -845,6 +845,10 @@ // induction variable satisfies some constraint. const SCEVAddRecExpr *IndVarBase = cast(LeftSCEV); + if (IndVarBase->getLoop() != &L) { + FailureReason = "LHS in icmp not induction variable for this loop"; + return None; + } if (!IndVarBase->isAffine()) { FailureReason = "LHS in icmp not induction variable"; return None; Index: llvm/test/Transforms/IRCE/iv-for-another-loop.ll =================================================================== --- llvm/test/Transforms/IRCE/iv-for-another-loop.ll +++ llvm/test/Transforms/IRCE/iv-for-another-loop.ll @@ -4,7 +4,7 @@ target triple = "x86_64-unknown-linux-gnu" ; REQUIRES: asserts -; XFAIL: * +; CHECK-NOT: irce define void @test() { bb: