This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/47920] strange code generated for expression (a+7)/8
- From: "carrot at google dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 1 Mar 2011 06:44:49 +0000
- Subject: [Bug target/47920] strange code generated for expression (a+7)/8
- Auto-submitted: auto-generated
- References: <bug-47920-4@http.gcc.gnu.org/bugzilla/>
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.