public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/31146] New: forwprop does not look through casts
@ 2007-03-12 12:23 rguenth at gcc dot gnu dot org
2007-03-12 14:59 ` [Bug tree-optimization/31146] " pinskia at gcc dot gnu dot org
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-03-12 12:23 UTC (permalink / raw)
To: gcc-bugs
The following two testcases should produce the same code after forwprop1:
struct foo { int i[3]; };
void bar (void)
{
struct foo Foo;
int i;
for (i=0; i<3; ++i)
{
void *p = &Foo.i[i];
int *pi = (int *)p;
if (pi != 0)
{
*pi = 0;
}
}
}
---
struct foo { int i[3]; };
void bar (void)
{
struct foo Foo;
int i;
for (i=0; i<3; ++i)
{
void *p = &Foo.i[i];
int *pi = (int *)p;
if (p != 0)
{
*pi = 0;
}
}
}
(the difference is testing p != 0 vs. pi != 0)
This happens in tramp3d-v4 via placement new:
for (i=0; i<3; ++i)
new (&a[i]) double;
where placement new expands to the "wrong" test sequence.
Mine.
--
Summary: forwprop does not look through casts
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
AssignedTo: rguenth at gcc dot gnu dot org
ReportedBy: rguenth at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31146
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug tree-optimization/31146] forwprop does not look through casts
2007-03-12 12:23 [Bug tree-optimization/31146] New: forwprop does not look through casts rguenth at gcc dot gnu dot org
@ 2007-03-12 14:59 ` pinskia at gcc dot gnu dot org
2007-03-12 15:09 ` pinskia at gcc dot gnu dot org
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-03-12 14:59 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2007-03-12 14:59 -------
forwprop should NOT, I repeat should NOT look through casts for conditional if
the SSA_NAME that defines the cast is still used after the conditional.
Really this non zero optimization should be done by VRP.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31146
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug tree-optimization/31146] forwprop does not look through casts
2007-03-12 12:23 [Bug tree-optimization/31146] New: forwprop does not look through casts rguenth at gcc dot gnu dot org
2007-03-12 14:59 ` [Bug tree-optimization/31146] " pinskia at gcc dot gnu dot org
@ 2007-03-12 15:09 ` pinskia at gcc dot gnu dot org
2007-03-12 15:35 ` rguenth at gcc dot gnu dot org
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-03-12 15:09 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from pinskia at gcc dot gnu dot org 2007-03-12 15:09 -------
I should mention, unless it can produce a constant result.
For an example this function:
void bar (void * a)
{
struct foo Foo;
int i;
for (i=0; i<3; ++i)
{
void *p = a;
int *pi = (int *)p;
if (pi != 0)
{
*pi = 0;
}
}
}
Should not be transformed into:
void bar (void * a)
{
struct foo Foo;
int i;
for (i=0; i<3; ++i)
{
void *p = a;
int *pi = (int *)p;
if (p != 0)
{
*pi = 0;
}
}
}
As VRP is not as smart as there is no back tracking of ranges.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31146
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug tree-optimization/31146] forwprop does not look through casts
2007-03-12 12:23 [Bug tree-optimization/31146] New: forwprop does not look through casts rguenth at gcc dot gnu dot org
2007-03-12 14:59 ` [Bug tree-optimization/31146] " pinskia at gcc dot gnu dot org
2007-03-12 15:09 ` pinskia at gcc dot gnu dot org
@ 2007-03-12 15:35 ` rguenth at gcc dot gnu dot org
2007-03-12 15:41 ` pinskia at gcc dot gnu dot org
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-03-12 15:35 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from rguenth at gcc dot gnu dot org 2007-03-12 15:35 -------
The problem is that for example FRE value numbers
void *p_4 = &a[0];
int *q_1 = (int *)p_4;
p_4 with void* type (even if &a[0] is of int* type) and so re-generates the
conversion to int* even though it is about to replace (int *)p_4 with p_4
(as tree_ssa_useless_type_conversion_1 is false for converting void* to int*).
At the same time tree-combining the conversion (int *)&a[0] leads to
&a[0] for which we have a value already, the void* p_4 :/
Maybe the new VN will fix this testcase as well. With the series of forwprop
patches in my queue (which you obviously don't like at all, but I blame you
for that) we get for
(void) (TARGET_EXPR <D.2605, (double *) operator new (8, (void *) &a[i])>;,
D.2605 != 0B ? try
{
*D.2605 = 0.0;
}
catch
{
operator delete ((void *) D.2605, (void *) &a[i]);
}, D.2605 : D.2605;)
instead of
__p_5 = &a[i_3];
iftmp.3_6 = (double *) __p_5;
if (iftmp.3_6 != 0B) goto <L1>; else goto <L2>;
<L1>:;
*iftmp.3_6 = 0.0;
<L2>:;
just
a[i_3] = 0.0;
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31146
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug tree-optimization/31146] forwprop does not look through casts
2007-03-12 12:23 [Bug tree-optimization/31146] New: forwprop does not look through casts rguenth at gcc dot gnu dot org
` (2 preceding siblings ...)
2007-03-12 15:35 ` rguenth at gcc dot gnu dot org
@ 2007-03-12 15:41 ` pinskia at gcc dot gnu dot org
2007-03-12 16:01 ` rguenth at gcc dot gnu dot org
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-03-12 15:41 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from pinskia at gcc dot gnu dot org 2007-03-12 15:41 -------
I think really this comes down to our type system, I remember posting a patch
for the LTO branch which adds back the explict cast to "void*", I can test
that, it should fix this testcase also :).
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31146
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug tree-optimization/31146] forwprop does not look through casts
2007-03-12 12:23 [Bug tree-optimization/31146] New: forwprop does not look through casts rguenth at gcc dot gnu dot org
` (3 preceding siblings ...)
2007-03-12 15:41 ` pinskia at gcc dot gnu dot org
@ 2007-03-12 16:01 ` rguenth at gcc dot gnu dot org
2007-03-16 10:11 ` rguenth at gcc dot gnu dot org
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-03-12 16:01 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from rguenth at gcc dot gnu dot org 2007-03-12 16:01 -------
Well sure - if we then would get
int *p_1 = &a[0];
void *q_1 = (void *)p_1;
int *r_1 = (int *)q_1;
if (r_1 != NULL)
...
then FRE would figure out that r_1 == p_1 and the forwprop pass after FRE will
fold the comparison.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31146
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug tree-optimization/31146] forwprop does not look through casts
2007-03-12 12:23 [Bug tree-optimization/31146] New: forwprop does not look through casts rguenth at gcc dot gnu dot org
` (4 preceding siblings ...)
2007-03-12 16:01 ` rguenth at gcc dot gnu dot org
@ 2007-03-16 10:11 ` rguenth at gcc dot gnu dot org
2007-03-20 11:05 ` rguenth at gcc dot gnu dot org
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-03-16 10:11 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from rguenth at gcc dot gnu dot org 2007-03-16 10:11 -------
Subject: Bug 31146
Author: rguenth
Date: Fri Mar 16 10:11:14 2007
New Revision: 122985
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122985
Log:
2007-03-16 Richard Guenther <rguenther@suse.de>
PR tree-optimization/31146
* tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Restructure
to allow recursion of forward_propagate_addr_expr.
(forward_propagate_addr_into_variable_array_index): Likewise.
(forward_propagate_addr_expr): Likewise.
(tree_ssa_forward_propagate_single_use_vars): Likewise.
(forward_propagate_addr_expr_1): Recurse on simple copies
instead of propagating into them. Do so for useless conversions
as well.
(forward_propagate_addr_expr): Clean up unused statements after
recursion.
* g++.dg/tree-ssa/pr31146.C: New testcase.
Added:
trunk/gcc/testsuite/g++.dg/tree-ssa/pr31146.C
Modified:
trunk/gcc/ChangeLog
trunk/gcc/testsuite/ChangeLog
trunk/gcc/tree-ssa-forwprop.c
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31146
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug tree-optimization/31146] forwprop does not look through casts
2007-03-12 12:23 [Bug tree-optimization/31146] New: forwprop does not look through casts rguenth at gcc dot gnu dot org
` (5 preceding siblings ...)
2007-03-16 10:11 ` rguenth at gcc dot gnu dot org
@ 2007-03-20 11:05 ` rguenth at gcc dot gnu dot org
2007-03-20 12:49 ` mueller at gcc dot gnu dot org
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-03-20 11:05 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from rguenth at gcc dot gnu dot org 2007-03-20 11:05 -------
A slightly related testcase is now properly optimized.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31146
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug tree-optimization/31146] forwprop does not look through casts
2007-03-12 12:23 [Bug tree-optimization/31146] New: forwprop does not look through casts rguenth at gcc dot gnu dot org
` (6 preceding siblings ...)
2007-03-20 11:05 ` rguenth at gcc dot gnu dot org
@ 2007-03-20 12:49 ` mueller at gcc dot gnu dot org
2007-05-02 9:13 ` rguenth at gcc dot gnu dot org
2007-05-02 9:17 ` rguenth at gcc dot gnu dot org
9 siblings, 0 replies; 11+ messages in thread
From: mueller at gcc dot gnu dot org @ 2007-03-20 12:49 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from mueller at gcc dot gnu dot org 2007-03-20 12:48 -------
*** Bug 30864 has been marked as a duplicate of this bug. ***
--
mueller at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |dcb314 at hotmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31146
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug tree-optimization/31146] forwprop does not look through casts
2007-03-12 12:23 [Bug tree-optimization/31146] New: forwprop does not look through casts rguenth at gcc dot gnu dot org
` (7 preceding siblings ...)
2007-03-20 12:49 ` mueller at gcc dot gnu dot org
@ 2007-05-02 9:13 ` rguenth at gcc dot gnu dot org
2007-05-02 9:17 ` rguenth at gcc dot gnu dot org
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-05-02 9:13 UTC (permalink / raw)
To: gcc-bugs
------- Comment #9 from rguenth at gcc dot gnu dot org 2007-05-02 10:13 -------
Subject: Bug 31146
Author: rguenth
Date: Wed May 2 09:12:49 2007
New Revision: 124349
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=124349
Log:
2007-05-02 Richard Guenther <rguenther@suse.de>
PR tree-optimization/31146
* tree-ssa-forwprop.c (forward_propagate_addr_expr_1): New
argument, single_use_p. If we have a single use that is
a conversion to the definition rhs type, propagate that rhs.
(forward_propagate_addr_expr): Pass single_use_p argument
to forward_propagate_addr_expr_1.
* g++.dg/tree-ssa/pr31146-2.C: New testcase.
Added:
trunk/gcc/testsuite/g++.dg/tree-ssa/pr31146-2.C
Modified:
trunk/gcc/ChangeLog
trunk/gcc/testsuite/ChangeLog
trunk/gcc/tree-ssa-forwprop.c
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31146
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug tree-optimization/31146] forwprop does not look through casts
2007-03-12 12:23 [Bug tree-optimization/31146] New: forwprop does not look through casts rguenth at gcc dot gnu dot org
` (8 preceding siblings ...)
2007-05-02 9:13 ` rguenth at gcc dot gnu dot org
@ 2007-05-02 9:17 ` rguenth at gcc dot gnu dot org
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-05-02 9:17 UTC (permalink / raw)
To: gcc-bugs
------- Comment #10 from rguenth at gcc dot gnu dot org 2007-05-02 10:17 -------
Fixed.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |FIXED
Target Milestone|--- |4.3.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31146
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2007-05-02 9:17 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-12 12:23 [Bug tree-optimization/31146] New: forwprop does not look through casts rguenth at gcc dot gnu dot org
2007-03-12 14:59 ` [Bug tree-optimization/31146] " pinskia at gcc dot gnu dot org
2007-03-12 15:09 ` pinskia at gcc dot gnu dot org
2007-03-12 15:35 ` rguenth at gcc dot gnu dot org
2007-03-12 15:41 ` pinskia at gcc dot gnu dot org
2007-03-12 16:01 ` rguenth at gcc dot gnu dot org
2007-03-16 10:11 ` rguenth at gcc dot gnu dot org
2007-03-20 11:05 ` rguenth at gcc dot gnu dot org
2007-03-20 12:49 ` mueller at gcc dot gnu dot org
2007-05-02 9:13 ` rguenth at gcc dot gnu dot org
2007-05-02 9:17 ` rguenth 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).