public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/115353] New: Missed thumb2 table branch instruction optimisations
@ 2024-06-05  4:36 gus at projectgus dot com
  2024-06-05  4:37 ` [Bug target/115353] " gus at projectgus dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: gus at projectgus dot com @ 2024-06-05  4:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115353

            Bug ID: 115353
           Summary: Missed thumb2 table branch instruction optimisations
           Product: gcc
           Version: 14.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gus at projectgus dot com
  Target Milestone: ---

Created attachment 58351
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58351&action=edit
Minimal test case that previously generated tbb

After updating to gcc 14.1 we noticed that many jump tables were no longer
being optimised to use Thumb2 table branch instructions (tbb/tbh) compared to
13.2.

A bisect shows the problem seems to have been introduced by 7006e5d2d7 "arm:
Use deltas for Arm switch tables".

## Versions

The 14.1 build we were using was:

> Target: arm-none-eabi
> Configured with: /build/arm-none-eabi-gcc/src/gcc-14.1.0/configure --target=arm-none-eabi --prefix=/usr --with-sysroot=/usr/arm-none-eabi --with-native-system-header-dir=/include --libexecdir=/usr/lib --enable-languages=c,c++ --enable-plugins --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --disable-tls --with-gnu-as --with-gnu-ld --with-system-zlib --with-newlib --with-headers=/usr/arm-none-eabi/include --with-python-dir=share/gcc-arm-none-eabi --with-gmp --with-mpfr --with-mpc --with-isl --with-libelf --enable-gnu-indirect-function --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-pkgversion='Arch Repository' --with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/arm-none-eabi-gcc/-/issues --with-multilib-list=rmprofile
> gcc version 14.1.0 (Arch Repository) 

Local bisect builds are configured slightly differently:

> Target: arm-none-eabi
> Configured with: /home/gus/dev/gcc/configure --target=arm-none-eabi --prefix=/home/gus/ry/george/tmp/gcc-temp-7006e5d2 --with-sysroot=/home/gus/ry/george/tmp/gcc-temp-7006e5d2/arm-none-eabi --enable-languages=c --enable-plugins --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --disable-tls --with-gnu-as --with-gnu-ld --with-system-zlib --with-newlib --with-headers=/home/gus/ry/george/tmp/gcc-temp-7006e5d2/arm-none-eabi/include --with-python-dir=share/gcc-arm-none-eabi --with-gmp --with-mpfr --with-mpc --with-isl --with-libelf --enable-gnu-indirect-function --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-multilib-list=rmprofile
> gcc version 14.0.0 20231026 (experimental) (GCC) 

## Test case

Will attach two minimal test cases, one for tbb and one with slightly larger
jump table range for tbh.

Compiled with "arm-none-eabi-gcc -mcpu=cortex-m4 -Os -Wall -Wextra".

GCC release 13.2 and parent commit of 7006e5d2d7 both optimise to table branch
instructions, i.e.

> jump_around:
>        @ args = 0, pretend = 0, frame = 0
>        @ frame_needed = 0, uses_anonymous_args = 0
>        push    {r3, lr}
>        cmp     r0, #6
>        bhi     .L9
>        tbb     [pc, r0]
>.L4:
>        .byte   (.L10-.L4)/2
>        .byte   (.L11-.L4)/2
>        .byte   (.L8-.L4)/2
>        .byte   (.L7-.L4)/2
>        .byte   (.L6-.L4)/2
>        .byte   (.L5-.L4)/2
>        .byte   (.L3-.L4)/2
>        .p2align 1

gcc commit 7006e5d2d7, release 14.1, and recent master branch all generate PC
address loads, i.e.

>jump_around:
>	@ args = 0, pretend = 0, frame = 0
>	@ frame_needed = 0, uses_anonymous_args = 0
>	push	{r3, lr}
>	cmp	r0, #5
>	bhi	.L8
>	adr	r3, .L4
>	ldr	pc, [r3, r0, lsl #2]
>	.p2align 2
>.L4:
>	.word	.L9+1
>	.word	.L10+1
>	.word	.L7+1
>	.word	.L6+1
>	.word	.L5+1
>	.word	.L3+1
>	.p2align 1

For large jump tables the additional overhead of 2x or 4x code size per entry
adds up.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug target/115353] Missed thumb2 table branch instruction optimisations
  2024-06-05  4:36 [Bug target/115353] New: Missed thumb2 table branch instruction optimisations gus at projectgus dot com
@ 2024-06-05  4:37 ` gus at projectgus dot com
  2024-06-05 12:25 ` [Bug target/115353] [14/15 regression] Missed thumb2 table branch instruction optimisations since r14-4946-g7006e5d2d7b5b2 rearnsha at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: gus at projectgus dot com @ 2024-06-05  4:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115353

--- Comment #1 from Angus Gratton <gus at projectgus dot com> ---
Created attachment 58352
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58352&action=edit
Larger test case that previously generated tbh

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug target/115353] [14/15 regression] Missed thumb2 table branch instruction optimisations since r14-4946-g7006e5d2d7b5b2
  2024-06-05  4:36 [Bug target/115353] New: Missed thumb2 table branch instruction optimisations gus at projectgus dot com
  2024-06-05  4:37 ` [Bug target/115353] " gus at projectgus dot com
