Bug 17958 - expand_divmod fails to optimize division of 64-bit quantity by small constant when BITS_PER_WORD is 32
Summary: expand_divmod fails to optimize division of 64-bit quantity by small constant...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.0.0
: P2 enhancement
Target Milestone: ---
Assignee: Dinar Temirbulatov
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2004-10-12 22:48 UTC by Zack Weinberg
Modified: 2012-06-13 08:27 UTC (History)
2 users (show)

See Also:
Host:
Target: powerpc-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-07-02 21:30:35


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zack Weinberg 2004-10-12 22:48:17 UTC
expand_divmod cannot optimize code such as

long long div10(long long n) { return n / 10; }

when BITS_PER_WORD is 32.  A call to __divdi3 gets generated.  By contrast, when
BITS_PER_WORD is 64, this is optimized to a multiply and a shift.  I noticed
this problem on powerpc32, but it ought to affect any 32-bit target.
Comment 1 Andrew Pinski 2004-10-12 22:55:35 UTC
not all constants though (power of 2 are fine) for an example 16:
        mr r12,r3
        srawi r11,r3,31
        srawi r9,r11,31
        srawi r10,r11,31
        srwi r10,r9,28
        li r9,0
        addc r12,r10,r4
        adde r11,r9,r3
        srwi r4,r12,4
        insrwi r4,r11,4,0
        srawi r3,r11,4


Confirmed.