https://gcc.gnu.org/g:8a0eb13732d088f52b1d2e7694d385bf7b7c95ad
commit r17-4190-g8a0eb13732d088f52b1d2e7694d385bf7b7c95ad Author: Georg-Johann Lay <[email protected]> Date: Sat Sep 12 22:25:28 2026 +0200 AVR: Option-ize pass avr_pass_casesi. This patch adds a new command line option -mdemote-switch as a means to control the avr-casesi pass. The switch is on provided optimization is active, which matches the previous behavior of avr_pass_casesi::gate(). gcc/ * common/config/avr/avr-common.cc (avr_option_optimization_table) [OPT_LEVELS_1_PLUS]: Set -mdemote-switch. * config/avr/avr-passes.cc (avr_pass_casesi::gate): Require avropt_demote_switch to be on. * config/avr/avr.opt (mdemote-switch): New option. * config/avr/avr.opt.urls (mdemote-switch): Add UrlSuffix. * doc/invoke.texi (AVR Options): Document -mdemote-switch. Diff: --- gcc/common/config/avr/avr-common.cc | 1 + gcc/config/avr/avr-passes.cc | 2 +- gcc/config/avr/avr.opt | 4 ++++ gcc/config/avr/avr.opt.urls | 3 +++ gcc/doc/invoke.texi | 12 ++++++++++-- 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/gcc/common/config/avr/avr-common.cc b/gcc/common/config/avr/avr-common.cc index fb4f05553d71..875efde66814 100644 --- a/gcc/common/config/avr/avr-common.cc +++ b/gcc/common/config/avr/avr-common.cc @@ -42,6 +42,7 @@ static const struct default_options avr_option_optimization_table[] = { OPT_LEVELS_ALL, OPT_foptimize_crc, NULL, 0 }, { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_mgas_isr_prologues, NULL, 1 }, { OPT_LEVELS_1_PLUS, OPT_mmain_is_OS_task, NULL, 1 }, + { OPT_LEVELS_1_PLUS, OPT_mdemote_switch, NULL, 1 }, { OPT_LEVELS_1_PLUS, OPT_mfuse_add_, NULL, 1 }, { OPT_LEVELS_2_PLUS, OPT_mfuse_add_, NULL, 2 }, { OPT_LEVELS_1_PLUS, OPT_mfuse_ifelse, NULL, 1 }, diff --git a/gcc/config/avr/avr-passes.cc b/gcc/config/avr/avr-passes.cc index 42ddbb390647..d2b2d8421e08 100644 --- a/gcc/config/avr/avr-passes.cc +++ b/gcc/config/avr/avr-passes.cc @@ -3951,7 +3951,7 @@ public: bool gate (function *) final override { - return optimize > 0; + return optimize > 0 && avropt_demote_switch; } unsigned int execute (function *) final override; diff --git a/gcc/config/avr/avr.opt b/gcc/config/avr/avr.opt index 9c4be3ba93e5..625c6b2440d7 100644 --- a/gcc/config/avr/avr.opt +++ b/gcc/config/avr/avr.opt @@ -136,6 +136,10 @@ msp8 Target RejectNegative Var(avropt_sp8) Init(0) This option is used internally for multilib generation and selection. The device has no SPH special function register. +mdemote-switch +Target Var(avropt_demote_switch) Init(0) Optimization +Optimization. Demote switch values to the size as used in the program. + mfuse-add Target Alias(mfuse-add=, 2, 0) Optimization Optimization. Split register additions from load/store instructions. Most useful on Reduced Tiny. diff --git a/gcc/config/avr/avr.opt.urls b/gcc/config/avr/avr.opt.urls index 197c706fff3d..a04394894e78 100644 --- a/gcc/config/avr/avr.opt.urls +++ b/gcc/config/avr/avr.opt.urls @@ -75,6 +75,9 @@ UrlSuffix(gcc/AVR-Options.html#index-mrodata-in-ram) msp8 UrlSuffix(gcc/AVR-Options.html#index-msp8) +mdemote-switch +UrlSuffix(gcc/AVR-Options.html#index-mdemote-switch) + mfuse-add UrlSuffix(gcc/AVR-Options.html#index-mfuse-add) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index a74e99081d35..3311ff946198 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -985,8 +985,8 @@ Objective-C and Objective-C++ Dialects}. @emph{AVR Options} (@ref{AVR Options}) @gccoptlist{-mmcu=@var{mcu} -mabsdata -maccumulate-args -masm-len-notes --mcvt -mbranch-cost=@var{cost} -mfuse-add=@var{level} -mfuse-ifelse --mfuse-move=@var{level} -mfuse-move2 +-mbranch-cost=@var{cost} -mcvt -mdemote-switch -mfuse-add=@var{level} +-mfuse-ifelse -mfuse-move=@var{level} -mfuse-move2 -mcall-prologues -mgas-isr-prologues -mint8 -mflmap -mdouble=@var{bits} -mlong-double=@var{bits} -mno-call-main -mn_flash=@var{size} -mfract-convert-truncate -mno-interrupts @@ -24609,6 +24609,14 @@ integers. The default branch cost is 0. Functions prologues/epilogues are expanded as calls to appropriate subroutines. Code size is smaller. +@opindex mdemote-switch +@item -mdemote-switch +Without this option, the compiler will treat @code{switch} variables +as 32-bit values at least. When this option is on, an AVR-specific +pass will try to demote such @code{switch} variables to the widths +as actually used in the program. This option is on per default when +optimization is on. + @opindex mfuse-add @item -mfuse-add @itemx -mno-fuse-add
