This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug optimization/14255] New: i386 backend should be teached how to use divl
- From: "bernie at develer dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 23 Feb 2004 08:08:10 -0000
- Subject: [Bug optimization/14255] New: i386 backend should be teached how to use divl
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
When dividing a 64bit integer by a 32bit integer,
GCC promotes everything to 64bits and generates
dumb code calling *both* __divdi3 and __moddi3.
A single divl instruction would have sufficed.
This missing optimization is the reason for
asm hacks such as linux/include/asm/div64.h.
This test case:
long long a;
long b, q, r;
void foo(void)
{
q = a / b;
r = a % b;
}
Gets compiled to:
foo:
pushl %ebp
movl b, %eax
movl %esp, %ebp
pushl %esi
movl %eax, %esi
pushl %ebx
sarl $31, %esi
pushl %esi
pushl %eax
pushl a+4
pushl a
movl %eax, %ebx
call __divdi3
addl $16, %esp
pushl %esi
pushl %ebx
pushl a+4
pushl a
movl %eax, q
call __moddi3
movl %eax, r
addl $16, %esp
leal -8(%ebp), %esp
popl %ebx
popl %esi
leave
ret
--
Summary: i386 backend should be teached how to use divl
Product: gcc
Version: 3.5.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P2
Component: optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: bernie at develer dot com
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14255