https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122541
Bug ID: 122541
Summary: ARM: Superfluous BIC (bit-clear) generated before OR
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: profclonk at gmail dot com
Target Milestone: ---
Created attachment 62697
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62697&action=edit
Test case source
Compiling this code:
unsigned int test1 (unsigned int x) {
return (x & 0xFFFFFFFE) | 0x80000000;
}
for ARM Thumb (e.g. ARM Cortex-A8) generates a superfluous "BIC" instruction:
00000000 <test1>:
0: f020 4000 bic.w r0, r0, #2147483648 @ 0x80000000
4: f020 0001 bic.w r0, r0, #1
8: f040 4000 orr.w r0, r0, #2147483648 @ 0x80000000
c: 4770 bx lr
e: bf00 nop
The first "BIC" does nothing, as the bit is later set to 1 with "ORR".
Command line:
arm-linux-gnueabihf-gcc-13 -v test.c -O3 -save-temps -c -o test.o -Wall -Wextra
-mcpu=cortex-a8 -mthumb && arm-linux-gnueabihf-objdump -d test.o
COLLECT_GCC=arm-linux-gnueabihf-gcc-13
Target: arm-linux-gnueabihf
arm-linux-gnueabihf-gcc-13 (Debian 13.3.0-16) 13.3.0, cross compiling for ARM
from x86_64