[LLVMbugs] [Bug 712] NEW: (n * 3 % 3) is not known to be zero.
bugzilla-daemon at cs.uiuc.edu
bugzilla-daemon at cs.uiuc.edu
Mon Feb 27 14:34:22 PST 2006
http://llvm.cs.uiuc.edu/bugs/show_bug.cgi?id=712
Summary: (n * 3 % 3) is not known to be zero.
Product: tools
Version: 1.6
Platform: PC
OS/Version: Linux
Status: NEW
Severity: minor
Priority: P2
Component: llvm-gcc
AssignedTo: unassignedbugs at nondot.org
ReportedBy: nicholas at mxc.ca
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 ; <uint> [#uses=1]
%tmp.3 = mul uint %tmp.1, 3 ; <uint> [#uses=1]
%tmp.5 = rem uint %tmp.3, 3 ; <uint> [#uses=1]
%tmp.6 = cast uint %tmp.5 to int ; <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.
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
More information about the llvm-bugs
mailing list