[SCEV] rewriteLoopExitValues(): even if have hard uses, still rewrite if cheap (PR44668)
authorRoman Lebedev <lebedev.ri@gmail.com>
Tue, 25 Feb 2020 18:53:00 +0000 (21:53 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Tue, 25 Feb 2020 20:05:59 +0000 (23:05 +0300)
commit44edc6fd2c63b7db43e13cc8caf1fee79bebdb5f
treeaa5aa03ca00fa8a2f3a113ff1a7f4808d90d603d
parentd6f47aeb5198b142072d8ce2bbf2fdd30d116db0
[SCEV] rewriteLoopExitValues(): even if have hard uses, still rewrite if cheap (PR44668)

Summary:
Replacing uses of IV outside of the loop is likely generally useful,
but `rewriteLoopExitValues()` is cautious, and if it isn't told to always
perform the replacement, and there are hard uses of IV in loop,
it doesn't replace.

In [[ https://bugs.llvm.org/show_bug.cgi?id=44668 | PR44668 ]],
that prevents `-indvars` from replacing uses of induction variable
after the loop, which might be one of the optimization failures
preventing that code from being vectorized.

Instead, now that the cost model is fixed, i believe we should be
a little bit more optimistic, and also perform replacement
if we believe it is within our budget.

Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=44668 | PR44668 ]].

Reviewers: reames, mkazantsev, asbirlea, fhahn, skatkov

Reviewed By: mkazantsev

Subscribers: nikic, hiraditya, zzheng, javed.absar, dmgreen, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D73501
llvm/lib/Transforms/Utils/LoopUtils.cpp
llvm/test/Transforms/IndVarSimplify/do-recompute-if-cheap.ll [moved from llvm/test/Transforms/IndVarSimplify/dont-recompute.ll with 88% similarity]
llvm/test/Transforms/IndVarSimplify/elim-extend.ll
llvm/test/Transforms/IndVarSimplify/lrev-existing-umin.ll
llvm/test/Transforms/IndVarSimplify/pr28705.ll
llvm/test/Transforms/IndVarSimplify/pr39673.ll