[PATCH] D136695: [LV][RISCV] Disable vectorization of epilogue loops

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 25 09:18:00 PDT 2022


reames created this revision.
reames added reviewers: craig.topper, asb, frasercrmck, fhahn.
Herald added subscribers: sunshaoce, VincentWu, StephenFan, vkmr, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, bollu, JDevlieghere, simoncook, johnrusso, rbar, hiraditya, arichardson, mcrosier.
Herald added a project: All.
reames requested review of this revision.
Herald added subscribers: pcwang-thead, eopXD, MaskRay.
Herald added a project: LLVM.

Epilogue loop vectorization is a feature in the vectorize intended to avoid running fully scalar code when the vector length of the main loop turns out to be either longer than the trip count of the actual loop, or with a huge remainder.

In practice, this feature appears to not have been well tuned.  I honestly don't think it should be on by default at all, but it definitely shouldn't be on for RISCV.  Note that other targets have also disabled it, but they've done so via disabling interleaving - which is well, completely unrelated - and we don't want to do that for RISCV.

In the near term, many examples I'm seeing have terrible codegen for epilogue vectorization.  We are greatly increasing code size for little value at reasonable VLEN values for small types.  In the long term, the cases that epilogue vectorization are intended to handle are better handled via tail folding on RISCV.

As an aside, I also don't really trust the correctness of epilogue vectorization.  The code structure is such that otherwise straight forward changes sometimes break only epilogue vectorization.  The reuse of an existing vplan without careful validation opens significant room for nasty bugs.  Given how rarely the code is exercised, that is not a good combination.

As such, this patch introduces a TTI hook, and completely disables epilogue vectorization on RISCV.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136695

Files:
  llvm/include/llvm/Analysis/TargetTransformInfo.h
  llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
  llvm/lib/Analysis/TargetTransformInfo.cpp
  llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  llvm/test/Transforms/LoopVectorize/RISCV/divrem.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136695.470523.patch
Type: text/x-patch
Size: 8859 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221025/83d1493c/attachment.bin>


More information about the llvm-commits mailing list