-
Notifications
You must be signed in to change notification settings - Fork 15k
Closed
Labels
Description
Bugzilla Link | 712 |
Resolution | FIXED |
Resolved on | Mar 06, 2010 14:00 |
Version | 1.0 |
OS | All |
Extended Description
There is a missed optimization opportunity in the following code:
int case1(unsigned char c)
{
unsigned long x = c * 3;
return x % 3;
}
Of course, the modulo operation is a form of division, so it should be combined
with the multiply and realize that the result must be zero. The resulting ll is:
int %case1(ubyte %argc) {
entry:
%tmp.1 = cast ubyte %argc to uint ; [#uses=1]
%tmp.3 = mul uint %tmp.1, 3 ; [#uses=1]
%tmp.5 = rem uint %tmp.3, 3 ; [#uses=1]
%tmp.6 = cast uint %tmp.5 to int ; [#uses=1]
ret int %tmp.6
}
I expected the following output:
int %case1(ubyte %c) {
entry:
ret int 0
}
Note that it works properly where you replace "3" with a power of two.