-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[RISCV] Sink ordered reduction check into FAdd. NFC #114180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-backend-risc-v Author: Elvis Wang (ElvisWang123) ChangesFull diff: https://github.com/llvm/llvm-project/pull/114180.diff 1 Files Affected:
diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
index 395baa5f1aab99..bfc3f5b29a2aaa 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
@@ -1552,7 +1552,7 @@ RISCVTTIImpl::getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
}
// IR Reduction is composed by two vmv and one rvv reduction instruction.
- if (TTI::requiresOrderedReduction(FMF)) {
+ if (TTI::requiresOrderedReduction(FMF) && ElementTy->isFloatingPointTy()) {
Opcodes.push_back(RISCV::VFMV_S_F);
for (unsigned i = 0; i < LT.first.getValue(); i++)
Opcodes.push_back(RISCV::VFREDOSUM_VS);
|
What is the point of this change? Only floating point reductions should return true for requiresOrderedReduction? |
Without the check querying the I found this issue in the #114184. When we query the cost model and always pass the FMF flags from the IntrinsicCostAttributes, it always return the cost of FP ordered reduction. I thought it is more user friendly to check if it is floating point type and user can call |
Mostly summarizing my investigation for future reference. The way this works for the current reduce.* intrinsics is that BasicTTI dispatches these to getArithmeticReductionCost and getMinMaxReductionCost respective. BasicTTI distinguishes fadd/fmul from the other arithmetic, and specifically passes None for the FMF on non-FP arithmetics. It does pass the FMF to the MinMax variant, but since there are no ordered min/max variants, that doesn't apply. |
@@ -1552,7 +1552,7 @@ RISCVTTIImpl::getArithmeticReductionCost(unsigned Opcode, VectorType *Ty, | |||
} | |||
|
|||
// IR Reduction is composed by two vmv and one rvv reduction instruction. | |||
if (TTI::requiresOrderedReduction(FMF)) { | |||
if (TTI::requiresOrderedReduction(FMF) && ElementTy->isFloatingPointTy()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a cleaner way to express this change is to simply sink the check for requiresOrderedReduction under the FADD case in the switch below. That's the only supported reduction kind with an ordered variant.
I am worried about transformations using I am fine to close this PR. |
d6b3e45
to
24ecef8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I'll rework #114250 after this lands
24ecef8
to
5af5e32
Compare
No description provided.