Author: serge-sans-paille Date: 2021-02-16T16:19:54+01:00 New Revision: 3c8bf29f14e45cdf4c5dc5edcb3bb2f02cc9f394
URL: https://github.com/llvm/llvm-project/commit/3c8bf29f14e45cdf4c5dc5edcb3bb2f02cc9f394 DIFF: https://github.com/llvm/llvm-project/commit/3c8bf29f14e45cdf4c5dc5edcb3bb2f02cc9f394.diff LOG: 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 Added: Modified: 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 Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 42801372189b..405b4d2e1980 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<std::string> &Recips = CodeGenOpts.Reciprocals; diff --git a/clang/test/CodeGen/attr-target-x87-softfp.c b/clang/test/CodeGen/attr-target-x87-softfp.c index 0d26dab74ec0..445e31280f84 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 5cbff4dd9e0c..13ce480ebe6e 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 1f12392d861b..69cfd82d2d71 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. _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits