https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91869
Bug ID: 91869 Summary: Constant bitfield assignment causes unnecessary use of memory and instructions Product: gcc Version: 9.2.1 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: pdj at knaldgas dot dk Target Milestone: --- Host: x86_64 Target: x86_64 Build: x86_64 Created attachment 46914 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46914&action=edit MWE in C, compile with gcc -O2 Assigning constant bitfields to variables cause unnecessary use of memory, instructions and time. Having a byte consisting of multiple bitfields, setting more than one bitfield causes gcc to place the constant in .rodata instead of immediate loading. When all fields are zero, or setting only one of the bitfields, immediate loading is used as expected. On microcontrollers with limited memory this is a problem. Bitfields (representation clauses) in Ada are well-defined, but I've written the MWE in C as C's bitfields exhibit the same (mis-)behaviour. The attached code should be generated with: $ gcc -O2 main.c -o main $ objdump -h -S main > main.lss Tried with Targets being x86_64 (9.2.1), arm-linux-gnueabihf (9.2.1) and avr (9.2.0), same result.