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 target/47920] strange code generated for expression (a+7)/8


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47920

--- Comment #3 from Carrot <carrot at google dot com> 2011-03-01 06:44:47 UTC ---
(In reply to comment #1)
> Presumably because arithmetic right-shift by 3 isn't the same as a division by
> 8 when (a+7) is negative.  Changing the types to unsigned gives the code you
> want.

You are right. Right shift and division are different for negative numbers.

Thumb1 uses a different code sequence since it doesn't support conditional
execution

t08:
    add    r0, r0, #7
    asr    r3, r0, #31
    lsr    r3, r3, #29
    add    r0, r3, r0
    asr    r0, r0, #3
    bx    lr

If we use the similar code sequence in thumb2 we can reduce one instruction
because the logical shift and the following add can be merged into one
instruction

t08:
    add    r0, r0, #7
    asr    r3, r0, #31
    add    r0, r0, r3, LSR #29
    asr    r0, r0, #3
    bx    lr

I wonder if this will be faster.


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