http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47777
Summary: use __aeabi_idivmod to compute quotient and remainder at the same time Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: target AssignedTo: unassig...@gcc.gnu.org ReportedBy: car...@google.com Target: arm-eabi Compile the following source code with options -march=armv7-a -O2 int t06(int x, int y) { int a = x / y; int b = x % y; return a+b; } GCC 4.6 generates: t06: @ args = 0, pretend = 0, frame = 0 @ frame_needed = 0, uses_anonymous_args = 0 stmfd sp!, {r4, r5, r6, lr} mov r6, r0 mov r5, r1 bl __aeabi_idiv mov r1, r5 mov r4, r0 mov r0, r6 bl __aeabi_idivmod add r0, r4, r1 ldmfd sp!, {r4, r5, r6, pc} It calls function __aeabi_idiv to compute quotient and calls __aeabi_idivmod to compute remainder. Actually __aeabi_idivmod can compute quotient and remainder at the same time. By taking advantage of this we can simplify the code to push {r4, lr} bl __aeabi_idivmod add r0, r0, r1 pop {r4, pc}