https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104195
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Severity|normal |enhancement Status|UNCONFIRMED |NEW Last reconfirmed| |2022-01-23 --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Looks like this could be done at the rtl level (set (reg:SI 104 [ _3->data[_4] ]) (mem:SI (plus:DI (and:DI (mult:DI (reg/v:DI 98 [ i ]) (const_int 4 [0x4])) (const_int 12 [0xc])) (plus:DI (and:DI (mult:DI (reg/v:DI 98 [ i ]) (const_int 4 [0x4])) (const_int -16 [0xfffffffffffffff0])) (reg:DI 105))) [1 _3->data[_4]+0 S4 A32])) ((i*4)&0xc) + (((i*4)&~0xf) + r105) -> (((i*4)&0xc) + ((i*4)&~0xf)) + r105 -> (((i*4)&0xc) | ((i*4)&~0xf)) + r105 -> (i*4)&~0x4 + r105 -> i*4 + r105 GCC does optimize the address case though: struct CChunk { int data[4]; }; int *f(struct CChunk *p, __SIZE_TYPE__ i) { return &p[i/4].data[i%4]; }