[PATCH] D131264: [RISCVInsertVSETVLI] Remove an unsound optimization

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 5 08:19:41 PDT 2022


reames created this revision.
reames added reviewers: craig.topper, frasercrmck, kito-cheng.
Herald added subscribers: sunshaoce, VincentWu, luke957, StephenFan, vkmr, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, niosHD, sabuasal, bollu, simoncook, johnrusso, rbar, asb, 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.

This fixes a bug reported privately by @craig.topper. Here's an example which illustrates the problem:

  vsetivli a1, a0, e32, m1, ta, mu # both DefInfo and PrevInfo
  vsetivli a2, a1, e32, m4, ta, mu

With the unsound result being:

  vsetivli a1, a0, e32, m1, ta, mu 
  vsetivli a2, a0, e32, m4, ta, mu

Consider the case where this is running on a machine with VLEN=512,.  For this case, the VLMAXs are 16 and 64 respectively.

Consider for a0 = 33.  The correct result is: a1 = 16, and a2 = 16

After the unsound optimization: a1 = 16 and a2 = 33

This particular example used VLMAXs which differed by more than a power of two.  With a difference of only one power of two, there's another form of this bug which involves the AVL < 2 x VLMAX special case, but that ones more complicated to construct as many examples turn out accidentally sound.

This patch takes the approach of simply removing the unsound optimization, but there are multiple sound sub-cases of it.  I plan to return to at least a couple of them, but figured it was cleaner to remove the unsound optimization (for ease of backporting), and then review the new optimizations on their own.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131264

Files:
  llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
  llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.ll
  llvm/test/CodeGen/RISCV/rvv/vsetvli-insert.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131264.450290.patch
Type: text/x-patch
Size: 5117 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220805/a63614f5/attachment.bin>


More information about the llvm-commits mailing list