public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/31799] New: Failed to optimize out test instruction
@ 2007-05-03 14:21 hjl at lucon dot org
2007-05-03 16:08 ` [Bug rtl-optimization/31799] " ubizjak at gmail dot com
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: hjl at lucon dot org @ 2007-05-03 14:21 UTC (permalink / raw)
To: gcc-bugs
For
void
foo (int x, int *y, int *z)
{
*z = ++x;
if (x != 0)
*y = 1;
}
gcc 4.3 generates
foo:
.LFB2:
addl $1, %edi
testl %edi, %edi
movl %edi, (%rdx)
je .L3
movl $1, (%rsi)
.L3:
rep ; ret
But "testl %edi, %edi" isn't needed since "addl $1, %edi" sets proper
FLAGS_REG.
--
Summary: Failed to optimize out test instruction
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: hjl at lucon dot org
GCC target triplet: x86_64-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31799
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug rtl-optimization/31799] Failed to optimize out test instruction
2007-05-03 14:21 [Bug rtl-optimization/31799] New: Failed to optimize out test instruction hjl at lucon dot org
@ 2007-05-03 16:08 ` ubizjak at gmail dot com
2007-05-03 16:22 ` ubizjak at gmail dot com
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: ubizjak at gmail dot com @ 2007-05-03 16:08 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from ubizjak at gmail dot com 2007-05-03 17:08 -------
(In reply to comment #0)
> foo:
> addl $1, %edi
> testl %edi, %edi
> movl %edi, (%rdx)
> je .L3
> movl $1, (%rsi)
> .L3:
> rep ; ret
This is just an unfortunate corner case. During combine phase we get:
(insn 10 6 11 2 (parallel [
(set (reg/v:SI 58 [ x.27 ])
(plus:SI (reg/v:SI 59 [ x ])
(const_int 1 [0x1])))
(clobber (reg:CC 17 flags))
]) 210 {*addsi_1} (insn_list:REG_DEP_TRUE 3 (nil))
(expr_list:REG_DEAD (reg/v:SI 59 [ x ])
(expr_list:REG_UNUSED (reg:CC 17 flags)
(nil))))
(insn 11 10 13 2 (set (mem:SI (reg/v/f:DI 61 [ z ]) [2 S4 A32])
(reg/v:SI 58 [ x.27 ])) 40 {*movsi_1} (insn_list:REG_DEP_TRUE 5
(insn_list:REG_DEP_TRUE 10 (nil)))
(expr_list:REG_DEAD (reg/v/f:DI 61 [ z ])
(nil)))
(insn 13 11 14 2 (set (reg:CCZ 17 flags)
(compare:CCZ (reg/v:SI 58 [ x.27 ])
(const_int -1 [0xffffffffffffffff]))) 5 {*cmpsi_1_insn} (nil)
(expr_list:REG_DEAD (reg/v:SI 58 [ x.27 ])
(nil)))
It looks that insn 10 and insn 13 don't combine into flags setting insn due to
insn 11 interfering in some way. If the code is changed to:
void
foo (int x, int *y, int *z)
{
if (++x != 0)
*y = 1;
*z = x;
}
then gcc generates expected asm without test insn.
--
ubizjak at gmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2007-05-03 17:08:39
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31799
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug rtl-optimization/31799] Failed to optimize out test instruction
2007-05-03 14:21 [Bug rtl-optimization/31799] New: Failed to optimize out test instruction hjl at lucon dot org
2007-05-03 16:08 ` [Bug rtl-optimization/31799] " ubizjak at gmail dot com
@ 2007-05-03 16:22 ` ubizjak at gmail dot com
2007-05-05 1:31 ` hjl at lucon dot org
2007-05-05 17:49 ` ubizjak at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: ubizjak at gmail dot com @ 2007-05-03 16:22 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from ubizjak at gmail dot com 2007-05-03 17:22 -------
Ah, for some reason insn 13 does not have the insn link pointing to insn 10.
Probably dataflow should/could fix this?
--
ubizjak at gmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ubizjak at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31799
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug rtl-optimization/31799] Failed to optimize out test instruction
2007-05-03 14:21 [Bug rtl-optimization/31799] New: Failed to optimize out test instruction hjl at lucon dot org
2007-05-03 16:08 ` [Bug rtl-optimization/31799] " ubizjak at gmail dot com
2007-05-03 16:22 ` ubizjak at gmail dot com
@ 2007-05-05 1:31 ` hjl at lucon dot org
2007-05-05 17:49 ` ubizjak at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: hjl at lucon dot org @ 2007-05-05 1:31 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from hjl at lucon dot org 2007-05-05 02:31 -------
The problem may be patterns like
[(set (match_operand:SI 0 "nonimmediate_operand" "=r,rm,r")
(plus:SI (match_operand:SI 1 "nonimmediate_operand" "%0,0,r")
(match_operand:SI 2 "general_operand" "rmni,rni,lni")))
(clobber (reg:CC FLAGS_REG))]
What if we replace (clobber (reg:CC FLAGS_REG)) with something more
reasonable like
(set (reg FLAGS_REG)
(compare
(plus:SI (match_dup 1) (match_dup 2))
(const_int 0)))
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31799
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug rtl-optimization/31799] Failed to optimize out test instruction
2007-05-03 14:21 [Bug rtl-optimization/31799] New: Failed to optimize out test instruction hjl at lucon dot org
` (2 preceding siblings ...)
2007-05-05 1:31 ` hjl at lucon dot org
@ 2007-05-05 17:49 ` ubizjak at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: ubizjak at gmail dot com @ 2007-05-05 17:49 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from ubizjak at gmail dot com 2007-05-05 18:49 -------
(In reply to comment #3)
> The problem may be patterns like
No, the patterns are OK. Combine pass merges these patterns without problems.
But without links, combine doesn't even try to merge them.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31799
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-05-05 17:49 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-03 14:21 [Bug rtl-optimization/31799] New: Failed to optimize out test instruction hjl at lucon dot org
2007-05-03 16:08 ` [Bug rtl-optimization/31799] " ubizjak at gmail dot com
2007-05-03 16:22 ` ubizjak at gmail dot com
2007-05-05 1:31 ` hjl at lucon dot org
2007-05-05 17:49 ` ubizjak at gmail dot com
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).