@ 2024-06-05 12:25 ` rearnsha at gcc dot gnu.org
  2024-06-06 11:49 ` ricbal02 at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rearnsha at gcc dot gnu.org @ 2024-06-05 12:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115353

Richard Earnshaw <rearnsha at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-06-05
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #2 from Richard Earnshaw <rearnsha at gcc dot gnu.org> ---
Confirmed.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug target/115353] [14/15 regression] Missed thumb2 table branch instruction optimisations since r14-4946-g7006e5d2d7b5b2
  2024-06-05  4:36 [Bug target/115353] New: Missed thumb2 table branch instruction optimisations gus at projectgus dot com
  2024-06-05  4:37 ` [Bug target/115353] " gus at projectgus dot com
  2024-06-05 12:25 ` [Bug target/115353] [14/15 regression] Missed thumb2 table branch instruction optimisations since r14-4946-g7006e5d2d7b5b2 rearnsha at gcc dot gnu.org
@ 2024-06-06 11:49 ` ricbal02 at gcc dot gnu.org
  2024-06-06 14:43 ` ricbal02 at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ricbal02 at gcc dot gnu.org @ 2024-06-06 11:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115353

Richard Ball <ricbal02 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug target/115353] [14/15 regression] Missed thumb2 table branch instruction optimisations since r14-4946-g7006e5d2d7b5b2
  2024-06-05  4:36 [Bug target/115353] New: Missed thumb2 table branch instruction optimisations gus at projectgus dot com
                   ` (2 preceding siblings ...)
  2024-06-06 11:49 ` ricbal02 at gcc dot gnu.org
@ 2024-06-06 14:43 ` ricbal02 at gcc dot gnu.org
  2024-06-06 15:11 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ricbal02 at gcc dot gnu.org @ 2024-06-06 14:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115353

--- Comment #3 from Richard Ball <ricbal02 at gcc dot gnu.org> ---
Patch in Upstream Review:
https://sourceware.org/pipermail/gcc-patches/2024-June/653820.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug target/115353] [14/15 regression] Missed thumb2 table branch instruction optimisations since r14-4946-g7006e5d2d7b5b2
  2024-06-05  4:36 [Bug target/115353] New: Missed thumb2 table branch instruction optimisations gus at projectgus dot com
                   ` (3 preceding siblings ...)
  2024-06-06 14:43 ` ricbal02 at gcc dot gnu.org
@ 2024-06-06 15:11 ` cvs-commit at gcc dot gnu.org
  2024-06-06 15:14 ` ricbal02 at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-06-06 15:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115353

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Ball <ricbal02@gcc.gnu.org>:

https://gcc.gnu.org/g:2963c76e8e24d4ebaf2b1b4ac4d7ca44eb0a9025

commit r15-1074-g2963c76e8e24d4ebaf2b1b4ac4d7ca44eb0a9025
Author: Richard Ball <richard.ball@arm.com>
Date:   Thu Jun 6 16:10:14 2024 +0100

    arm: Fix CASE_VECTOR_SHORTEN_MODE for thumb2.

    The CASE_VECTOR_SHORTEN_MODE query is missing some equals signs
    which causes suboptimal codegen due to missed optimisation
    opportunities. This patch also adds a test for thumb2
    switch statements as none exist currently.

    gcc/ChangeLog:
            PR target/115353
            * config/arm/arm.h (enum arm_auto_incmodes):
            Correct CASE_VECTOR_SHORTEN_MODE query.

    gcc/testsuite/ChangeLog:

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug target/115353] [14/15 regression] Missed thumb2 table branch instruction optimisations since r14-4946-g7006e5d2d7b5b2
  2024-06-05  4:36 [Bug target/115353] New: Missed thumb2 table branch instruction optimisations gus at projectgus dot com
                   ` (4 preceding siblings ...)
  2024-06-06 15:11 ` cvs-commit at gcc dot gnu.org
@ 2024-06-06 15:14 ` ricbal02 at gcc dot gnu.org
  2024-06-07 14:17 ` [Bug target/115353] [14 " cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ricbal02 at gcc dot gnu.org @ 2024-06-06 15:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115353

--- Comment #5 from Richard Ball <ricbal02 at gcc dot gnu.org> ---
Fixed on trunk so far

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug target/115353] [14 regression] Missed thumb2 table branch instruction optimisations since r14-4946-g7006e5d2d7b5b2
  2024-06-05  4:36 [Bug target/115353] New: Missed thumb2 table branch instruction optimisations gus at projectgus dot com
                   ` (5 preceding siblings ...)
  2024-06-06 15:14 ` ricbal02 at gcc dot gnu.org
@ 2024-06-07 14:17 ` cvs-commit at gcc dot gnu.org
  2024-06-07 14:18 ` ricbal02 at gcc dot gnu.org
  2024-06-07 16:08 ` rearnsha at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-06-07 14:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115353

