[LSR] Use evaluateAtIteration in lsr-term-fold
authorPhilip Reames <preames@rivosinc.com>
Tue, 21 Mar 2023 15:02:32 +0000 (08:02 -0700)
committerPhilip Reames <listmail@philipreames.com>
Tue, 21 Mar 2023 15:11:36 +0000 (08:11 -0700)
commitb33f5e7ed3cd04797b721e32b982b2cf6e06e192
tree868773432512bbfc606a63108919db84e7f74dca
parentb7af34c303ca3dc53ee5945b0c692b3b10ebae94
[LSR] Use evaluateAtIteration in lsr-term-fold

This is a follow up to one of the side discussions on D146429.  There are two semantic changes contained here.

The motivation for the change to the legality condition introduced in D146429 comes from the fact that we only check the post-inc form. As such, as long as the values of the post-inc variable don't self wrap, it's actually okay if we wrap past the starting value of the pre-inc IV.

Second, Nikic noticed during review that the test changes changed behavior for TC=0 (i.e. N=0 in the tests).  On more careful inspection, it became apparent that the previous manual expansion code was incorrect in the case where the primary IV could wrap without poison, and started with the limit value (i.e. i8 post-inc starts at 255 for 0 exit test, implying pre-inc starts with 0).  See @wrap_around test for an example of the (previous) miscompile.

Differential Revision: https://reviews.llvm.org/D146457
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
llvm/test/Transforms/LoopStrengthReduce/lsr-term-fold.ll