Skip to content

Commit fe9458c

Browse files
committed
Fix up flag_cunroll_grow_size handling in presence of optimize attr [PR96535]
As the testcase in the PR shows (not included in the patch, as it seems quite fragile to observe unrolling in the IL), the introduction of flag_cunroll_grow_size broke optimize attribute related to loop unrolling. The problem is that the new option flag is set (if not set explicitly) only in process_options and in rs6000_option_override_internal (and there only if global_init_p). So, this means that while it is Optimization option, it will only be set based on the command line -funroll-loops/-O3/-fpeel-loops or -funroll-all-loops, which means that if command line does include any of those, it is enabled even for functions that will through optimize attribute have all of those disabled, and if command line does not include those, it will not be enabled for functions that will through optimize attribute have any of those enabled. process_options is called just once, so IMHO it should be handling only non-Optimization option adjustments (various other options suffer from that too, but as this is a regression from 10.1 on the 10 branch, changing those is not appropriate). Similarly, rs6000_option_override_internal is called only once (with global_init_p) and then for target attribute handling, but not for optimize attribute handling. This patch moves the unrolling related handling from process_options into finish_options which is invoked whenever the options are being finalized, and the rs6000 specific parts into the override_options_after_change hook which is called for optimize attribute handling (and unfortunately also th cfun changes, but what the hook does is cheap) and I've added a call to that from rs6000_override_options_internal, so it is also called on cmdline processing and for target attribute. Furthermore, it stops using AUTODETECT_VALUE, which can work only once, and instead uses the global_options_set.x_... flags. 2020-08-12 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/96535 * toplev.c (process_options): Move flag_unroll_loops and flag_cunroll_grow_size handling from here to ... * opts.c (finish_options): ... here. For flag_cunroll_grow_size, don't check for AUTODETECT_VALUE, but instead check opts_set->x_flag_cunroll_grow_size. * common.opt (funroll-completely-grow-size): Default to 0. * config/rs6000/rs6000.c (TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE): Redefine. (rs6000_override_options_after_change): New function. (rs6000_option_override_internal): Call it. Move there the flag_cunroll_grow_size, unroll_only_small_loops and flag_rename_registers handling.
1 parent a12026e commit fe9458c

File tree

4 files changed

+49
-33
lines changed

4 files changed

+49
-33
lines changed

gcc/common.opt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2884,7 +2884,7 @@ Common Report Var(flag_unroll_all_loops) Optimization
28842884
Perform loop unrolling for all loops.
28852885

28862886
funroll-completely-grow-size
2887-
Undocumented Var(flag_cunroll_grow_size) Init(2) Optimization
2887+
Undocumented Var(flag_cunroll_grow_size) Optimization
28882888
; Internal undocumented flag, allow size growth during complete unrolling
28892889

28902890
; Nonzero means that loop optimizer may assume that the induction variables

gcc/config/rs6000/rs6000.c

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,9 @@ static const struct attribute_spec rs6000_attribute_table[] =
14931493
#undef TARGET_PROMOTE_FUNCTION_MODE
14941494
#define TARGET_PROMOTE_FUNCTION_MODE rs6000_promote_function_mode
14951495

1496+
#undef TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE
1497+
#define TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE rs6000_override_options_after_change
1498+
14961499
#undef TARGET_RETURN_IN_MEMORY
14971500
#define TARGET_RETURN_IN_MEMORY rs6000_return_in_memory
14981501

@@ -3420,6 +3423,34 @@ rs6000_md_asm_adjust (vec<rtx> &/*outputs*/, vec<rtx> &/*inputs*/,
34203423
return NULL;
34213424
}
34223425

