On Thu, Oct 17, 2024 at 2:51 AM Andi Kleen <[email protected]> wrote:
>
> From: Andi Kleen <[email protected]>
Instead of initializing with -1 can you Init(0) and add OPT_fjump_tables
and OPT_fbit_tests to the default_options_table table in opts.cc,
under OPT_LEVELS_1_PLUS_NOT_DEBUG I'd guess.
Thanks,
Richard.
> gcc/ChangeLog:
>
> * common.opt: Enable -fbit-tests and -fjump-tables only at -O1.
> * tree-switch-conversion.h (jump_table_cluster::is_enabled):
> Dito.
> ---
> gcc/common.opt | 4 ++--
> gcc/tree-switch-conversion.h | 5 +++--
> 2 files changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/gcc/common.opt b/gcc/common.opt
> index 12b25ff486de..4af7a94fea42 100644
> --- a/gcc/common.opt
> +++ b/gcc/common.opt
> @@ -2189,11 +2189,11 @@ Common Var(flag_ivopts) Init(1) Optimization
> Optimize induction variables on trees.
>
> fjump-tables
> -Common Var(flag_jump_tables) Init(1) Optimization
> +Common Var(flag_jump_tables) Init(-1) Optimization
> Use jump tables for sufficiently large switch statements.
>
> fbit-tests
> -Common Var(flag_bit_tests) Init(1) Optimization
> +Common Var(flag_bit_tests) Init(-1) Optimization
> Use bit tests for sufficiently large switch statements.
>
> fkeep-inline-functions
> diff --git a/gcc/tree-switch-conversion.h b/gcc/tree-switch-conversion.h
> index 6468995eb316..fbfd7ff7b3ff 100644
> --- a/gcc/tree-switch-conversion.h
> +++ b/gcc/tree-switch-conversion.h
> @@ -442,7 +442,7 @@ public:
> /* Return whether bit test expansion is allowed. */
> static inline bool is_enabled (void)
> {
> - return flag_bit_tests;
> + return flag_bit_tests >= 0 ? flag_bit_tests : (optimize >= 1);
> }
>
> /* True when the jump table handles an entire switch statement. */
> @@ -524,7 +524,8 @@ bool jump_table_cluster::is_enabled (void)
> over-ruled us, we really have no choice. */
> if (!targetm.have_casesi () && !targetm.have_tablejump ())
> return false;
> - if (!flag_jump_tables)
> + int flag = flag_jump_tables >= 0 ? flag_jump_tables : (optimize >= 1);
> + if (!flag)
> return false;
> #ifndef ASM_OUTPUT_ADDR_DIFF_ELT
> if (flag_pic)
> --
> 2.46.2
>