[LV] Account for minimum vscale when rejecting scalable vectorization of short loops
authorPhilip Reames <preames@rivosinc.com>
Fri, 9 Dec 2022 19:24:01 +0000 (11:24 -0800)
committerPhilip Reames <listmail@philipreames.com>
Fri, 9 Dec 2022 19:29:41 +0000 (11:29 -0800)
commitb0f904b6da044ea65d344bc07fc56234adbc6268
treec438802e54d51686b5c9347821eae1e065be36bc
parent9cc0779c4e2378e3121968078f09dde14288459d
[LV] Account for minimum vscale when rejecting scalable vectorization of short loops

The vectorizer has code to reject scalable vectorization of loops with very short trip counts, and instead use fixed length vectors. The current code doesn't account for the minimum vscale value known, and thus under estimates the number of lanes in the scalable type for RISCV's default configuration. This results in use of predication and a trivially dead loop where a single straight line piece of code would suffice.

Note that the code quality of the original scalable vectorization could (and probably should) be improved other ways as well. This patch is solely about whether the scalable vectorization was the right choice to begin with.

This bit of code - both with and without my change - does make the unchecked assumption that the target knows how to lower fixed length vectors whose length is provably less than the vector length.

Differential Revision: https://reviews.llvm.org/D137285
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/test/Transforms/LoopVectorize/RISCV/short-trip-count.ll