This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug optimization/14255] New: i386 backend should be teached how to use divl


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]