public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/47920] New: strange code generated for expression (a+7)/8
@ 2011-02-28 9:31 carrot at google dot com
2011-02-28 10:48 ` [Bug target/47920] " mikpe at it dot uu.se
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: carrot at google dot com @ 2011-02-28 9:31 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47920
Summary: strange code generated for expression (a+7)/8
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: carrot@google.com
Target: arm-linux-androideabi
Compile the following code with options -mthumb -march=armv7-a -O2
int t08(int a)
{
return (a+7)/8;
}
GCC 4.6 generates
t08:
add r3, r0, #14
adds r0, r0, #7
it mi
movmi r0, r3
asrs r0, r0, #3
bx lr
Why not simply generate
adds r0, r0, #7
asrs r0, r0, #3
bx lr
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/47920] strange code generated for expression (a+7)/8
2011-02-28 9:31 [Bug target/47920] New: strange code generated for expression (a+7)/8 carrot at google dot com
@ 2011-02-28 10:48 ` mikpe at it dot uu.se
2011-02-28 10:51 ` jakub at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: mikpe at it dot uu.se @ 2011-02-28 10:48 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47920
--- Comment #1 from Mikael Pettersson <mikpe at it dot uu.se> 2011-02-28 09:56:36 UTC ---
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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/47920] strange code generated for expression (a+7)/8
2011-02-28 9:31 [Bug target/47920] New: strange code generated for expression (a+7)/8 carrot at google dot com
2011-02-28 10:48 ` [Bug target/47920] " mikpe at it dot uu.se
@ 2011-02-28 10:51 ` jakub at gcc dot gnu.org
2011-03-01 6:44 ` carrot at google dot com
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-02-28 10:51 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47920
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-02-28 10:09:25 UTC ---
Yeah, exactly. Try for say a = -20.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/47920] strange code generated for expression (a+7)/8
2011-02-28 9:31 [Bug target/47920] New: strange code generated for expression (a+7)/8 carrot at google dot com
2011-02-28 10:48 ` [Bug target/47920] " mikpe at it dot uu.se
2011-02-28 10:51 ` jakub at gcc dot gnu.org
@ 2011-03-01 6:44 ` carrot at google dot com
2011-03-03 10:50 ` ibolton at gcc dot gnu.org
2011-03-05 14:21 ` rearnsha at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: carrot at google dot com @ 2011-03-01 6:44 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/47920] strange code generated for expression (a+7)/8
2011-02-28 9:31 [Bug target/47920] New: strange code generated for expression (a+7)/8 carrot at google dot com
` (2 preceding siblings ...)
2011-03-01 6:44 ` carrot at google dot com
@ 2011-03-03 10:50 ` ibolton at gcc dot gnu.org
2011-03-05 14:21 ` rearnsha at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: ibolton at gcc dot gnu.org @ 2011-03-03 10:50 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47920
Ian Bolton <ibolton at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |WAITING
Last reconfirmed| |2011.03.03 10:49:54
CC| |ibolton at gcc dot gnu.org
Ever Confirmed|0 |1
--- Comment #4 from Ian Bolton <ibolton at gcc dot gnu.org> 2011-03-03 10:49:54 UTC ---
I don't think "strange code" applies any more, thanks to input from Mikael and
Jakub. I am wondering whether to reject this bug. Any further comments?
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/47920] strange code generated for expression (a+7)/8
2011-02-28 9:31 [Bug target/47920] New: strange code generated for expression (a+7)/8 carrot at google dot com
` (3 preceding siblings ...)
2011-03-03 10:50 ` ibolton at gcc dot gnu.org
@ 2011-03-05 14:21 ` rearnsha at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: rearnsha at gcc dot gnu.org @ 2011-03-05 14:21 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47920
Richard Earnshaw <rearnsha at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|WAITING |RESOLVED
Resolution| |INVALID
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-03-05 14:21 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-28 9:31 [Bug target/47920] New: strange code generated for expression (a+7)/8 carrot at google dot com
2011-02-28 10:48 ` [Bug target/47920] " mikpe at it dot uu.se
2011-02-28 10:51 ` jakub at gcc dot gnu.org
2011-03-01 6:44 ` carrot at google dot com
2011-03-03 10:50 ` ibolton at gcc dot gnu.org
2011-03-05 14:21 ` rearnsha at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).