Reduce the number of attributes attached to each function
authorserge-sans-paille <sguelton@redhat.com>
Wed, 10 Feb 2021 08:42:50 +0000 (09:42 +0100)
committerserge-sans-paille <sguelton@redhat.com>
Tue, 16 Feb 2021 15:19:54 +0000 (16:19 +0100)
This takes advantage of the implicit default behavior to reduce the number of
attributes, which in turns reduces compilation time. I've observed -3% in
instruction count when compiling sqlite3 amalgamation with -O0

Differential Revision: https://reviews.llvm.org/D96400

clang/lib/CodeGen/CGCall.cpp
clang/test/CodeGen/attr-target-x87-softfp.c
clang/test/CodeGenOpenCL/no-signed-zeros.cl
clang/test/CodeGenOpenCL/relaxed-fpmath.cl

index 4280137..405b4d2 100644 (file)
@@ -1773,8 +1773,8 @@ void CodeGenModule::getDefaultFunctionAttributes(StringRef Name,
     }
     FuncAttrs.addAttribute("frame-pointer", FpKind);
 
-    FuncAttrs.addAttribute("less-precise-fpmad",
-                           llvm::toStringRef(CodeGenOpts.LessPreciseFPMAD));
+    if (CodeGenOpts.LessPreciseFPMAD)
+      FuncAttrs.addAttribute("less-precise-fpmad", "true");
 
     if (CodeGenOpts.NullPointerIsValid)
       FuncAttrs.addAttribute(llvm::Attribute::NullPointerIsValid);
@@ -1788,9 +1788,8 @@ void CodeGenModule::getDefaultFunctionAttributes(StringRef Name,
           CodeGenOpts.FP32DenormalMode.str());
     }
 
-    FuncAttrs.addAttribute("no-trapping-math",
-                           llvm::toStringRef(LangOpts.getFPExceptionMode() ==
-                                             LangOptions::FPE_Ignore));
+    if (LangOpts.getFPExceptionMode() == LangOptions::FPE_Ignore)
+      FuncAttrs.addAttribute("no-trapping-math", "true");
 
     // Strict (compliant) code is the default, so only add this attribute to
     // indicate that we are trying to workaround a problem case.
