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

            Bug ID: 127700
           Summary: 32-bit constant loaded twice
           Product: gcc
           Version: 16.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kuratius at googlemail dot com
  Target Milestone: ---

Created attachment 65741
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65741&action=edit
Sample code for producing the unoptimized assembly with arm-none-eabi-gcc -Os
-mcpu=arm946e-s -marm -S expbug.c

https://godbolt.org/z/vaK4TGnMv
First, it shouldn't reload the constant, and second it probably shouldn't
choose to use 4 separate imm adds instead of an ldr+add pair. imms might make
sense if the value is 16 or 24 bit, or if the value wasn't already in a
register.
Casting the table into a volatile pointer before accessing it fixes this, but
it's probably not ideal.
I tried going back a few versions, and I think this issue has probably existed
for a decade or so, GCC 9 also has a similar problem.

You can try compiling the sample code attached here with 
arm-none-eabi-gcc -Os -mcpu=arm946e-s -marm -S expbug.c to see the assembly
output.
-O2 and -O3 have the same issue.
  • [Bug target/127700] New: 32-bi... kuratius at googlemail dot com via Gcc-bugs

Reply via email to