<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - -ffp-contract=on prevents vectorization of reduction loop"
   href="https://bugs.llvm.org/show_bug.cgi?id=52266">52266</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>-ffp-contract=on prevents vectorization of reduction loop
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Loop Optimizer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>craig.topper@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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;
}

<a href="https://godbolt.org/z/cdv8dKPj9">https://godbolt.org/z/cdv8dKPj9</a>


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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>