Skip to content

Commit 36af734

Browse files
committed
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 2dc6e98.
1 parent 3de01d0 commit 36af734

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

clang/docs/CommandGuide/clang.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,11 @@ Code Generation Options
460460
:option:`-Oz` Like :option:`-Os` (and thus :option:`-O2`), but reduces code
461461
size further.
462462

463-
:option:`-Og` Like :option:`-O1`. In future versions, this option might
464-
disable different optimizations in order to improve debuggability.
463+
:option:`-Og` Similar to :option:`-O1`, but with slightly reduced
464+
optimization and better variable visibility. The same optimizations are run
465+
as at :option:`-O1`, but the ``-fextend-variable-liveness`` flag is
466+
also set, which tries to prevent optimizations from reducing the liveness of
467+
user variables, improving their availability when debugging.
465468

466469
:option:`-O` Equivalent to :option:`-O1`.
467470

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ Modified Compiler Flags
366366

367367
- The ``-fveclib=libmvec`` option now supports AArch64 targets (requires GLIBC 2.40 or newer).
368368

369+
- The ``-Og`` optimization flag now sets ``-fextend-variable-liveness``,
370+
reducing performance slightly while reducing the number of optimized-out
371+
variables. (#GH118026)
372+
369373
Removed Compiler Flags
370374
-------------------------
371375

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7555,7 +7555,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
75557555
if (Args.hasArg(options::OPT_fretain_comments_from_system_headers))
75567556
CmdArgs.push_back("-fretain-comments-from-system-headers");
75577557

7558-
Args.AddLastArg(CmdArgs, options::OPT_fextend_variable_liveness_EQ);
7558+
if (Arg *A = Args.getLastArg(options::OPT_fextend_variable_liveness_EQ)) {
7559+
A->render(Args, CmdArgs);
7560+
} else if (Arg *A = Args.getLastArg(options::OPT_O_Group);
7561+
A && A->containsValue("g")) {
7562+
// Set -fextend-variable-liveness=all by default at -Og.
7563+
CmdArgs.push_back("-fextend-variable-liveness=all");
7564+
}
75597565

75607566
// Forward -fcomment-block-commands to -cc1.
75617567
Args.AddAllArgs(CmdArgs, options::OPT_fcomment_block_commands);

clang/test/Driver/extend-variable-liveness.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Tests that -fextend-variable-liveness and its aliases are correctly passed
2-
// by the driver.
2+
// by the driver, and are set by default at -Og.
33

44
// RUN: %clang -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,DEFAULT
5+
// RUN: %clang -### -Og -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,ALL
56
// RUN: %clang -fextend-variable-liveness=none -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,NONE
67
// RUN: %clang -fextend-variable-liveness=this -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,THIS
78
// RUN: %clang -fextend-variable-liveness=all -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,ALL

0 commit comments

Comments
 (0)