<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 - When -ffp-contract=on is effective, fma conversion works even with -O0."
   href="https://bugs.llvm.org/show_bug.cgi?id=43223">43223</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>When -ffp-contract=on is effective, fma conversion works even with -O0.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </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>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>ueno.masakazu@jp.fujitsu.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>When -ffp-contract=on is effective, fma conversion works even with -O0.
I think it is better to stop fma conversion when -O0.

Sample program:
float foo(float b, float c, float d) {
   return b * c + d;
}

$ clang -O0 -ffp-contract=on a.c -S -o - | grep fma  // OK?
        fmadd   s0, s0, s1, s2
$ clang -O1 -ffp-contract=on a.c -S -o - | grep fma
        fmadd   s0, s0, s1, s2
$ clang -O0 -ffp-contract=fast a.c -S -o - | grep fma
$ clang -O1 -ffp-contract=fast a.c -S -o - | grep fma
        fmadd   s0, s0, s1, s2

It seems that it can be stopped by making the following changes.
What do you think?

diff --git a/clang/lib/CodeGen/CGExprScalar.cpp
b/clang/lib/CodeGen/CGExprScalar.cpp
index 3d082de..f0d9fda 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -3308,7 +3308,8 @@ static Value* tryEmitFMulAdd(const BinOpInfo &op,
          "Only fadd/fsub can be the root of an fmuladd.");

   // Check whether this op is marked as fusable.
-  if (!op.FPFeatures.allowFPContractWithinStatement())
+  if (CGF.CGM.getCodeGenOpts().OptimizationLevel == 0 ||
+      !op.FPFeatures.allowFPContractWithinStatement())
     return nullptr;

   // We have a potentially fusable op. Look for a mul on one of the operands.</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>