https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112573
Wilco <wilco at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2023-11-20 Ever confirmed|0 |1 CC| |wilco at gcc dot gnu.org Status|UNCONFIRMED |NEW --- Comment #3 from Wilco <wilco at gcc dot gnu.org> --- We should reassociate the immediate last for more optimal addressing like LLVM: adrp x8, a add x8, x8, :lo12:a lsr w9, w0, #8 add x8, x8, w1, sxtw strb w9, [x8, #1] lsr w9, w0, #16 strb w0, [x8, #3] strb w9, [x8, #2] lsr w9, w0, #24 strb w9, [x8] ret However GCC's reassociation is incorrect - it has been for many years and things got much worse in GCC12... As a result we may merge the immediate offset into the base address like in 'h'. Using -fdata-sections behaves like -fno-section-anchors, so it works as expected (and 'extern' is the same as well). We could block merging offsets to get more address CSEs if that ends up better overall.