From 3c8bf29f14e45cdf4c5dc5edcb3bb2f02cc9f394 Mon Sep 17 00:00:00 2001 From: serge-sans-paille Date: Wed, 10 Feb 2021 09:42:50 +0100 Subject: [PATCH] Reduce the number of attributes attached to each function 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 | 29 +++++++++++------------ clang/test/CodeGen/attr-target-x87-softfp.c | 4 ++-- clang/test/CodeGenOpenCL/no-signed-zeros.cl | 2 +- clang/test/CodeGenOpenCL/relaxed-fpmath.cl | 36 ++++++++++++++--------------- 4 files changed, 35 insertions(+), 36 deletions(-) diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 4280137..405b4d2 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -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 &Recips = CodeGenOpts.Reciprocals; diff --git a/clang/test/CodeGen/attr-target-x87-softfp.c b/clang/test/CodeGen/attr-target-x87-softfp.c index 0d26dab..445e312 100644 --- a/clang/test/CodeGen/attr-target-x87-softfp.c +++ b/clang/test/CodeGen/attr-target-x87-softfp.c @@ -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" diff --git a/clang/test/CodeGenOpenCL/no-signed-zeros.cl b/clang/test/CodeGenOpenCL/no-signed-zeros.cl index 5cbff4d..13ce480 100644 --- a/clang/test/CodeGenOpenCL/no-signed-zeros.cl +++ b/clang/test/CodeGenOpenCL/no-signed-zeros.cl @@ -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" diff --git a/clang/test/CodeGenOpenCL/relaxed-fpmath.cl b/clang/test/CodeGenOpenCL/relaxed-fpmath.cl index 1f12392..69cfd82 100644 --- a/clang/test/CodeGenOpenCL/relaxed-fpmath.cl +++ b/clang/test/CodeGenOpenCL/relaxed-fpmath.cl @@ -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. -- 2.7.4