[llvm] a5f1729 - [SDAG] Fix neutral value for vecreduce_fadd

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 29 13:29:38 PDT 2020


Author: Nikita Popov
Date: 2020-10-29T21:27:59+01:00
New Revision: a5f172927df578fe06e4b28da48d979458c88e0a

URL: https://github.com/llvm/llvm-project/commit/a5f172927df578fe06e4b28da48d979458c88e0a
DIFF: https://github.com/llvm/llvm-project/commit/a5f172927df578fe06e4b28da48d979458c88e0a.diff

LOG: [SDAG] Fix neutral value for vecreduce_fadd

The neutral value for FADD is -0.0, not 0.0, so this is what we
need to pad vectors with.

Added: 
    

Modified: 
    llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
    llvm/test/CodeGen/AArch64/vecreduce-fadd-legalization.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
index 133a577f974e..333c604690ab 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
@@ -4781,7 +4781,7 @@ SDValue DAGTypeLegalizer::WidenVecOp_VECREDUCE(SDNode *N) {
         APInt::getSignedMaxValue(ElemVT.getSizeInBits()), dl, ElemVT);
     break;
   case ISD::VECREDUCE_FADD:
-    NeutralElem = DAG.getConstantFP(0.0, dl, ElemVT);
+    NeutralElem = DAG.getConstantFP(-0.0, dl, ElemVT);
     break;
   case ISD::VECREDUCE_FMUL:
     NeutralElem = DAG.getConstantFP(1.0, dl, ElemVT);

diff  --git a/llvm/test/CodeGen/AArch64/vecreduce-fadd-legalization.ll b/llvm/test/CodeGen/AArch64/vecreduce-fadd-legalization.ll
index 8bbea08cccb6..9bdba70ba8d7 100644
--- a/llvm/test/CodeGen/AArch64/vecreduce-fadd-legalization.ll
+++ b/llvm/test/CodeGen/AArch64/vecreduce-fadd-legalization.ll
@@ -48,7 +48,9 @@ define fp128 @test_v1f128(<1 x fp128> %a) nounwind {
 define float @test_v3f32(<3 x float> %a) nounwind {
 ; CHECK-LABEL: test_v3f32:
 ; CHECK:       // %bb.0:
-; CHECK-NEXT:    mov v0.s[3], wzr
+; CHECK-NEXT:    mov w8, #-2147483648
+; CHECK-NEXT:    fmov s1, w8
+; CHECK-NEXT:    mov v0.s[3], v1.s[0]
 ; CHECK-NEXT:    ext v1.16b, v0.16b, v0.16b, #8
 ; CHECK-NEXT:    fadd v0.2s, v0.2s, v1.2s
 ; CHECK-NEXT:    faddp s0, v0.2s
@@ -63,7 +65,7 @@ define float @test_v5f32(<5 x float> %a) nounwind {
 ; CHECK-NEXT:    // kill: def $s0 killed $s0 def $q0
 ; CHECK-NEXT:    // kill: def $s1 killed $s1 def $q1
 ; CHECK-NEXT:    // kill: def $s2 killed $s2 def $q2
-; CHECK-NEXT:    movi v5.2d, #0000000000000000
+; CHECK-NEXT:    movi v5.4s, #128, lsl #24
 ; CHECK-NEXT:    mov v0.s[1], v1.s[0]
 ; CHECK-NEXT:    mov v0.s[2], v2.s[0]
 ; CHECK-NEXT:    // kill: def $s4 killed $s4 def $q4


        


More information about the llvm-commits mailing list