diff options
| author | Keno Fischer <kfischer@college.harvard.edu> | 2016-07-13 01:28:12 +0000 |
|---|---|---|
| committer | Keno Fischer <kfischer@college.harvard.edu> | 2016-07-13 01:28:12 +0000 |
| commit | 1efc3b70c55910de72277f55959574c55329b0fa (patch) | |
| tree | ddb5c035242deca835ca484bf00a6f36254ec888 /llvm/lib | |
| parent | 835df56cb3d222a76fa65eb34bd27d8e2e98e45f (diff) | |
| download | bcm5719-llvm-1efc3b70c55910de72277f55959574c55329b0fa.tar.gz bcm5719-llvm-1efc3b70c55910de72277f55959574c55329b0fa.zip | |
Fix ScalarEvolutionExpander step scaling bug
The expandAddRecExprLiterally function incorrectly transforms
`[Start + Step * X]` into `Step * [Start + X]` instead of the correct
transform of `[Step * X] + Start`.
This caused https://github.com/JuliaLang/julia/issues/14704#issuecomment-174126219
due to what appeared to be sufficiently complicated loop interactions.
Patch by Jameson Nash (jameson@juliacomputing.com).
Reviewers: sanjoy
Differential Revision: http://reviews.llvm.org/D16505
llvm-svn: 275239
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Analysis/ScalarEvolutionExpander.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp index 77164356d8e..77e4ec7ab40 100644 --- a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp @@ -1288,6 +1288,13 @@ Value *SCEVExpander::expandAddRecExprLiterally(const SCEVAddRecExpr *S) { if (!SE.dominates(Step, L->getHeader())) { PostLoopScale = Step; Step = SE.getConstant(Normalized->getType(), 1); + if (!Start->isZero()) { + // The normalization below assumes that Start is constant zero, so if + // it isn't re-associate Start to PostLoopOffset. + assert(!PostLoopOffset && "Start not-null but PostLoopOffset set?"); + PostLoopOffset = Start; + Start = SE.getConstant(Normalized->getType(), 0); + } Normalized = cast<SCEVAddRecExpr>(SE.getAddRecExpr( Start, Step, Normalized->getLoop(), |

