[LV] Fix bug when unrolling (only) a loop with non-latch exit
authorPhilip Reames <listmail@philipreames.com>
Tue, 29 Jun 2021 14:54:53 +0000 (07:54 -0700)
committerPhilip Reames <listmail@philipreames.com>
Tue, 29 Jun 2021 15:04:26 +0000 (08:04 -0700)
commite49d65f36d66e247c148601f59edeb2e0b44d8dd
treec1ce30cda5594fb512cb4496f18137a3bf3df9e2
parentc33ebad73516ffcf7b00821a430aa6a0199941f0
[LV] Fix bug when unrolling (only) a loop with non-latch exit

If we unroll a loop in the vectorizer (without vectorizing), and the cost model requires a epilogue be generated for correctness, the code generation must actually do so.

The included test case on an unmodified opt will access memory one past the expected bound.  As a result, this patch is fixing a latent miscompile.

Differential Revision: https://reviews.llvm.org/D103700
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/test/Transforms/LoopVectorize/unroll_nonlatch.ll