[llvm] e80da0f - [RISCV] Disable combineBinOpToReduce if the reduction AVL might be 0.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 25 18:47:16 PDT 2023
Author: Craig Topper
Date: 2023-04-25T18:46:54-07:00
New Revision: e80da0f8409aaf70d18b12c5d5d884f2c9cbddcc
URL: https://github.com/llvm/llvm-project/commit/e80da0f8409aaf70d18b12c5d5d884f2c9cbddcc
DIFF: https://github.com/llvm/llvm-project/commit/e80da0f8409aaf70d18b12c5d5d884f2c9cbddcc.diff
LOG: [RISCV] Disable combineBinOpToReduce if the reduction AVL might be 0.
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.
Reviewed By: fakepaper56
Differential Revision: https://reviews.llvm.org/D149174
Added:
Modified:
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 6d2b442b0c2a6..22bca318c897b 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -9170,6 +9170,11 @@ static SDValue combineBinOpToReduce(SDNode *N, SelectionDAG &DAG,
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);
More information about the llvm-commits
mailing list