@@ -1799,18 +1798,18 @@ void CodeGenModule::getDefaultFunctionAttributes(StringRef Name,
 
     // TODO: Are these all needed?
     // unsafe/inf/nan/nsz are handled by instruction-level FastMathFlags.
-    FuncAttrs.addAttribute("no-infs-fp-math",
-                           llvm::toStringRef(LangOpts.NoHonorInfs));
-    FuncAttrs.addAttribute("no-nans-fp-math",
-                           llvm::toStringRef(LangOpts.NoHonorNaNs));
-    FuncAttrs.addAttribute("unsafe-fp-math",
-                           llvm::toStringRef(LangOpts.UnsafeFPMath));
-    FuncAttrs.addAttribute("use-soft-float",
-                           llvm::toStringRef(CodeGenOpts.SoftFloat));
+    if (LangOpts.NoHonorInfs)
+      FuncAttrs.addAttribute("no-infs-fp-math", "true");
+    if (LangOpts.NoHonorNaNs)
+      FuncAttrs.addAttribute("no-nans-fp-math", "true");
+    if (LangOpts.UnsafeFPMath)
+      FuncAttrs.addAttribute("unsafe-fp-math", "true");
+    if (CodeGenOpts.SoftFloat)
+      FuncAttrs.addAttribute("use-soft-float", "true");
     FuncAttrs.addAttribute("stack-protector-buffer-size",
                            llvm::utostr(CodeGenOpts.SSPBufferSize));
-    FuncAttrs.addAttribute("no-signed-zeros-fp-math",
-                           llvm::toStringRef(LangOpts.NoSignedZero));
+    if (LangOpts.NoSignedZero)
+      FuncAttrs.addAttribute("no-signed-zeros-fp-math", "true");
 
     // TODO: Reciprocal estimate codegen options should apply to instructions?
     const std::vector<std::string> &Recips = CodeGenOpts.Reciprocals;
index 0d26dab..445e312 100644 (file)
@@ -8,9 +8,9 @@ int __attribute__((target("no-x87"))) bar(int a) { return 4; }
 // CHECK: bar{{.*}} #1
 
 // CHECK: #0 = {{.*}}"target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87"
-// HARD: "use-soft-float"="false"
+// HARD-NOT: "use-soft-float"
 // SOFT: "use-soft-float"="true"
 
 // CHECK: #1 = {{.*}}"target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,-x87"
-// HARD: "use-soft-float"="false"
+// HARD-NOT: "use-soft-float"
 // SOFT: "use-soft-float"="true"
index 5cbff4d..13ce480 100644 (file)
@@ -6,5 +6,5 @@ float signedzeros(float a) {
 }
 
 // CHECK: attributes
-// NORMAL: "no-signed-zeros-fp-math"="false"
+// NORMAL-NOT: "no-signed-zeros-fp-math"
 // NO-SIGNED-ZEROS: "no-signed-zeros-fp-math"="true"
index 1f12392..69cfd82 100644 (file)
@@ -29,11 +29,11 @@ float spscalardiv(float a, float b) {
 }
 // CHECK: attributes
 
-// NORMAL: "less-precise-fpmad"="false"
-// NORMAL: "no-infs-fp-math"="false"
-// NORMAL: "no-nans-fp-math"="false"
-// NORMAL: "no-signed-zeros-fp-math"="false"
-// NORMAL: "unsafe-fp-math"="false"
+// NORMAL-NOT: "less-precise-fpmad"
+// NORMAL-NOT: "no-infs-fp-math"
+// NORMAL-NOT: "no-nans-fp-math"
+// NORMAL-NOT: "no-signed-zeros-fp-math"
+// NORMAL-NOT: "unsafe-fp-math"
 
 // FAST: "less-precise-fpmad"="true"
 // FAST: "no-infs-fp-math"="true"
@@ -41,29 +41,29 @@ float spscalardiv(float a, float b) {
 // FAST: "no-signed-zeros-fp-math"="true"
 // FAST: "unsafe-fp-math"="true"
 
-// FINITE: "less-precise-fpmad"="false"
+// FINITE-NOT: "less-precise-fpmad"
 // FINITE: "no-infs-fp-math"="true"
 // FINITE: "no-nans-fp-math"="true"
-// FINITE: "no-signed-zeros-fp-math"="false"
-// FINITE: "unsafe-fp-math"="false"
+// FINITE-NOT: "no-signed-zeros-fp-math"
+// FINITE-NOT: "unsafe-fp-math"
 
 // UNSAFE: "less-precise-fpmad"="true"
-// UNSAFE: "no-infs-fp-math"="false"
-// UNSAFE: "no-nans-fp-math"="false"
+// UNSAFE-NOT: "no-infs-fp-math"
+// UNSAFE-NOT: "no-nans-fp-math"
 // UNSAFE: "no-signed-zeros-fp-math"="true"
 // UNSAFE: "unsafe-fp-math"="true"
 
 // MAD: "less-precise-fpmad"="true"
-// MAD: "no-infs-fp-math"="false"
-// MAD: "no-nans-fp-math"="false"
-// MAD: "no-signed-zeros-fp-math"="false"
-// MAD: "unsafe-fp-math"="false"
+// MAD-NOT: "no-infs-fp-math"
+// MAD-NOT: "no-nans-fp-math"
+// MAD-NOT: "no-signed-zeros-fp-math"
+// MAD-NOT: "unsafe-fp-math"
 
-// NOSIGNED: "less-precise-fpmad"="false"
-// NOSIGNED: "no-infs-fp-math"="false"
-// NOSIGNED: "no-nans-fp-math"="false"
+// NOSIGNED-NOT: "less-precise-fpmad"
+// NOSIGNED-NOT: "no-infs-fp-math"
+// NOSIGNED-NOT: "no-nans-fp-math"
 // NOSIGNED: "no-signed-zeros-fp-math"="true"
-// NOSIGNED: "unsafe-fp-math"="false"
+// NOSIGNED-NOT: "unsafe-fp-math"
 
 #else
 // Undefine this to avoid putting it in the PCH.