On 28/09/2023 14:26, Richard Ball wrote:
For normal optimization for the Arm state in gcc we get an uncompressed
table of jump targets. This is in the middle of the text segment
far larger than necessary, especially at -Os.
This patch compresses the table to use deltas in a similar manner to
Thumb code generation.
Similar code is also used for -fpic where we currently generate a jump
to a jump. In this format the jumps are too dense for the hardware branch
predictor to handle accurately, so execution is likely to be very expensive.

Changes to switch statements for arm include a new function to handle the
assembly generation for different machine modes. This allows for more
optimisation to be performed in aout.h where arm has switched from using
ASM_OUTPUT_ADDR_VEC_ELT to using ASM_OUTPUT_ADDR_DIFF_ELT.
In ASM_OUTPUT_ADDR_DIFF_ELT new assembly generation options have been
added to utilise the different machine modes. Additional changes
made to the casesi expand and insn, CASE_VECTOR_PC_RELATIVE,
CASE_VECTOR_SHORTEN_MODE and LABEL_ALIGN_AFTER_BARRIER are all
to accomodate this new approach to switch statement generation.

New tests have been added and no regressions on arm-none-eabi.

gcc/ChangeLog:

        * config/arm/aout.h (ASM_OUTPUT_ADDR_DIFF_ELT): Add table output
        for different machine modes for arm.
        * config/arm/arm-protos.h (arm_output_casesi): New prototype.
        * config/arm/arm.h (CASE_VECTOR_PC_RELATIVE): Make arm use
        ASM_OUTPUT_ADDR_DIFF_ELT.
        (CASE_VECTOR_SHORTEN_MODE): Change table size calculation for
        TARGET_ARM.
        (LABEL_ALIGN_AFTER_BARRIER): Change to accommodate .p2align 2
        for TARGET_ARM.
        * config/arm/arm.cc (arm_output_casesi): New function.
        * config/arm/arm.md (arm_casesi_internal): Change casesi expand
        and insn.
        for arm to use new function arm_output_casesi.

gcc/testsuite/ChangeLog:

        * gcc.target/arm/arm-switchstatement.c: New test.

#define CASE_VECTOR_PC_RELATIVE ((TARGET_ARM || TARGET_THUMB2           \
                                  || (TARGET_THUMB1                     \
                                      && (optimize_size || flag_pic)))  \
                                 && (!target_pure_code))

A minor nit for future reference: (TARGET_ARM || TARGET_THUMB2) is normally written as TARGET_32BIT. No need to fix this as the next patch will rewrite this macro again anyway.

This is OK.

Reviewed-by: rearn...@arm.com

R.

Reply via email to