public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/42258] New: redundant register move around mul instruction
@ 2009-12-03 3:27 carrot at google dot com
2009-12-09 2:27 ` [Bug regression/42258] " carrot at google dot com
` (10 more replies)
0 siblings, 11 replies; 12+ messages in thread
From: carrot at google dot com @ 2009-12-03 3:27 UTC (permalink / raw)
To: gcc-bugs
Compile following function with options -march=armv5te -mthumb -Os
int mulx(int x)
{
return x*42;
}
Gcc generates:
mulx:
mov r2, #42
mov r3, r2 //A
mul r3, r0
@ sp needed for prologue
mov r0, r3 //B
bx lr
There are two redundant mov instructions marked as A and B. The ideal code
should be:
mov r2, #42
mul r0, r2
bx lr
The root causes of the two movs are different.
A.
In arm.md there is an insn pattern which can support 3-register multiplication.
(define_insn "*thumb_mulsi3"
[(set (match_operand:SI 0 "register_operand" "=&l,&l,&l")
(mult:SI (match_operand:SI 1 "register_operand" "%l,*h,0")
(match_operand:SI 2 "register_operand" "l,l,l")))]
"TARGET_THUMB1 && !arm_arch6"
"*
if (which_alternative < 2)
return \"mov\\t%0, %1\;mul\\t%0, %2\";
else
return \"mul\\t%0, %2\";
"
[(set_attr "length" "4,4,2")
(set_attr "insn" "mul")]
)
So after expand we got the following rtx insn:
(insn 7 6 8 3 testD.i:2 (set (reg:SI 136)
(mult:SI (reg:SI 137)
(reg/v:SI 135 [ x ]))) -1 (nil))
For register allocator there is no difference between (set r3 mult(r0, r2))
and (set r2 mult(r0, r2)) if the original r2 is dead after this
instruction. Unfortunately the first form is chosen, so an extra mov is
generated.
B.
After rtl expansion I got:
(insn 2 4 3 2 testD.i:2 (set (reg/v:SI 135 [ x ])
(reg:SI 0 r0 [ x ])) -1 (nil))
(note 3 2 5 2 NOTE_INSN_FUNCTION_BEG)
(note 5 3 6 3 [bb 3] NOTE_INSN_BASIC_BLOCK)
(insn 6 5 7 3 testD.i:2 (set (reg:SI 137)
(const_int 42 [0x2a])) -1 (nil))
(insn 7 6 8 3 testD.i:2 (set (reg:SI 136)
(mult:SI (reg:SI 137)
(reg/v:SI 135 [ x ]))) -1 (nil))
(insn 8 7 9 3 testD.i:2 (set (reg:SI 134 [ <retval> ])
(reg:SI 136)) -1 (nil))
(jump_insn 9 8 10 3 testD.i:2 (set (pc)
(label_ref 11)) -1 (nil)
-> 11)
(barrier 10 9 16)
(note 16 10 13 4 [bb 4] NOTE_INSN_BASIC_BLOCK)
(insn 13 16 14 4 testD.i:4 (clobber (reg/i:SI 0 r0)) -1 (nil))
(insn 14 13 11 4 testD.i:4 (clobber (reg:SI 134 [ <retval> ])) -1 (nil))
(code_label 11 14 17 5 1 "" [1 uses])
(note 17 11 12 5 [bb 5] NOTE_INSN_BASIC_BLOCK)
(insn 12 17 15 5 testD.i:4 (set (reg/i:SI 0 r0)
(reg:SI 134 [ <retval> ])) -1 (nil))
(insn 15 12 0 5 testD.i:4 (use (reg/i:SI 0 r0)) -1 (nil))
The extra mov comes from insn 12 and no later pass can eliminate it. Should we
propagate expression into return register?
--
Summary: redundant register move around mul instruction
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=42258
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug regression/42258] redundant register move around mul instruction
2009-12-03 3:27 [Bug target/42258] New: redundant register move around mul instruction carrot at google dot com
@ 2009-12-09 2:27 ` carrot at google dot com
2009-12-09 16:12 ` ramana at gcc dot gnu dot org
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: carrot at google dot com @ 2009-12-09 2:27 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from carrot at google dot com 2009-12-09 02:27 -------
Gcc 4.4 doesn't have this problem. It is a new regression caused by patch
152533.
--
carrot at google dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |vmakarov at redhat dot com
Component|target |regression
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42258
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug regression/42258] redundant register move around mul instruction
2009-12-03 3:27 [Bug target/42258] New: redundant register move around mul instruction carrot at google dot com
2009-12-09 2:27 ` [Bug regression/42258] " carrot at google dot com
@ 2009-12-09 16:12 ` ramana at gcc dot gnu dot org
2009-12-30 23:14 ` [Bug rtl-optimization/42258] [4.5 Regression] " rguenth at gcc dot gnu dot org
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: ramana at gcc dot gnu dot org @ 2009-12-09 16:12 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-12-09 16:12:19
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42258
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug rtl-optimization/42258] [4.5 Regression] redundant register move around mul instruction
2009-12-03 3:27 [Bug target/42258] New: redundant register move around mul instruction carrot at google dot com
2009-12-09 2:27 ` [Bug regression/42258] " carrot at google dot com
2009-12-09 16:12 ` ramana at gcc dot gnu dot org
@ 2009-12-30 23:14 ` rguenth at gcc dot gnu dot org
2009-12-31 9:33 ` steven at gcc dot gnu dot org
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-12-30 23:14 UTC (permalink / raw)
To: gcc-bugs
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|regression |rtl-optimization
Keywords| |missed-optimization, ra
Summary|[4.5 only] redundant |[4.5 Regression] redundant
|register move around mul |register move around mul
|instruction |instruction
Target Milestone|--- |4.5.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42258
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug rtl-optimization/42258] [4.5 Regression] redundant register move around mul instruction
2009-12-03 3:27 [Bug target/42258] New: redundant register move around mul instruction carrot at google dot com
` (2 preceding siblings ...)
2009-12-30 23:14 ` [Bug rtl-optimization/42258] [4.5 Regression] " rguenth at gcc dot gnu dot org
@ 2009-12-31 9:33 ` steven at gcc dot gnu dot org
2009-12-31 11:11 ` rguenth at gcc dot gnu dot org
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: steven at gcc dot gnu dot org @ 2009-12-31 9:33 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from steven at gcc dot gnu dot org 2009-12-31 09:32 -------
http://gcc.gnu.org/viewcvs?view=revision&revision=152533
--
steven at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
BugsThisDependsOn| |22072
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42258
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug rtl-optimization/42258] [4.5 Regression] redundant register move around mul instruction
2009-12-03 3:27 [Bug target/42258] New: redundant register move around mul instruction carrot at google dot com
` (3 preceding siblings ...)
2009-12-31 9:33 ` steven at gcc dot gnu dot org
@ 2009-12-31 11:11 ` rguenth at gcc dot gnu dot org
2010-01-02 15:58 ` rguenth at gcc dot gnu dot org
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-12-31 11:11 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from rguenth at gcc dot gnu dot org 2009-12-31 11:11 -------
But the patch was backported.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42258
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug rtl-optimization/42258] [4.5 Regression] redundant register move around mul instruction
2009-12-03 3:27 [Bug target/42258] New: redundant register move around mul instruction carrot at google dot com
` (4 preceding siblings ...)
2009-12-31 11:11 ` rguenth at gcc dot gnu dot org
@ 2010-01-02 15:58 ` rguenth at gcc dot gnu dot org
2010-03-17 11:05 ` bernds at codesourcery dot com
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-01-02 15:58 UTC (permalink / raw)
To: gcc-bugs
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42258
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug rtl-optimization/42258] [4.5 Regression] redundant register move around mul instruction
2009-12-03 3:27 [Bug target/42258] New: redundant register move around mul instruction carrot at google dot com
` (5 preceding siblings ...)
2010-01-02 15:58 ` rguenth at gcc dot gnu dot org
@ 2010-03-17 11:05 ` bernds at codesourcery dot com
2010-03-17 11:44 ` bernds at codesourcery dot com
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: bernds at codesourcery dot com @ 2010-03-17 11:05 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from bernds at codesourcery dot com 2010-03-17 11:05 -------
It's not immediately obvious to me why the ARM mulsi3 patterns are written the
way they are - what are the earlyclobber tricks supposed to be good for?
Richard E., any clues?
--
bernds at codesourcery dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |rearnsha at arm dot com,
| |bernds at codesourcery dot
| |com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42258
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug rtl-optimization/42258] [4.5 Regression] redundant register move around mul instruction
2009-12-03 3:27 [Bug target/42258] New: redundant register move around mul instruction carrot at google dot com
` (6 preceding siblings ...)
2010-03-17 11:05 ` bernds at codesourcery dot com
@ 2010-03-17 11:44 ` bernds at codesourcery dot com
2010-03-17 11:59 ` steven at gcc dot gnu dot org
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: bernds at codesourcery dot com @ 2010-03-17 11:44 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from bernds at codesourcery dot com 2010-03-17 11:44 -------
Created an attachment (id=20123)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20123&action=view)
A patch to fix it.
Okay, so the pattern is written strangely because it's a two-operand mul where
the input and output may not be the same register.
It may be better to write this using an earlyclobbered in-out operand, but you
can't show anymore that the operation is commutative.
It can be fixed with a simple peephole optimization, at least for this
testcase.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42258
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug rtl-optimization/42258] [4.5 Regression] redundant register move around mul instruction
2009-12-03 3:27 [Bug target/42258] New: redundant register move around mul instruction carrot at google dot com
` (7 preceding siblings ...)
2010-03-17 11:44 ` bernds at codesourcery dot com
@ 2010-03-17 11:59 ` steven at gcc dot gnu dot org
2010-03-19 18:19 ` bernds at gcc dot gnu dot org
2010-03-20 12:58 ` steven at gcc dot gnu dot org
10 siblings, 0 replies; 12+ messages in thread
From: steven at gcc dot gnu dot org @ 2010-03-17 11:59 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from steven at gcc dot gnu dot org 2010-03-17 11:59 -------
Perhaps add a comment why the peephole is needed? That information tend to get
lost rather quickly.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42258
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug rtl-optimization/42258] [4.5 Regression] redundant register move around mul instruction
2009-12-03 3:27 [Bug target/42258] New: redundant register move around mul instruction carrot at google dot com
` (8 preceding siblings ...)
2010-03-17 11:59 ` steven at gcc dot gnu dot org
@ 2010-03-19 18:19 ` bernds at gcc dot gnu dot org
2010-03-20 12:58 ` steven at gcc dot gnu dot org
10 siblings, 0 replies; 12+ messages in thread
From: bernds at gcc dot gnu dot org @ 2010-03-19 18:19 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from bernds at gcc dot gnu dot org 2010-03-19 18:19 -------
Subject: Bug 42258
Author: bernds
Date: Fri Mar 19 18:18:54 2010
New Revision: 157581
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=157581
Log:
gcc/
PR rtl-optimization/42258
* ira-lives.c (check_and_make_def_conflict): Ignore conflict for a
use that may match DEF.
testsuite/
PR rtl-optimization/42258
* gcc.target/arm/thumb1-mul-moves.c: New test.
Added:
trunk/gcc/testsuite/gcc.target/arm/thumb1-mul-moves.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/ira-lives.c
trunk/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42258
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug rtl-optimization/42258] [4.5 Regression] redundant register move around mul instruction
2009-12-03 3:27 [Bug target/42258] New: redundant register move around mul instruction carrot at google dot com
` (9 preceding siblings ...)
2010-03-19 18:19 ` bernds at gcc dot gnu dot org
@ 2010-03-20 12:58 ` steven at gcc dot gnu dot org
10 siblings, 0 replies; 12+ messages in thread
From: steven at gcc dot gnu dot org @ 2010-03-20 12:58 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from steven at gcc dot gnu dot org 2010-03-20 12:58 -------
Shouldeth be fixedeth by aforementionedeth patcheth (comment #7). Yay!
--
steven at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
URL| |http://gcc.gnu.org/ml/gcc-
| |patches/2010-
| |03/msg00905.html
Status|NEW |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42258
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2010-03-20 12:58 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-03 3:27 [Bug target/42258] New: redundant register move around mul instruction carrot at google dot com
2009-12-09 2:27 ` [Bug regression/42258] " carrot at google dot com
2009-12-09 16:12 ` ramana at gcc dot gnu dot org
2009-12-30 23:14 ` [Bug rtl-optimization/42258] [4.5 Regression] " rguenth at gcc dot gnu dot org
2009-12-31 9:33 ` steven at gcc dot gnu dot org
2009-12-31 11:11 ` rguenth at gcc dot gnu dot org
2010-01-02 15:58 ` rguenth at gcc dot gnu dot org
2010-03-17 11:05 ` bernds at codesourcery dot com
2010-03-17 11:44 ` bernds at codesourcery dot com
2010-03-17 11:59 ` steven at gcc dot gnu dot org
2010-03-19 18:19 ` bernds at gcc dot gnu dot org
2010-03-20 12:58 ` steven 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).