From: | johnmce@world.std.com (John McEnerney) |
Newsgroups: | comp.compilers |
Date: | 29 Jan 1996 17:38:11 -0500 |
Organization: | Metrowerks, Inc. |
References: | 96-01-088 96-01-101 |
Keywords: | arithmetic, optimize |
hbaker@netcom.com (Henry G. Baker) writes:
> [do any compilers actually optimize a/b and a%b into a single operation
> if both appear?]
prener@watson.ibm.com (Dan Prener) wrote:
> IBM's xlc compiler does this, when compiling for the POWER (but not
> the PowerPC) architecture.
Metrowerks CodeWarrior for PowerPC will sort of do this:
int main(int a, int b) { return(a / b + a % b); }
00000000: 7CA323D6 divw r5,r3,r4
00000004: 7C0521D6 mullw r0,r5,r4
00000008: 7C001850 sub r0,r3,r0
0000000C: 7C650214 add r3,r5,r0
00000010: 4E800020 blr
The PowerPC does not compute a remainder result--thus the MULLW/SUB--but
the compiler manages to avoid doing the expensive DIVW twice. It's
actually just a side-effect of performing the CSE optimization at the
machine instruction level--the compiler generates DIVW twice but the
optimizer realizes that they compute the same result and optimizes one of
them away.
--
John McEnerney (mcenerney@metrowerks.com)
Metrowerks PowerPC Compiler Architect
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.