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: unassignedb...@nondot.org
          Reporter: ueno.masak...@jp.fujitsu.com
                CC: htmldevelo...@gmail.com, llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to