[PATCH] D115978: [RISCV] Use positive 0.0 for the neutral element in fadd reductions if nsz is present.
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 23 08:38:10 PST 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7704c503ecb8: [RISCV] Use positive 0.0 for the neutral element in fadd reductions if nsz is… (authored by craig.topper).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D115978/new/
https://reviews.llvm.org/D115978
Files:
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-reduction-fp.ll
llvm/test/CodeGen/RISCV/rvv/vreductions-fp-sdnode.ll
Index: llvm/test/CodeGen/RISCV/rvv/vreductions-fp-sdnode.ll
===================================================================
--- llvm/test/CodeGen/RISCV/rvv/vreductions-fp-sdnode.ll
+++ llvm/test/CodeGen/RISCV/rvv/vreductions-fp-sdnode.ll
@@ -882,3 +882,17 @@
%red = call double @llvm.vector.reduce.fmax.nxv16f64(<vscale x 16 x double> %v)
ret double %red
}
+
+define float @vreduce_nsz_fadd_nxv1f32(<vscale x 1 x float> %v, float %s) {
+; CHECK-LABEL: vreduce_nsz_fadd_nxv1f32:
+; CHECK: # %bb.0:
+; CHECK-NEXT: vsetivli zero, 1, e32, m1, ta, mu
+; CHECK-NEXT: vmv.v.i v9, 0
+; CHECK-NEXT: vsetvli a0, zero, e32, mf2, ta, mu
+; CHECK-NEXT: vfredusum.vs v8, v8, v9
+; CHECK-NEXT: vfmv.f.s ft0, v8
+; CHECK-NEXT: fadd.s fa0, fa0, ft0
+; CHECK-NEXT: ret
+ %red = call reassoc nsz float @llvm.vector.reduce.fadd.nxv1f32(float %s, <vscale x 1 x float> %v)
+ ret float %red
+}
Index: llvm/test/CodeGen/RISCV/rvv/fixed-vectors-reduction-fp.ll
===================================================================
--- llvm/test/CodeGen/RISCV/rvv/fixed-vectors-reduction-fp.ll
+++ llvm/test/CodeGen/RISCV/rvv/fixed-vectors-reduction-fp.ll
@@ -1408,3 +1408,20 @@
%red = call double @llvm.vector.reduce.fmax.v32f64(<32 x double> %v)
ret double %red
}
+
+define float @vreduce_nsz_fadd_v4f32(<4 x float>* %x, float %s) {
+; CHECK-LABEL: vreduce_nsz_fadd_v4f32:
+; CHECK: # %bb.0:
+; CHECK-NEXT: vsetivli zero, 4, e32, m1, ta, mu
+; CHECK-NEXT: vle32.v v8, (a0)
+; CHECK-NEXT: vsetivli zero, 1, e32, m1, ta, mu
+; CHECK-NEXT: vmv.v.i v9, 0
+; CHECK-NEXT: vsetivli zero, 4, e32, m1, ta, mu
+; CHECK-NEXT: vfredusum.vs v8, v8, v9
+; CHECK-NEXT: vfmv.f.s ft0, v8
+; CHECK-NEXT: fadd.s fa0, fa0, ft0
+; CHECK-NEXT: ret
+ %v = load <4 x float>, <4 x float>* %x
+ %red = call reassoc nsz float @llvm.vector.reduce.fadd.v4f32(float %s, <4 x float> %v)
+ ret float %red
+}
Index: llvm/lib/Target/RISCV/RISCVISelLowering.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -4538,9 +4538,12 @@
switch (Opcode) {
default:
llvm_unreachable("Unhandled reduction");
- case ISD::VECREDUCE_FADD:
- return std::make_tuple(RISCVISD::VECREDUCE_FADD_VL, Op.getOperand(0),
- DAG.getNeutralElement(BaseOpcode, DL, EltVT, Flags));
+ case ISD::VECREDUCE_FADD: {
+ // Use positive zero if we can. It is cheaper to materialize.
+ SDValue Zero =
+ DAG.getConstantFP(Flags.hasNoSignedZeros() ? 0.0 : -0.0, DL, EltVT);
+ return std::make_tuple(RISCVISD::VECREDUCE_FADD_VL, Op.getOperand(0), Zero);
+ }
case ISD::VECREDUCE_SEQ_FADD:
return std::make_tuple(RISCVISD::VECREDUCE_SEQ_FADD_VL, Op.getOperand(1),
Op.getOperand(0));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115978.396033.patch
Type: text/x-patch
Size: 2878 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211223/35205396/attachment.bin>
More information about the llvm-commits
mailing list