[llvm-bugs] [Bug 43223] New: When -ffp-contract=on is effective, fma conversion works even with -O0.

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Sep 4 19:11:24 PDT 2019


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

            Bug ID: 43223
           Summary: When -ffp-contract=on is effective, fma conversion
                    works even with -O0.
           Product: new-bugs
           Version: unspecified
          Hardware: Other
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: ueno.masakazu at jp.fujitsu.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org

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.

-- 
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/20190905/8ba19e55/attachment.html>


More information about the llvm-bugs mailing list