3426+
/* This target function is similar to the hook TARGET_OPTION_OVERRIDE
3427+
but is called when the optimize level is changed via an attribute or
3428+
pragma or when it is reset at the end of the code affected by the
3429+
attribute or pragma. It is not called at the beginning of compilation
3430+
when TARGET_OPTION_OVERRIDE is called so if you want to perform these
3431+
actions then, you should have TARGET_OPTION_OVERRIDE call
3432+
TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE. */
3433+
3434+
static void
3435+
rs6000_override_options_after_change (void)
3436+
{
3437+
/* Explicit -funroll-loops turns -munroll-only-small-loops off, and
3438+
turns -frename-registers on. */
3439+
if ((global_options_set.x_flag_unroll_loops && flag_unroll_loops)
3440+
|| (global_options_set.x_flag_unroll_all_loops
3441+
&& flag_unroll_all_loops))
3442+
{
3443+
if (!global_options_set.x_unroll_only_small_loops)
3444+
unroll_only_small_loops = 0;
3445+
if (!global_options_set.x_flag_rename_registers)
3446+
flag_rename_registers = 1;
3447+
if (!global_options_set.x_flag_cunroll_grow_size)
3448+
flag_cunroll_grow_size = 1;
3449+
}
3450+
else if (!global_options_set.x_flag_cunroll_grow_size)
3451+
flag_cunroll_grow_size = flag_peel_loops || optimize >= 3;
3452+
}
3453+
34233454
/* Override command line options.
34243455

34253456
Combine build-specific configuration information with options
@@ -4647,30 +4678,15 @@ rs6000_option_override_internal (bool global_init_p)
46474678
param_sched_pressure_algorithm,
46484679
SCHED_PRESSURE_MODEL);
46494680

4650-
/* Explicit -funroll-loops turns -munroll-only-small-loops off, and
4651-
turns -frename-registers on. */
4652-
if ((global_options_set.x_flag_unroll_loops && flag_unroll_loops)
4653-
|| (global_options_set.x_flag_unroll_all_loops
4654-
&& flag_unroll_all_loops))
4655-
{
4656-
if (!global_options_set.x_unroll_only_small_loops)
4657-
unroll_only_small_loops = 0;
4658-
if (!global_options_set.x_flag_rename_registers)
4659-
flag_rename_registers = 1;
4660-
if (!global_options_set.x_flag_cunroll_grow_size)
4661-
flag_cunroll_grow_size = 1;
4662-
}
4663-
else
4664-
if (!global_options_set.x_flag_cunroll_grow_size)
4665-
flag_cunroll_grow_size = flag_peel_loops || optimize >= 3;
4666-
46674681
/* If using typedef char *va_list, signal that
46684682
__builtin_va_start (&ap, 0) can be optimized to
46694683
ap = __builtin_next_arg (0). */
46704684
if (DEFAULT_ABI != ABI_V4)
46714685
targetm.expand_builtin_va_start = NULL;
46724686
}
46734687

4688+
rs6000_override_options_after_change ();
4689+
46744690
/* If not explicitly specified via option, decide whether to generate indexed
46754691
load/store instructions. A value of -1 indicates that the
46764692
initial value of this variable has not been overwritten. During

gcc/opts.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,11 +1142,21 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
11421142

11431143
/* Control IPA optimizations based on different -flive-patching level. */
11441144
if (opts->x_flag_live_patching)
1145-
{
1146-
control_options_for_live_patching (opts, opts_set,
1147-
opts->x_flag_live_patching,
1148-
loc);
1149-
}
1145+
control_options_for_live_patching (opts, opts_set,
1146+
opts->x_flag_live_patching,
1147+
loc);
1148+
1149+
/* Unrolling all loops implies that standard loop unrolling must also
1150+
be done. */
1151+
if (opts->x_flag_unroll_all_loops)
1152+
opts->x_flag_unroll_loops = 1;
1153+
1154+
/* Allow cunroll to grow size accordingly. */
1155+
if (!opts_set->x_flag_cunroll_grow_size)
1156+
opts->x_flag_cunroll_grow_size
1157+
= (opts->x_flag_unroll_loops
1158+
|| opts->x_flag_peel_loops
1159+
|| opts->x_optimize >= 3);
11501160
}
11511161

11521162
#define LEFT_COLUMN 27

gcc/toplev.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,16 +1474,6 @@ process_options (void)
14741474
flag_abi_version = 2;
14751475
}
14761476

1477-
/* Unrolling all loops implies that standard loop unrolling must also
1478-
be done. */
1479-
if (flag_unroll_all_loops)
1480-
flag_unroll_loops = 1;
1481-
1482-
/* Allow cunroll to grow size accordingly. */
1483-
if (flag_cunroll_grow_size == AUTODETECT_VALUE)
1484-
flag_cunroll_grow_size
1485-
= flag_unroll_loops || flag_peel_loops || optimize >= 3;
1486-
14871477
/* web and rename-registers help when run after loop unrolling. */
14881478
if (flag_web == AUTODETECT_VALUE)
14891479
flag_web = flag_unroll_loops;

0 commit comments

Comments
 (0)