From ff98fa955b5dc98bb05e30ed79299155d2a2f97c Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Sat, 7 Jan 2017 19:53:13 +0000 Subject: [PATCH] [-fcompare-debug] var tracking options are not optimization options If we include them in the ICF hash, they may cause congruence_groups to be processed in a different order due to different hashes, which in turn causes different funcdef_nos to be assigned to functions. Since these numbers are included in -fcompare-debug dumps, they cause failures. Since these options are not optimization options, in that they do not (or should not, save for bugs like this) affect the executable code output by the compiler, they should not be marked as such. This patch replaces the Optimization flag in the var-tracking options with the newly-introduced PerFunction flag, so that it can still be controlled on a per-function basis, but that disregards it in the hash computation used by ICF. This fixes -fcompare-debug failures in numerous LTO testcases. for gcc/ChangeLog * doc/options.texi (PerFunction): New. * opt-functions.awk (switch_flags): Map both Optimization and PerFunction to CL_OPTIMIZATION. * opth-gen.awk: Test for PerFunction flag along with Optimization. * optc-save-gen.awk: Likewise. Introduce var_opt_hash and set it only when the latter is present. Skip those that don't in the hash function generator. * common.opt (fvar-tracking): Mark as PerFunction instead of Optimization. (fvar-tracking-assignments): Likewise. (fvar-tracking-assignments-toggle): Likewise. (fvar-tracking-uninit): Likewise. From-SVN: r244198 --- gcc/ChangeLog | 16 ++++++++++++++++ gcc/common.opt | 8 ++++---- gcc/doc/options.texi | 7 +++++++ gcc/opt-functions.awk | 2 +- gcc/optc-save-gen.awk | 7 +++++-- gcc/opth-gen.awk | 2 +- 6 files changed, 34 insertions(+), 8 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 02a2a9ac950..9f7f0900bec 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,19 @@ +2017-01-07 Alexandre Oliva + + * doc/options.texi (PerFunction): New. + * opt-functions.awk (switch_flags): Map both Optimization and + PerFunction to CL_OPTIMIZATION. + * opth-gen.awk: Test for PerFunction flag along with + Optimization. + * optc-save-gen.awk: Likewise. Introduce var_opt_hash and set + it only when the latter is present. Skip those that don't in + the hash function generator. + * common.opt (fvar-tracking): Mark as PerFunction instead of + Optimization. + (fvar-tracking-assignments): Likewise. + (fvar-tracking-assignments-toggle): Likewise. + (fvar-tracking-uninit): Likewise. + 2017-01-07 Jakub Jelinek PR translation/79018 diff --git a/gcc/common.opt b/gcc/common.opt index a18e27d33f1..4b35e4b61be 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -2644,7 +2644,7 @@ Common Undocumented Var(flag_use_linker_plugin) ; will be set according to optimize, debug_info_level and debug_hooks ; in process_options (). fvar-tracking -Common Report Var(flag_var_tracking) Init(2) Optimization +Common Report Var(flag_var_tracking) Init(2) PerFunction Perform variable tracking. ; Positive if we should track variables at assignments, negative if @@ -2652,13 +2652,13 @@ Perform variable tracking. ; annotations. When flag_var_tracking_assignments == ; AUTODETECT_VALUE it will be set according to flag_var_tracking. fvar-tracking-assignments -Common Report Var(flag_var_tracking_assignments) Init(2) Optimization +Common Report Var(flag_var_tracking_assignments) Init(2) PerFunction Perform variable tracking by annotating assignments. ; Nonzero if we should toggle flag_var_tracking_assignments after ; processing options and computing its default. */ fvar-tracking-assignments-toggle -Common Report Var(flag_var_tracking_assignments_toggle) Optimization +Common Report Var(flag_var_tracking_assignments_toggle) PerFunction Toggle -fvar-tracking-assignments. ; Positive if we should track uninitialized variables, negative if @@ -2666,7 +2666,7 @@ Toggle -fvar-tracking-assignments. ; annotations. When flag_var_tracking_uninit == AUTODETECT_VALUE it ; will be set according to flag_var_tracking. fvar-tracking-uninit -Common Report Var(flag_var_tracking_uninit) Optimization +Common Report Var(flag_var_tracking_uninit) PerFunction Perform variable tracking and also tag variables that are uninitialized. ftree-vectorize diff --git a/gcc/doc/options.texi b/gcc/doc/options.texi index 5c067f75d6d..3b68aabcfc3 100644 --- a/gcc/doc/options.texi +++ b/gcc/doc/options.texi @@ -430,6 +430,13 @@ This is an optimization option. It should be shown as such in @code{Var} should be saved and restored when the optimization level is changed with @code{optimize} attributes. +@item PerFunction +This is an option that can be overridden on a per-function basis. +@code{Optimization} implies @code{PerFunction}, but options that do not +affect executable code generation may use this flag instead, so that the +option is not taken into account in ways that might affect executable +code generation. + @item Undocumented The option is deliberately missing documentation and should not be included in the @option{--help} output. diff --git a/gcc/opt-functions.awk b/gcc/opt-functions.awk index 540980ef54e..0736a6f3faf 100644 --- a/gcc/opt-functions.awk +++ b/gcc/opt-functions.awk @@ -105,7 +105,7 @@ function switch_flags (flags) test_flag("Undocumented", flags, " | CL_UNDOCUMENTED") \ test_flag("NoDWARFRecord", flags, " | CL_NO_DWARF_RECORD") \ test_flag("Warning", flags, " | CL_WARNING") \ - test_flag("Optimization", flags, " | CL_OPTIMIZATION") + test_flag("(Optimization|PerFunction)", flags, " | CL_OPTIMIZATION") sub( "^0 \\| ", "", result ) return result } diff --git a/gcc/optc-save-gen.awk b/gcc/optc-save-gen.awk index fb517fe034b..d79d1e9cd8d 100644 --- a/gcc/optc-save-gen.awk +++ b/gcc/optc-save-gen.awk @@ -100,7 +100,7 @@ var_opt_range["optimize_debug"] = "0, 1"; # cache. for (i = 0; i < n_opts; i++) { - if (flag_set_p("Optimization", flags[i])) { + if (flag_set_p("(Optimization|PerFunction)", flags[i])) { name = var_name(flags[i]) if(name == "") continue; @@ -743,7 +743,7 @@ var_opt_val[2] = "x_optimize_debug" var_opt_val_type[1] = "char " var_opt_val_type[2] = "char " for (i = 0; i < n_opts; i++) { - if (flag_set_p("Optimization", flags[i])) { + if (flag_set_p("(Optimization|PerFunction)", flags[i])) { name = var_name(flags[i]) if(name == "") continue; @@ -756,6 +756,7 @@ for (i = 0; i < n_opts; i++) { otype = var_type_struct(flags[i]) var_opt_val_type[n_opt_val] = otype; var_opt_val[n_opt_val++] = "x_" name; + var_opt_hash[n_opt_val] = flag_set_p("Optimization", flags[i]); } } print ""; @@ -765,6 +766,8 @@ print "cl_optimization_hash (struct cl_optimization const *ptr ATTRIBUTE_UNUSED) print "{"; print " inchash::hash hstate;"; for (i = 0; i < n_opt_val; i++) { + if (!var_opt_hash[i]) + continue; name = var_opt_val[i] print " hstate.add_wide_int (ptr->" name");"; } diff --git a/gcc/opth-gen.awk b/gcc/opth-gen.awk index f6b3812b8be..13577550a86 100644 --- a/gcc/opth-gen.awk +++ b/gcc/opth-gen.awk @@ -142,7 +142,7 @@ var_opt_char[1] = "unsigned char x_optimize_size"; var_opt_char[2] = "unsigned char x_optimize_debug"; for (i = 0; i < n_opts; i++) { - if (flag_set_p("Optimization", flags[i])) { + if (flag_set_p("(Optimization|PerFunction)", flags[i])) { name = var_name(flags[i]) if(name == "") continue; -- 2.30.2