[Bug target/111500] [arm-none-eabi-gcc] / suboptimal optimization

2023-09-24 Thread cptarse-luke at yahoo dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111500

--- Comment #3 from Luke  ---
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)

[Bug target/111500] [arm-none-eabi-gcc] / suboptimal optimization

2023-09-24 Thread cptarse-luke at yahoo dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111500

--- Comment #4 from Luke  ---
the a.i file for example #1a is:
# 1 "a.c"
# 1 "/tmp//"
# 1 ""
# 1 ""
# 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...

[Bug target/111580] New: [arm-none-eabi-gcc] / suboptimal optimization / b.n to bx lr

2023-09-24 Thread cptarse-luke at yahoo dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111580

Bug ID: 111580
   Summary: [arm-none-eabi-gcc] / suboptimal optimization / b.n to
bx lr
   Product: gcc
   Version: 9.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: target
  Assignee: unassigned at gcc dot gnu.org
  Reporter: cptarse-luke at yahoo dot com
  Target Milestone: ---

it seems like, i should have filed this separately:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111500

i feel like gcc should output a "bx lr" instead of a jump ("b .L1") to a "bx
lr"...

the file "a.i" is:
# 1 "a.c"
# 1 "/tmp//"
# 1 ""
# 1 ""
# 1 "a.c"
int artiBN2BX(int a, int b) {
 if (a 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)
> 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
> cat a.s
artiBN2BX:
cmp r0, r1
blt .L5
mulsr0, r1
.L1:bx  lr
.L5:addsr0, r0, r1
b   .L1

[Bug target/111581] New: [arm-none-eabi-gcc] / suboptimal optimization /

2023-09-24 Thread cptarse-luke at yahoo dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111581

Bug ID: 111581
   Summary: [arm-none-eabi-gcc] / suboptimal optimization /
   Product: gcc
   Version: 9.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: target
  Assignee: unassigned at gcc dot gnu.org
  Reporter: cptarse-luke at yahoo dot com
  Target Milestone: ---

it seems like, i should have filed this separately:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111500

i think the uxth/sxth is superfluous here,
since nobody ever looks at the high half word...

> 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) 
> 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
> cat a.i
# 1 "a.c"
# 1 "/tmp//"
# 1 ""
# 1 ""
# 1 "a.c"
void artiSXTH(volatile short * a) {
 short b = *a;
 *a = b;
}
> cat a.s
artiSXTH:
ldrhr3, [r0]
sxthr3, r3
strhr3, [r0]
bx  lr

[Bug target/111582] New: [arm-none-eabi-gcc] / suboptimal optimization / bitfield / superfluous stack write

2023-09-24 Thread cptarse-luke at yahoo dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111582

Bug ID: 111582
   Summary: [arm-none-eabi-gcc] / suboptimal optimization /
bitfield / superfluous stack write
   Product: gcc
   Version: 9.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: target
  Assignee: unassigned at gcc dot gnu.org
  Reporter: cptarse-luke at yahoo dot com
  Target Milestone: ---

When I try to use a struct with a bitfield,
then it happens, that GCC writes to the stack without ever reading it:

> 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)
# 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
> cat a.i
# 1 "a.c"
# 1 "/tmp//"
# 1 ""
# 1 ""
# 1 "a.c"

typedef unsigned char u8;
typedef unsigned int u32;
extern int fatal();
__attribute__((always_inline)) inline u32 lsb(const u8 l) { return (1U<> (i*8);
 if (R.rs || msk==~R.msk) return (((volatile u8*)R.a)[i] = v) << (i*8);
 else if (R.v==~R.msk) return (((volatile u8*)R.a)[i] |= v) << (i*8);
 return (((volatile u8*)R.a)[i] = (((volatile u8*)R.a)[i] &
(R.msk>>(i*8))) | v) << (i*8);
  }
 return 0;
}
__attribute__((always_inline)) inline Reg GU(Reg R, u32 A, u32 N, u8 o, u8 w,
u32 v) {
   const u32 msk=~(lsb(w)< cat a.s
artiSP:
sub sp, sp, #16
mov r2, sp
movsr3, #2
strbr3, [r2, #12]
...
add sp, sp, #16
bx  lr

I compile it on a
Intel(R) Pentium(R) Silver J5040 CPU @ 2.00GHz
running Void Linux (kernel: 6.3.13_1)
for a STM32G030.

[Bug target/111581] [arm-none-eabi-gcc] / suboptimal optimization / uxth/sxth

2023-09-24 Thread cptarse-luke at yahoo dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111581

--- Comment #1 from Luke  ---
in the unsigned case:
furthermore the ldrh already cleared the high half-word,
so that a uxth would be superfluous,
even if there would be a subsequent str...

[Bug target/111581] [arm-none-eabi-gcc] / suboptimal optimization / uxth/sxth

2023-09-25 Thread cptarse-luke at yahoo dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111581

Luke  changed:

   What|Removed |Added

 Status|WAITING |RESOLVED
 Resolution|--- |DUPLICATE

--- Comment #3 from Luke  ---
nope... i didn't know bug 60749... and it does not happen, when i omit the
"volatile"...

*** This bug has been marked as a duplicate of bug 60749 ***

[Bug rtl-optimization/60749] combine is overly cautious when operating on volatile memory references

2023-09-25 Thread cptarse-luke at yahoo dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60749

Luke  changed:

   What|Removed |Added

 CC||cptarse-luke at yahoo dot com

--- Comment #3 from Luke  ---
*** Bug 111581 has been marked as a duplicate of this bug. ***

[Bug target/111500] [arm-none-eabi-gcc] / suboptimal optimization / subs followed by cmp (et alii)

2023-09-25 Thread cptarse-luke at yahoo dot com via 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

[Bug target/111500] [arm-none-eabi-gcc] / suboptimal optimization / subs followed by cmp (et alii)

2023-09-25 Thread cptarse-luke at yahoo dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111500

--- Comment #7 from Luke  ---
(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...

[Bug target/111500] [arm-none-eabi-gcc] / suboptimal optimization / subs followed by cmp (et alii)

2023-09-25 Thread cptarse-luke at yahoo dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111500

Luke  changed:

   What|Removed |Added

 Status|WAITING |RESOLVED
 Resolution|--- |DUPLICATE

--- Comment #8 from Luke  ---


*** This bug has been marked as a duplicate of bug 104773 ***

[Bug rtl-optimization/104773] compare with 1 not merged with subtract 1

2023-09-25 Thread cptarse-luke at yahoo dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104773

Luke  changed:

   What|Removed |Added

 CC||cptarse-luke at yahoo dot com

--- Comment #3 from Luke  ---
*** Bug 111500 has been marked as a duplicate of this bug. ***