[PATCH] D149174: [RISCV] Disable combineBinOpToReduce if the reduction AVL might be 0.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 25 11:10:34 PDT 2023


craig.topper created this revision.
craig.topper added reviewers: reames, frasercrmck, fakepaper56.
Herald added subscribers: jobnoorman, luke, VincentWu, 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, simoncook, johnrusso, rbar, asb, hiraditya, arichardson.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added subscribers: pcwang-thead, eopXD, MaskRay.
Herald added a project: LLVM.

If the reduction AVL is 0, operand 0 of the reduction will be
returned rather than the scalar input.

To make the fold legal, we would need to fold the new scalar value
with whatever operand 0 is which may require a new scalar operation
before the reduction.

Block the combine if we can't prove AVL is non-zero.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149174

Files:
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp


Index: llvm/lib/Target/RISCV/RISCVISelLowering.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -9170,6 +9170,11 @@
   if (!ScalarV.hasOneUse())
     return SDValue();
 
+  // If the AVL is zero, operand 0 will be returned. So it's not safe to fold.
+  // FIXME: We might be able to improve this if operand 0 is undef.
+  if (!isNonZeroAVL(Reduce.getOperand(5)))
+    return SDValue();
+
   SDValue NewStart = N->getOperand(1 - ReduceIdx);
 
   SDLoc DL(N);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149174.516850.patch
Type: text/x-patch
Size: 580 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230425/e7221c9c/attachment.bin>


More information about the llvm-commits mailing list