--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-14 branch has been updated by Richard Ball
<ricbal02@gcc.gnu.org>:

https://gcc.gnu.org/g:ca1924947b5bed8105ae020bef6950bddda448f3

commit r14-10289-gca1924947b5bed8105ae020bef6950bddda448f3
Author: Richard Ball <richard.ball@arm.com>
Date:   Thu Jun 6 16:10:14 2024 +0100

    arm: Fix CASE_VECTOR_SHORTEN_MODE for thumb2.

    The CASE_VECTOR_SHORTEN_MODE query is missing some equals signs
    which causes suboptimal codegen due to missed optimisation
    opportunities. This patch also adds a test for thumb2
    switch statements as none exist currently.

    gcc/ChangeLog:
            PR target/115353
            * config/arm/arm.h (enum arm_auto_incmodes):
            Correct CASE_VECTOR_SHORTEN_MODE query.

    gcc/testsuite/ChangeLog:

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

    (cherry picked from commit 2963c76e8e24d4ebaf2b1b4ac4d7ca44eb0a9025)

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug target/115353] [14 regression] Missed thumb2 table branch instruction optimisations since r14-4946-g7006e5d2d7b5b2
  2024-06-05  4:36 [Bug target/115353] New: Missed thumb2 table branch instruction optimisations gus at projectgus dot com
                   ` (6 preceding siblings ...)
  2024-06-07 14:17 ` [Bug target/115353] [14 " cvs-commit at gcc dot gnu.org
@ 2024-06-07 14:18 ` ricbal02 at gcc dot gnu.org
  2024-06-07 16:08 ` rearnsha at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: ricbal02 at gcc dot gnu.org @ 2024-06-07 14:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115353

Richard Ball <ricbal02 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #7 from Richard Ball <ricbal02 at gcc dot gnu.org> ---
Fixed

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug target/115353] [14 regression] Missed thumb2 table branch instruction optimisations since r14-4946-g7006e5d2d7b5b2
  2024-06-05  4:36 [Bug target/115353] New: Missed thumb2 table branch instruction optimisations gus at projectgus dot com
                   ` (7 preceding siblings ...)
  2024-06-07 14:18 ` ricbal02 at gcc dot gnu.org
@ 2024-06-07 16:08 ` rearnsha at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: rearnsha at gcc dot gnu.org @ 2024-06-07 16:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115353

Richard Earnshaw <rearnsha at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |14.2

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-06-07 16:08 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-05  4:36 [Bug target/115353] New: Missed thumb2 table branch instruction optimisations gus at projectgus dot com
2024-06-05  4:37 ` [Bug target/115353] " gus at projectgus dot com
2024-06-05 12:25 ` [Bug target/115353] [14/15 regression] Missed thumb2 table branch instruction optimisations since r14-4946-g7006e5d2d7b5b2 rearnsha at gcc dot gnu.org
2024-06-06 11:49 ` ricbal02 at gcc dot gnu.org
2024-06-06 14:43 ` ricbal02 at gcc dot gnu.org
2024-06-06 15:11 ` cvs-commit at gcc dot gnu.org
2024-06-06 15:14 ` ricbal02 at gcc dot gnu.org
2024-06-07 14:17 ` [Bug target/115353] [14 " cvs-commit at gcc dot gnu.org
2024-06-07 14:18 ` ricbal02 at gcc dot gnu.org
2024-06-07 16:08 ` rearnsha at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).