[Bug target/86011] Inefficient code generated for ldivmod with constant value
pinskia at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Dec 21 11:39:23 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86011
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Target Milestone|--- |11.0
Resolution|--- |FIXED
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed in GCC 11:
lsrs r1, r2, #30
push {r4, lr}
orr r1, r1, r3, lsl #2
bic lr, r1, #-1073741824
bic r1, r2, #-1073741824
add r1, r1, lr
asrs r4, r3, #31
add r3, r1, r3, lsr #28
and r1, r4, #137
add r3, r3, r1
movw r1, #57025
movt r1, 13617
bic r4, r4, #75
umull lr, r1, r1, r3
mov lr, #77
lsrs r1, r1, #4
mls r3, lr, r1, r3
movw r1, #14469
movt r1, 16171
add r3, r3, r4
str r3, [r0, #4]
subs r2, r2, r3
umull r2, r1, r2, r1
str r2, [r0]
pop {r4, pc}
For:
#define N 7723
struct foo { long a, b; };
struct foo test(long long x)
{
return (struct foo){x / N, x % N};
}
GCC 11+ Produces:
push {r4, lr}
mov r4, r0
mov r1, r3
mov r0, r2
movs r3, #0
movw r2, #7723
bl __aeabi_ldivmod
strd r0, r2, [r4]
mov r0, r4
pop {r4, pc}
Which is exactly what you want too.
More information about the Gcc-bugs
mailing list