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 "<built-in>" # 1 "<command-line>" # 1 "a.c" int artiBN2BX(int a, int b) { if (a<b) return a+b; return a*b; } this results in this machine code: > 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 muls r0, r1 .L1: bx lr .L5: adds r0, r0, r1 b .L1