[llvm-dev] defaults for FP contraction [e.g. fused multiply-add]: suggestion and patch to be slightly more aggressive and to make Clang`s optimization settings closer to having the same meaning as when they are given to GCC [at least for "-O3"]

Abe Skolnik via llvm-dev llvm-dev at lists.llvm.org
Mon Sep 12 11:58:58 PDT 2016


The now-ungated-by-O3-or-higher passes with no new unexpected failures when run on Ubuntu 
14.04.1 on a Xeon-based server in 64-bit mode.  [No known unexpected failures when testing on 
any other platform.]

-- Abe





The below patch is relative to...
---------------------------------
commit b0768e805d1d33d730e5bd44ba578df043dfbc66
Author: George Burgess IV <george.burgess.iv at gmail.com>
Date:   Wed Sep 7 20:03:19 2016 +0000






diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 619ea9c..4b04937 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2437,6 +2437,12 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
    if (Arch == llvm::Triple::spir || Arch == llvm::Triple::spir64) {
      Res.getDiagnosticOpts().Warnings.push_back("spir-compat");
    }
+
+  // If there will ever be e.g. "LangOpts.C", replace "LangOpts.C11 || LangOpts.C99" with 
"LangOpts.C" on the next line.
+  if (    (LangOpts.C11 || LangOpts.C99 || LangOpts.CPlusPlus)                        // ...
+  /*...*/ && ( CodeGenOptions::FPC_On == Res.getCodeGenOpts().getFPContractMode() ) ) // ... 
// just being careful
+    LangOpts.DefaultFPContract = 1;
+
    return Success;
  }

diff --git a/clang/test/CodeGen/fp-contract-pragma.cpp b/clang/test/CodeGen/fp-contract-pragma.cpp
index 1c5921a..0949272 100644
--- a/clang/test/CodeGen/fp-contract-pragma.cpp
+++ b/clang/test/CodeGen/fp-contract-pragma.cpp
@@ -13,6 +13,7 @@ float fp_contract_2(float a, float b, float c) {
  // CHECK: _Z13fp_contract_2fff
  // CHECK: %[[M:.+]] = fmul float %a, %b
  // CHECK-NEXT: fadd float %[[M]], %c
+  #pragma STDC FP_CONTRACT OFF
    {
      #pragma STDC FP_CONTRACT ON
    }


More information about the llvm-dev mailing list