Author: Stephen Tozer Date: 2025-06-19T16:22:50+01:00 New Revision: 36af7345dfb8e84a1f2971db34089b63321e8467
URL: https://github.com/llvm/llvm-project/commit/36af7345dfb8e84a1f2971db34089b63321e8467 DIFF: https://github.com/llvm/llvm-project/commit/36af7345dfb8e84a1f2971db34089b63321e8467.diff LOG: Reapply "[Clang] Enable -fextend-variable-liveness at -Og (#118026)" Relands this feature after several fixes: * Force fake uses to be emitted before musttail calls (#136867) * Added soften-float legalization for fake uses (#142714) * Treat fake uses as size-less instructions in a SystemZ assert (#144390) If further issues with fake uses are found then this may be reverted again, but all currently-known issues are resolved. This reverts commit 2dc6e98169baeb1f73036da0ea50fd828d8323d0. Added: Modified: clang/docs/CommandGuide/clang.rst clang/docs/ReleaseNotes.rst clang/lib/Driver/ToolChains/Clang.cpp clang/test/Driver/extend-variable-liveness.c Removed: ################################################################################ diff --git a/clang/docs/CommandGuide/clang.rst b/clang/docs/CommandGuide/clang.rst index 1b8776c5e9ad2..7d49f2cc28a10 100644 --- a/clang/docs/CommandGuide/clang.rst +++ b/clang/docs/CommandGuide/clang.rst @@ -460,8 +460,11 @@ Code Generation Options :option:`-Oz` Like :option:`-Os` (and thus :option:`-O2`), but reduces code size further. - :option:`-Og` Like :option:`-O1`. In future versions, this option might - disable diff erent optimizations in order to improve debuggability. + :option:`-Og` Similar to :option:`-O1`, but with slightly reduced + optimization and better variable visibility. The same optimizations are run + as at :option:`-O1`, but the ``-fextend-variable-liveness`` flag is + also set, which tries to prevent optimizations from reducing the liveness of + user variables, improving their availability when debugging. :option:`-O` Equivalent to :option:`-O1`. diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index dd748ab06873d..96477ef6ddc9a 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -366,6 +366,10 @@ Modified Compiler Flags - The ``-fveclib=libmvec`` option now supports AArch64 targets (requires GLIBC 2.40 or newer). +- The ``-Og`` optimization flag now sets ``-fextend-variable-liveness``, + reducing performance slightly while reducing the number of optimized-out + variables. (#GH118026) + Removed Compiler Flags ------------------------- diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index a78a1c8978183..5a3c09e3a343a 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -7555,7 +7555,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, if (Args.hasArg(options::OPT_fretain_comments_from_system_headers)) CmdArgs.push_back("-fretain-comments-from-system-headers"); - Args.AddLastArg(CmdArgs, options::OPT_fextend_variable_liveness_EQ); + if (Arg *A = Args.getLastArg(options::OPT_fextend_variable_liveness_EQ)) { + A->render(Args, CmdArgs); + } else if (Arg *A = Args.getLastArg(options::OPT_O_Group); + A && A->containsValue("g")) { + // Set -fextend-variable-liveness=all by default at -Og. + CmdArgs.push_back("-fextend-variable-liveness=all"); + } // Forward -fcomment-block-commands to -cc1. Args.AddAllArgs(CmdArgs, options::OPT_fcomment_block_commands); diff --git a/clang/test/Driver/extend-variable-liveness.c b/clang/test/Driver/extend-variable-liveness.c index bbfb2ece6f297..99a5409ceccea 100644 --- a/clang/test/Driver/extend-variable-liveness.c +++ b/clang/test/Driver/extend-variable-liveness.c @@ -1,7 +1,8 @@ // Tests that -fextend-variable-liveness and its aliases are correctly passed -// by the driver. +// by the driver, and are set by default at -Og. // RUN: %clang -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,DEFAULT +// RUN: %clang -### -Og -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,ALL // RUN: %clang -fextend-variable-liveness=none -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,NONE // RUN: %clang -fextend-variable-liveness=this -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,THIS // RUN: %clang -fextend-variable-liveness=all -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,ALL _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits