public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/41514] redundant compare instruction of consecutive conditional branches
2009-09-30 8:25 [Bug target/41514] New: redundant compare instruction of consecutive conditional branches carrot at google dot com
@ 2009-09-30 8:25 ` carrot at google dot com
2009-09-30 8:51 ` steven at gcc dot gnu dot org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: carrot at google dot com @ 2009-09-30 8:25 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from carrot at google dot com 2009-09-30 08:25 -------
Created an attachment (id=18671)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=18671&action=view)
test case
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41514
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/41514] New: redundant compare instruction of consecutive conditional branches
@ 2009-09-30 8:25 carrot at google dot com
2009-09-30 8:25 ` [Bug target/41514] " carrot at google dot com
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: carrot at google dot com @ 2009-09-30 8:25 UTC (permalink / raw)
To: gcc-bugs
Compile the attached source code with options -Os -march=armv5te -mthumb, gcc
generates:
push {lr}
cmp r0, #63 // A
beq .L3
cmp r0, #63 // B
bhi .L4
cmp r0, #45
beq .L3
cmp r0, #47
bne .L5
b .L3
.L4:
cmp r0, #99
bne .L5
.L3:
mov r0, #1
b .L2
.L5:
mov r0, #0
.L2:
@ sp needed for prologue
pop {pc}
Instruction B is the same as instruction A, and there are no other instructions
between them clobber condition codes. So we can remove instruction B.
--
Summary: redundant compare instruction of consecutive conditional
branches
Product: gcc
Version: 4.5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: carrot at google dot com
GCC build triplet: i686-linux
GCC host triplet: i686-linux
GCC target triplet: arm-eabi
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41514
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/41514] redundant compare instruction of consecutive conditional branches
2009-09-30 8:25 [Bug target/41514] New: redundant compare instruction of consecutive conditional branches carrot at google dot com
2009-09-30 8:25 ` [Bug target/41514] " carrot at google dot com
@ 2009-09-30 8:51 ` steven at gcc dot gnu dot org
2009-10-01 7:38 ` carrot at google dot com
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: steven at gcc dot gnu dot org @ 2009-09-30 8:51 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from steven at gcc dot gnu dot org 2009-09-30 08:50 -------
Where does it come from? (Remember: option -dAP, then look at .s file)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41514
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/41514] redundant compare instruction of consecutive conditional branches
2009-09-30 8:25 [Bug target/41514] New: redundant compare instruction of consecutive conditional branches carrot at google dot com
2009-09-30 8:25 ` [Bug target/41514] " carrot at google dot com
2009-09-30 8:51 ` steven at gcc dot gnu dot org
@ 2009-10-01 7:38 ` carrot at google dot com
2009-10-06 7:13 ` ramana at gcc dot gnu dot org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: carrot at google dot com @ 2009-10-01 7:38 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from carrot at google dot com 2009-10-01 07:37 -------
(In reply to comment #2)
> Where does it come from? (Remember: option -dAP, then look at .s file)
>
The first several instructions and corresponding rtl patterns are:
cmp r0, #63
beq .L3
cmp r0, #63
bhi .L4
(jump_insn 8 3 35 src/./test5.c:3 (set (pc)
(if_then_else (eq (reg/v:SI 0 r0 [orig:135 ch ] [135])
(const_int 63 [0x3f]))
(label_ref 18)
(pc))) 201 {*cbranchsi4_insn} (expr_list:REG_BR_PROB (const_int
2900 [0xb54])
(nil))
-> 18)
(note 35 8 9 [bb 3] NOTE_INSN_BASIC_BLOCK)
(jump_insn 9 35 36 src/./test5.c:3 (set (pc)
(if_then_else (gtu (reg/v:SI 0 r0 [orig:135 ch ] [135])
(const_int 63 [0x3f]))
(label_ref 14)
(pc))) 201 {*cbranchsi4_insn} (expr_list:REG_BR_PROB (const_int
5000 [0x1388])
(nil))
-> 14)
In thumb's instruction patterns, compare and branch instructions can't be
expressed separately. So we can't easily remove the second compare instruction
in middle end.
I just noticed the second conditional branch (larger than 63) is totally
unnecessary if we compare the equality with 63, 45, 47, 99 one by one. This is
another missed optimization exposed by this test case.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41514
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/41514] redundant compare instruction of consecutive conditional branches
2009-09-30 8:25 [Bug target/41514] New: redundant compare instruction of consecutive conditional branches carrot at google dot com
` (2 preceding siblings ...)
2009-10-01 7:38 ` carrot at google dot com
@ 2009-10-06 7:13 ` ramana at gcc dot gnu dot org
2009-12-12 1:08 ` rearnsha at gcc dot gnu dot org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: ramana at gcc dot gnu dot org @ 2009-10-06 7:13 UTC (permalink / raw)
To: gcc-bugs
--
ramana at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2009-10-06 07:13:35
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41514
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/41514] redundant compare instruction of consecutive conditional branches
2009-09-30 8:25 [Bug target/41514] New: redundant compare instruction of consecutive conditional branches carrot at google dot com
` (3 preceding siblings ...)
2009-10-06 7:13 ` ramana at gcc dot gnu dot org
@ 2009-12-12 1:08 ` rearnsha at gcc dot gnu dot org
2010-03-31 21:41 ` bernds at codesourcery dot com
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rearnsha at gcc dot gnu dot org @ 2009-12-12 1:08 UTC (permalink / raw)
To: gcc-bugs
--
rearnsha at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41514
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/41514] redundant compare instruction of consecutive conditional branches
2009-09-30 8:25 [Bug target/41514] New: redundant compare instruction of consecutive conditional branches carrot at google dot com
` (4 preceding siblings ...)
2009-12-12 1:08 ` rearnsha at gcc dot gnu dot org
@ 2010-03-31 21:41 ` bernds at codesourcery dot com
2010-04-16 9:43 ` bernds at gcc dot gnu dot org
2010-04-16 11:24 ` bernds at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: bernds at codesourcery dot com @ 2010-03-31 21:41 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from bernds at codesourcery dot com 2010-03-31 21:41 -------
A simple patch is at http://gcc.gnu.org/ml/gcc-patches/2010-03/msg01405.html
--
bernds at codesourcery dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bernds at codesourcery dot
| |com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41514
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/41514] redundant compare instruction of consecutive conditional branches
2009-09-30 8:25 [Bug target/41514] New: redundant compare instruction of consecutive conditional branches carrot at google dot com
` (5 preceding siblings ...)
2010-03-31 21:41 ` bernds at codesourcery dot com
@ 2010-04-16 9:43 ` bernds at gcc dot gnu dot org
2010-04-16 11:24 ` bernds at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: bernds at gcc dot gnu dot org @ 2010-04-16 9:43 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from bernds at gcc dot gnu dot org 2010-04-16 09:42 -------
Subject: Bug 41514
Author: bernds
Date: Fri Apr 16 09:42:32 2010
New Revision: 158404
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=158404
Log:
PR target/41514
* config/arm/arm.md (cbranchsi4_insn): Renamed from "*cbranchsi4_insn".
If the previous insn is a cbranchsi4_insn with the same arguments,
omit the compare instruction.
PR target/41514
gcc.target/arm/thumb-comparisons.c: New test.
Added:
trunk/gcc/testsuite/gcc.target/arm/thumb-comparisons.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/config/arm/arm.md
trunk/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41514
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/41514] redundant compare instruction of consecutive conditional branches
2009-09-30 8:25 [Bug target/41514] New: redundant compare instruction of consecutive conditional branches carrot at google dot com
` (6 preceding siblings ...)
2010-04-16 9:43 ` bernds at gcc dot gnu dot org
@ 2010-04-16 11:24 ` bernds at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: bernds at gcc dot gnu dot org @ 2010-04-16 11:24 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from bernds at gcc dot gnu dot org 2010-04-16 11:24 -------
Fixed.
--
bernds at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41514
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2010-04-16 11:24 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-30 8:25 [Bug target/41514] New: redundant compare instruction of consecutive conditional branches carrot at google dot com
2009-09-30 8:25 ` [Bug target/41514] " carrot at google dot com
2009-09-30 8:51 ` steven at gcc dot gnu dot org
2009-10-01 7:38 ` carrot at google dot com
2009-10-06 7:13 ` ramana at gcc dot gnu dot org
2009-12-12 1:08 ` rearnsha at gcc dot gnu dot org
2010-03-31 21:41 ` bernds at codesourcery dot com
2010-04-16 9:43 ` bernds at gcc dot gnu dot org
2010-04-16 11:24 ` bernds at gcc dot gnu dot 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).