public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/111500] New: [arm-none-eabi-gcc] / suboptimal optimization
@ 2023-09-20 14:55 gnu.arne at wgboome dot org
2023-09-20 16:16 ` [Bug target/111500] " pinskia at gcc dot gnu.org
` (10 more replies)
0 siblings, 11 replies; 12+ messages in thread
From: gnu.arne at wgboome dot org @ 2023-09-20 14:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111500
Bug ID: 111500
Summary: [arm-none-eabi-gcc] / suboptimal optimization
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: gnu.arne at wgboome dot org
Target Milestone: ---
Hi!
For my STM32G030K6T I need thumb2 machine code.
arm-none-eabi-gcc can convert my C code quite nicely.
When I inspected the resulting disassembled machine code, I found some funny
artifacts.
Is it worth making&sending minimal source code and/or that corresponding
"preprocessed file *.i*"?
I mean: Is somebody able/willing to do something about it?
Here are the 4 artifacts (when using "-O3 -g"):
1.
a "subs r2, #1" instruction is followed by a "cmp r2, #0 / bne.n" instruction,
although the "subs" already leaves the zero flag properly, doesn't it?
2.
a "b.n" instruction jumps to a "bx lr" instruction, although both have the same
length... i mean: instead of "b.n" it could have written "bx lr"...
3.
a "uxth r2, r2" is followed by a "strh r2, [r3]", although "strh" doesn't look
at the high half-word of r2, does it?
4.
when i use single bits in a struct (e. g.: "struct A { int a:1; int b:7; }"),
gcc reserves 16 bytes on the stack and sometimes writes into this area, without
ever reading from there... when i do it myself with "struct A { int ab; }" and
"if (S.ab&128)..." and "if (S.ab&127)..." then it doesnt touch the stack...
Thx.
Bye.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/111500] [arm-none-eabi-gcc] / suboptimal optimization
2023-09-20 14:55 [Bug c/111500] New: [arm-none-eabi-gcc] / suboptimal optimization gnu.arne at wgboome dot org
@ 2023-09-20 16:16 ` pinskia at gcc dot gnu.org
2023-09-20 19:14 ` gnu.arne at wgboome dot org
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-20 16:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111500
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|c |target
Status|UNCONFIRMED |WAITING
Ever confirmed|0 |1
Keywords| |missed-optimization
Target| |arm
Last reconfirmed| |2023-09-20
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Can you attach (compilible) examples code for each issue? Really these should
be filed seperately too.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/111500] [arm-none-eabi-gcc] / suboptimal optimization
2023-09-20 14:55 [Bug c/111500] New: [arm-none-eabi-gcc] / suboptimal optimization gnu.arne at wgboome dot org
2023-09-20 16:16 ` [Bug target/111500] " pinskia at gcc dot gnu.org
@ 2023-09-20 19:14 ` gnu.arne at wgboome dot org
2023-09-25 4:46 ` cptarse-luke at yahoo dot com
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: gnu.arne at wgboome dot org @ 2023-09-20 19:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111500
--- Comment #2 from Luke <gnu.arne at wgboome dot org> ---
(In reply to Andrew Pinski from comment #1)
> Can you attach (compilible) examples code for each issue? Really these
> should be filed seperately too.
do u mean, i should file 3 further bug reports?
i try examples for artifact #1 first...
is it right like this?
example code for artifact #1a:
// "cmp" follows the "subs" immediately
__attribute((noinline)) void artiSUBS() {
for (int i=100; i>0; i--)
200017ec: 2364 movs r3, #100 ; 0x64
*(volatile int*)0xE000E014 = i;
200017ee: 4a03 ldr r2, [pc, #12] ; (200017fc)
200017f0: 6013 str r3, [r2, #0]
for (int i=100; i>0; i--)
200017f2: 3b01 subs r3, #1
200017f4: 2b00 cmp r3, #0
200017f6: d1fb bne.n 200017f0
}
200017f8: 4770 bx lr
200017fa: 46c0 nop
200017fc: e000e014
example code for artifact #1b:
// gcc tends to do the "i--" too early; "ldr" does not touch flags
// maybe because it hopes to get beneficial pipeline effects at loop entry?
__attribute((noinline)) void artiSUBS() {
200017ec: 2364 movs r3, #100 ; 0x64
for (int i=100; i>0; i--)
(void) *(volatile int*)0xE000E014;
200017ee: 4a03 ldr r2, [pc, #12] ; (200017fc)
200017f0: 3b01 subs r3, #1
200017f2: 6811 ldr r1, [r2, #0]
for (int i=100; i>0; i--)
200017f4: 2b00 cmp r3, #0
200017f6: d1fb bne.n 200017f0
}
200017f8: 4770 bx lr
200017fa: 46c0 nop
200017fc: e000e014
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/111500] [arm-none-eabi-gcc] / suboptimal optimization
2023-09-20 14:55 [Bug c/111500] New: [arm-none-eabi-gcc] / suboptimal optimization gnu.arne at wgboome dot org
2023-09-20 16:16 ` [Bug target/111500] " pinskia at gcc dot gnu.org
2023-09-20 19:14 ` gnu.arne at wgboome dot org
@ 2023-09-25 4:46 ` cptarse-luke at yahoo dot com
2023-09-25 4:52 ` cptarse-luke at yahoo dot com
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: cptarse-luke at yahoo dot com @ 2023-09-25 4:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111500
--- Comment #3 from Luke <cptarse-luke at yahoo dot com> ---
maybe i should also say the "-v" output?
> arm-none-eabi-gcc -v
Using built-in specs.
COLLECT_GCC=arm-none-eabi-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-none-eabi/9.3.0/lto-wrapper
Target: arm-none-eabi
Configured with: ../configure --disable-decimal-float --disable-libffi
--disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp
--disable-libstdcxx-pch --disable-libstdc__-v3 --disable-nls --disable-shared
--disable-threads --disable-tls --disable-werror --enable-__cxa_atexit
--enable-c99 --enable-gnu-indirect-function --enable-interwork
--enable-languages=c,c++ --enable-long-long --enable-multilib --enable-plugins
--host= --libdir=/usr/lib --libexecdir=/usr/lib --prefix=/usr
--target=arm-none-eabi --with-gmp --with-gnu-as --with-gnu-ld
--with-headers=/usr/arm-none-eabi/include --with-host-libstdcxx='-static-libgcc
-Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-isl --with-libelf --with-mpc
--with-mpfr --with-multilib-list=rmprofile
--with-native-system-header-dir=/include --with-newlib
--with-python-dir=share/gcc-arm-none-eabi --with-sysroot=/usr/arm-none-eabi
--with-system-zlib
Thread model: single
gcc version 9.3.0 (GCC)
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/111500] [arm-none-eabi-gcc] / suboptimal optimization
2023-09-20 14:55 [Bug c/111500] New: [arm-none-eabi-gcc] / suboptimal optimization gnu.arne at wgboome dot org
` (2 preceding siblings ...)
2023-09-25 4:46 ` cptarse-luke at yahoo dot com
@ 2023-09-25 4:52 ` cptarse-luke at yahoo dot com
2023-09-25 6:43 ` [Bug target/111500] [arm-none-eabi-gcc] / suboptimal optimization / subs followed by cmp (et alii) pinskia at gcc dot gnu.org
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: cptarse-luke at yahoo dot com @ 2023-09-25 4:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111500
--- Comment #4 from Luke <cptarse-luke at yahoo dot com> ---
the a.i file for example #1a is:
# 1 "a.c"
# 1 "/tmp//"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "a.c"
void artiSUBS() {
for (int i=100; i>0; i--)
*(volatile int*)0xE000E014 = i;
}
the command-line was:
> arm-none-eabi-gcc -save-temps -S a.c -O3 -g -mcpu=cortex-m0plus -mthumb -Wall --specs=nosys.specs -nostdlib -fdata-sections -ffunction-sections -ffreestanding -Winline
and the resulting a.s file contains that subs/cmp sequence...
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/111500] [arm-none-eabi-gcc] / suboptimal optimization / subs followed by cmp (et alii)
2023-09-20 14:55 [Bug c/111500] New: [arm-none-eabi-gcc] / suboptimal optimization gnu.arne at wgboome dot org
` (3 preceding siblings ...)
2023-09-25 4:52 ` cptarse-luke at yahoo dot com
@ 2023-09-25 6:43 ` pinskia at gcc dot gnu.org
2023-09-25 6:48 ` pinskia at gcc dot gnu.org
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-25 6:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111500
Bug 111500 depends on bug 111580, which changed state.
Bug 111580 Summary: [arm-none-eabi-gcc] / suboptimal optimization / b.n to bx lr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111580
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |DUPLICATE
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/111500] [arm-none-eabi-gcc] / suboptimal optimization / subs followed by cmp (et alii)
2023-09-20 14:55 [Bug c/111500] New: [arm-none-eabi-gcc] / suboptimal optimization gnu.arne at wgboome dot org
` (4 preceding siblings ...)
2023-09-25 6:43 ` [Bug target/111500] [arm-none-eabi-gcc] / suboptimal optimization / subs followed by cmp (et alii) pinskia at gcc dot gnu.org
@ 2023-09-25 6:48 ` pinskia at gcc dot gnu.org
2023-09-25 6:52 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-25 6:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111500
Bug 111500 depends on bug 111582, which changed state.
Bug 111582 Summary: [arm-none-eabi-gcc] / suboptimal optimization / bitfield / superfluous stack write
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111582
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |FIXED
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/111500] [arm-none-eabi-gcc] / suboptimal optimization / subs followed by cmp (et alii)
2023-09-20 14:55 [Bug c/111500] New: [arm-none-eabi-gcc] / suboptimal optimization gnu.arne at wgboome dot org
` (5 preceding siblings ...)
2023-09-25 6:48 ` pinskia at gcc dot gnu.org
@ 2023-09-25 6:52 ` pinskia at gcc dot gnu.org
2023-09-25 6:53 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-25 6:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111500
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Luke from comment #4)
> the a.i file for example #1a is:
> # 1 "a.c"
> # 1 "/tmp//"
> # 1 "<built-in>"
> # 1 "<command-line>"
> # 1 "a.c"
> void artiSUBS() {
> for (int i=100; i>0; i--)
> *(volatile int*)0xE000E014 = i;
> }
>
> the command-line was:
> > arm-none-eabi-gcc -save-temps -S a.c -O3 -g -mcpu=cortex-m0plus -mthumb -Wall --specs=nosys.specs -nostdlib -fdata-sections -ffunction-sections -ffreestanding -Winline
>
> and the resulting a.s file contains that subs/cmp sequence...
This is most likely a dup of bug 104773.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/111500] [arm-none-eabi-gcc] / suboptimal optimization / subs followed by cmp (et alii)
2023-09-20 14:55 [Bug c/111500] New: [arm-none-eabi-gcc] / suboptimal optimization gnu.arne at wgboome dot org
` (6 preceding siblings ...)
2023-09-25 6:52 ` pinskia at gcc dot gnu.org
@ 2023-09-25 6:53 ` pinskia at gcc dot gnu.org
2023-09-25 7:09 ` cptarse-luke at yahoo dot com
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-25 6:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111500
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #5)
> This is most likely a dup of bug 104773.
Or of bug 3507.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/111500] [arm-none-eabi-gcc] / suboptimal optimization / subs followed by cmp (et alii)
2023-09-20 14:55 [Bug c/111500] New: [arm-none-eabi-gcc] / suboptimal optimization gnu.arne at wgboome dot org
` (7 preceding siblings ...)
2023-09-25 6:53 ` pinskia at gcc dot gnu.org
@ 2023-09-25 7:09 ` cptarse-luke at yahoo dot com
2023-09-25 7:28 ` cptarse-luke at yahoo dot com
2023-09-25 10:45 ` cptarse-luke at yahoo dot com
10 siblings, 0 replies; 12+ messages in thread
From: cptarse-luke at yahoo dot com @ 2023-09-25 7:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111500
Bug 111500 depends on bug 111581, which changed state.
Bug 111581 Summary: [arm-none-eabi-gcc] / suboptimal optimization / uxth/sxth
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111581
What |Removed |Added
----------------------------------------------------------------------------
Status|WAITING |RESOLVED
Resolution|--- |DUPLICATE
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/111500] [arm-none-eabi-gcc] / suboptimal optimization / subs followed by cmp (et alii)
2023-09-20 14:55 [Bug c/111500] New: [arm-none-eabi-gcc] / suboptimal optimization gnu.arne at wgboome dot org
` (8 preceding siblings ...)
2023-09-25 7:09 ` cptarse-luke at yahoo dot com
@ 2023-09-25 7:28 ` cptarse-luke at yahoo dot com
2023-09-25 10:45 ` cptarse-luke at yahoo dot com
10 siblings, 0 replies; 12+ messages in thread
From: cptarse-luke at yahoo dot com @ 2023-09-25 7:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111500
--- Comment #7 from Luke <cptarse-luke at yahoo dot com> ---
(In reply to Andrew Pinski from comment #6)
> (In reply to Andrew Pinski from comment #5)
> > This is most likely a dup of bug 104773.
>
> Or of bug 3507.
i concur...
but i do not know which one to choose...
they both look the same to me... somehow...
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/111500] [arm-none-eabi-gcc] / suboptimal optimization / subs followed by cmp (et alii)
2023-09-20 14:55 [Bug c/111500] New: [arm-none-eabi-gcc] / suboptimal optimization gnu.arne at wgboome dot org
` (9 preceding siblings ...)
2023-09-25 7:28 ` cptarse-luke at yahoo dot com
@ 2023-09-25 10:45 ` cptarse-luke at yahoo dot com
10 siblings, 0 replies; 12+ messages in thread
From: cptarse-luke at yahoo dot com @ 2023-09-25 10:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111500
Luke <cptarse-luke at yahoo dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|WAITING |RESOLVED
Resolution|--- |DUPLICATE
--- Comment #8 from Luke <cptarse-luke at yahoo dot com> ---
*** This bug has been marked as a duplicate of bug 104773 ***
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2023-09-25 10:45 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-20 14:55 [Bug c/111500] New: [arm-none-eabi-gcc] / suboptimal optimization gnu.arne at wgboome dot org
2023-09-20 16:16 ` [Bug target/111500] " pinskia at gcc dot gnu.org
2023-09-20 19:14 ` gnu.arne at wgboome dot org
2023-09-25 4:46 ` cptarse-luke at yahoo dot com
2023-09-25 4:52 ` cptarse-luke at yahoo dot com
2023-09-25 6:43 ` [Bug target/111500] [arm-none-eabi-gcc] / suboptimal optimization / subs followed by cmp (et alii) pinskia at gcc dot gnu.org
2023-09-25 6:48 ` pinskia at gcc dot gnu.org
2023-09-25 6:52 ` pinskia at gcc dot gnu.org
2023-09-25 6:53 ` pinskia at gcc dot gnu.org
2023-09-25 7:09 ` cptarse-luke at yahoo dot com
2023-09-25 7:28 ` cptarse-luke at yahoo dot com
2023-09-25 10:45 ` cptarse-luke at yahoo dot com
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).