[PATCH] D111555: [LoopVectorize] Add vector reduction support for fmuladd intrinsic

Dave Green via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 9 00:35:10 PST 2021


dmgreen added a comment.

I think, unlike the other opcodes in a reduction chain, we may need to check that the operand number is correct. The other opcodes are commutative so it doesn't matter which of the operands the reduction passes through, but for fmuladd we need to ensure we are dealing with the last addition parameter.

Something like this test case I think shouldn't be treated like an add reduction, due to the induction passing through the multiply operand of the fmuladd:

  define float @fmuladd_strict(float* %a, float* %b, i64 %n) #0 {  
  entry:
    br label %for.body
  
  for.body:
    %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
    %sum.07 = phi float [ 0.000000e+00, %entry ], [ %muladd, %for.body ]
    %arrayidx = getelementptr inbounds float, float* %a, i64 %iv
    %0 = load float, float* %arrayidx, align 4 
    %arrayidx2 = getelementptr inbounds float, float* %b, i64 %iv
    %1 = load float, float* %arrayidx2, align 4
    %muladd = tail call fast float @llvm.fmuladd.f32(float %0, float %sum.07, float %1)
    %iv.next = add nuw nsw i64 %iv, 1  
    %exitcond.not = icmp eq i64 %iv.next, %n
    br i1 %exitcond.not, label %for.end, label %for.body
   
  for.end: 
    ret float %muladd
  }
   
  declare float @llvm.fmuladd.f32(float, float, float)                                



================
Comment at: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:9609-9610
+      bool IsFMulAdd = (Kind == RecurKind::FMulAdd);
+      if (IsFMulAdd)
+        assert(
+            RecurrenceDescriptor::isFMulAddIntrinsic(R) &&
----------------
This may be simpler if it avoids the if: `assert((!IsFMulAdd || RecurrenceDescriptor::isFMulAddIntrinsic(R)) && "...");`


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111555/new/

https://reviews.llvm.org/D111555



More information about the llvm-commits mailing list