This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/17680] New: Gcc generates mull for a power of 2
- From: "terpstra at ito dot tu-darmstadt dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 26 Sep 2004 19:05:21 -0000
- Subject: [Bug c/17680] New: Gcc generates mull for a power of 2
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
unsigned long long foo(unsigned long x)
{ return (unsigned long long)x * 16777216; }
compiled with gcc -O -S -o beh.s -c beh.s generates:
pushl %ebp
movl %esp, %ebp
movl $16777216, %eax
mull 8(%ebp)
popl %ebp
ret
Interestingly, when the code is:
unsigned long long foo(unsigned long x) {
unsigned long long y = x;
return y * 16777216;
}
gcc generates:
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %eax
movl $0, %edx
shldl $24, %eax, %edx
sall $24, %eax
popl %ebp
ret
Normally, I would just use a temporary like above.
However, in the context where this missed optimization occured there was a method:
foo(unsigned long a, unsigned long b)
{
unsigned long long z = (unsigned long long)a * (unsigned long long)b;
...
}
This construction performs a single mul, whereas with the temporary approach it
does a full-scale 64bit multiplication. Really, I just want the best of both
worlds. ie: that I leave the code as above (and thus use only one mul), but when
the code foo(x, 16777216) appears, use shifts as expected.
--
Summary: Gcc generates mull for a power of 2
Product: gcc
Version: 3.4.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: terpstra at ito dot tu-darmstadt dot de
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17680