From 2199dbc5ff22bb2b6fbccbdafd48767efa3ee901 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 19 Jun 2009 17:33:15 +0000 Subject: [PATCH] Don't (unconditionally) use getSCEVAtScope to simplify the step expression in IVUsers, because in the case of a use of a non-linear addrec outside of a loop, this causes the addrec to be evaluated as a linear addrec. llvm-svn: 73774 --- llvm/lib/Analysis/IVUsers.cpp | 1 - .../LoopStrengthReduce/quadradic-exit-value.ll | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 llvm/test/Transforms/LoopStrengthReduce/quadradic-exit-value.ll diff --git a/llvm/lib/Analysis/IVUsers.cpp b/llvm/lib/Analysis/IVUsers.cpp index 0bacc3944365..6a53a83665c2 100644 --- a/llvm/lib/Analysis/IVUsers.cpp +++ b/llvm/lib/Analysis/IVUsers.cpp @@ -112,7 +112,6 @@ static bool getSCEVStartAndStride(const SCEVHandle &SH, Loop *L, Loop *UseLoop, SCEVHandle AddRecStart = AddRec->getStart(); AddRecStart = SE->getSCEVAtScope(AddRecStart, UseLoop); SCEVHandle AddRecStride = AddRec->getStepRecurrence(*SE); - AddRecStride = SE->getSCEVAtScope(AddRecStride, UseLoop); // FIXME: If Start contains an SCEVAddRecExpr from a different loop, other // than an outer loop of the current loop, reject it. LSR has no concept of diff --git a/llvm/test/Transforms/LoopStrengthReduce/quadradic-exit-value.ll b/llvm/test/Transforms/LoopStrengthReduce/quadradic-exit-value.ll new file mode 100644 index 000000000000..d15c2dc31351 --- /dev/null +++ b/llvm/test/Transforms/LoopStrengthReduce/quadradic-exit-value.ll @@ -0,0 +1,18 @@ +; RUN: llvm-as < %s | opt -analyze -iv-users -disable-output | grep {Stride i64 {1,+,2}:} + +; The value of %r is dependent on a polynomial iteration expression. + +define i64 @foo(i64 %n) { +entry: + br label %loop + +loop: + %indvar = phi i64 [ 0, %entry ], [ %indvar.next, %loop ] + %indvar.next = add i64 %indvar, 1 + %c = icmp eq i64 %indvar.next, %n + br i1 %c, label %exit, label %loop + +exit: + %r = mul i64 %indvar, %indvar + ret i64 %r +}