[llvm-bugs] [Bug 52266] New: -ffp-contract=on prevents vectorization of reduction loop

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Oct 22 10:57:43 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=52266

            Bug ID: 52266
           Summary: -ffp-contract=on prevents vectorization of reduction
                    loop
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: craig.topper at gmail.com
                CC: llvm-bugs at lists.llvm.org

Compiling this function with -ffp-contract=on does not vectorize when compiler
for -march=haswell. It works for -ffp-contract=off or -ffp-contract=fast

float foo(float *a, float *b, int n) {
  float sum = 0.0f;

  for (int i = 0; i != n; ++i) {
#pragma clang fp reassociate(on)
    sum += a[i] * b[i];
  }
  return sum;
}

https://godbolt.org/z/cdv8dKPj9


I believe the problems is that the -ffp-contract=on causes the multiply and
accumulate in the loop to become a fmuladd intrinsic in the frontend. This
prevents the reduction recurrence from being detected since it is not an FAdd
instruction. With -ffp-contract=off or fast, there are separate fmul and fadd
instructions.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20211022/a75559fd/attachment.html>


More information about the llvm-bugs mailing list