Commit c2c51a3e by Richard Biener Committed by Richard Biener

re PR tree-optimization/87176 (wrong code at -Os and above on x86-64-linux-gnu)

2018-09-04  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/87176
	* tree-ssa-sccvn.c (visit_phi): Remove redundant allsame
	variable.  When value-numbering a virtual PHI node make sure
	to not value-number to the backedge value.

	* gcc.dg/torture/pr87176.c: New testcase.
	* gcc.dg/torture/ssa-fre-1.c: Likewise.

From-SVN: r264077
parent 727c8c82
2018-09-04 Richard Biener <rguenther@suse.de>
PR tree-optimization/87176
* tree-ssa-sccvn.c (visit_phi): Remove redundant allsame
variable. When value-numbering a virtual PHI node make sure
to not value-number to the backedge value.
2018-09-04 Jonathan Wakely <jwakely@redhat.com> 2018-09-04 Jonathan Wakely <jwakely@redhat.com>
* doc/extend.texi (Long Long, Hex Floats): Document support for * doc/extend.texi (Long Long, Hex Floats): Document support for
......
2018-09-04 Richard Biener <rguenther@suse.de>
PR tree-optimization/87176
* gcc.dg/torture/pr87176.c: New testcase.
* gcc.dg/torture/ssa-fre-1.c: Likewise.
2018-09-03 Jerry DeLisle <jvdelisle@gcc.gnu.org> 2018-09-03 Jerry DeLisle <jvdelisle@gcc.gnu.org>
* gfortran.dg/modulo_check: New test. * gfortran.dg/modulo_check: New test.
......
/* { dg-do run } */
int a, b, c;
int main ()
{
int d = a = 0;
while (1)
{
a = a ^ 6;
if (!a)
break;
if (d)
goto L;
d = a;
for (b = 0; b < 2; b++)
{
const int *f[3] = { &c };
const int **g[] = { &f[2] };
int h = ~d;
if (d)
L:
if (h > 1)
continue;
}
}
return 0;
}
/* { dg-do compile } */
/* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */
/* { dg-additional-options "-fstrict-aliasing -fdump-tree-fre1" } */
float f;
int foo(int *p, int *q)
{
*p = 0;
if (*p)
*q = 1;
else
f = 8.0f;
return *p;
}
/* { dg-final { scan-tree-dump "return 0;" "fre1" } } */
...@@ -4110,11 +4110,11 @@ static bool ...@@ -4110,11 +4110,11 @@ static bool
visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p) visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p)
{ {
tree result, sameval = VN_TOP, seen_undef = NULL_TREE; tree result, sameval = VN_TOP, seen_undef = NULL_TREE;
tree backedge_name = NULL_TREE; tree backedge_val = NULL_TREE;
bool seen_non_backedge = false;
tree sameval_base = NULL_TREE; tree sameval_base = NULL_TREE;
poly_int64 soff, doff; poly_int64 soff, doff;
unsigned n_executable = 0; unsigned n_executable = 0;
bool allsame = true;
edge_iterator ei; edge_iterator ei;
edge e; edge e;
...@@ -4139,11 +4139,13 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p) ...@@ -4139,11 +4139,13 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p)
++n_executable; ++n_executable;
if (TREE_CODE (def) == SSA_NAME) if (TREE_CODE (def) == SSA_NAME)
{ {
if (e->flags & EDGE_DFS_BACK)
backedge_name = def;
if (!backedges_varying_p || !(e->flags & EDGE_DFS_BACK)) if (!backedges_varying_p || !(e->flags & EDGE_DFS_BACK))
def = SSA_VAL (def); def = SSA_VAL (def);
if (e->flags & EDGE_DFS_BACK)
backedge_val = def;
} }
if (!(e->flags & EDGE_DFS_BACK))
seen_non_backedge = true;
if (def == VN_TOP) if (def == VN_TOP)
; ;
/* Ignore undefined defs for sameval but record one. */ /* Ignore undefined defs for sameval but record one. */
...@@ -4172,16 +4174,25 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p) ...@@ -4172,16 +4174,25 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p)
&& known_eq (soff, doff)) && known_eq (soff, doff))
continue; continue;
} }
allsame = false; sameval = NULL_TREE;
break; break;
} }
} }
/* If the value we want to use is the backedge and that wasn't visited /* If the value we want to use is the backedge and that wasn't visited
yet drop to VARYING. */ yet drop to VARYING. This only happens when not iterating.
if (backedge_name If we value-number a virtual operand never value-number to the
&& sameval == backedge_name value from the backedge as that confuses the alias-walking code.
&& !SSA_VISITED (backedge_name)) See gcc.dg/torture/pr87176.c. If the value is the same on a
non-backedge everything is OK though. */
if (backedge_val
&& !seen_non_backedge
&& TREE_CODE (backedge_val) == SSA_NAME
&& sameval == backedge_val
&& (SSA_NAME_IS_VIRTUAL_OPERAND (backedge_val)
|| !SSA_VISITED (backedge_val)))
/* Note this just drops to VARYING without inserting the PHI into
the hashes. */
result = PHI_RESULT (phi); result = PHI_RESULT (phi);
/* If none of the edges was executable keep the value-number at VN_TOP, /* If none of the edges was executable keep the value-number at VN_TOP,
if only a single edge is exectuable use its value. */ if only a single edge is exectuable use its value. */
...@@ -4212,7 +4223,7 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p) ...@@ -4212,7 +4223,7 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p)
/* If all values are the same use that, unless we've seen undefined /* If all values are the same use that, unless we've seen undefined
values as well and the value isn't constant. values as well and the value isn't constant.
CCP/copyprop have the same restriction to not remove uninit warnings. */ CCP/copyprop have the same restriction to not remove uninit warnings. */
else if (allsame else if (sameval
&& (! seen_undef || is_gimple_min_invariant (sameval))) && (! seen_undef || is_gimple_min_invariant (sameval)))
result = sameval; result = sameval;
else else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment