public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-4625] bootstrap/102681 - properly CSE PHIs with default def args
@ 2021-10-22 9:41 Richard Biener
0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2021-10-22 9:41 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:fe8475c500939011b90504304aec61bf6f48ac7d
commit r12-4625-gfe8475c500939011b90504304aec61bf6f48ac7d
Author: Richard Biener <rguenther@suse.de>
Date: Fri Oct 22 10:32:36 2021 +0200
bootstrap/102681 - properly CSE PHIs with default def args
The PR shows that we fail to CSE PHIs containing (different)
default definitions due to the fact on how we now handle
on-demand build of VN_INFO. The following fixes this in the
same way the PHI visitation code does.
On gcc.dg/ubsan/pr81981.c this causes one expected warning to be
elided since the uninit pass sees the change
<bb 4> [local count: 1073741824]:
# u$0_2 = PHI <u$0_5(D)(3), i_3(D)(5)>
- # cstore_11 = PHI <t$0_6(D)(3), i_3(D)(5)>
v = u$0_2;
- return cstore_11;
+ return u$0_2;
and thus only one of the conditionally uninitialized uses (the
other became dead). I have XFAILed the missing diagnostic,
I don't see a way to preserve that.
2021-10-22 Richard Biener <rguenther@suse.de>
PR bootstrap/102681
* tree-ssa-sccvn.c (vn_phi_insert): For undefined SSA args
record VN_TOP.
(vn_phi_lookup): Likewise.
* gcc.dg/tree-ssa/ssa-fre-97.c: New testcase.
* gcc.dg/ubsan/pr81981.c: XFAIL one case.
Diff:
---
gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-97.c | 19 +++++++++++++++++++
gcc/testsuite/gcc.dg/ubsan/pr81981.c | 2 +-
gcc/tree-ssa-sccvn.c | 14 ++++++++++++--
3 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-97.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-97.c
new file mode 100644
index 00000000000..2f09c8baeb8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-97.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* ethread threading does not yet catch this but it might at some point. */
+/* { dg-options "-O -fdump-tree-fre1-details -fno-thread-jumps" } */
+
+int foo (int b, int x)
+{
+ int i, j;
+ if (b)
+ i = x;
+ if (b)
+ j = x;
+ return j == i;
+}
+
+/* Even with different undefs we should CSE a PHI node with the
+ same controlling condition. */
+
+/* { dg-final { scan-tree-dump "Replaced redundant PHI node" "fre1" } } */
+/* { dg-final { scan-tree-dump "return 1;" "fre1" } } */
diff --git a/gcc/testsuite/gcc.dg/ubsan/pr81981.c b/gcc/testsuite/gcc.dg/ubsan/pr81981.c
index 8a6597c84c8..d201efb3f65 100644
--- a/gcc/testsuite/gcc.dg/ubsan/pr81981.c
+++ b/gcc/testsuite/gcc.dg/ubsan/pr81981.c
@@ -16,6 +16,6 @@ foo (int i)
u[0] = i;
}
- v = u[0]; /* { dg-warning "may be used uninitialized" } */
+ v = u[0]; /* { dg-warning "may be used uninitialized" "" { xfail *-*-* } } */
return t[0]; /* { dg-warning "may be used uninitialized" } */
}
diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c
index ae0172a143e..893b1d0ddaa 100644
--- a/gcc/tree-ssa-sccvn.c
+++ b/gcc/tree-ssa-sccvn.c
@@ -4499,7 +4499,12 @@ vn_phi_lookup (gimple *phi, bool backedges_varying_p)
tree def = PHI_ARG_DEF_FROM_EDGE (phi, e);
if (TREE_CODE (def) == SSA_NAME
&& (!backedges_varying_p || !(e->flags & EDGE_DFS_BACK)))
- def = SSA_VAL (def);
+ {
+ if (ssa_undefined_value_p (def, false))
+ def = VN_TOP;
+ else
+ def = SSA_VAL (def);
+ }
vp1->phiargs[e->dest_idx] = def;
}
vp1->type = TREE_TYPE (gimple_phi_result (phi));
@@ -4543,7 +4548,12 @@ vn_phi_insert (gimple *phi, tree result, bool backedges_varying_p)
tree def = PHI_ARG_DEF_FROM_EDGE (phi, e);
if (TREE_CODE (def) == SSA_NAME
&& (!backedges_varying_p || !(e->flags & EDGE_DFS_BACK)))
- def = SSA_VAL (def);
+ {
+ if (ssa_undefined_value_p (def, false))
+ def = VN_TOP;
+ else
+ def = SSA_VAL (def);
+ }
vp1->phiargs[e->dest_idx] = def;
}
vp1->value_id = VN_INFO (result)->value_id;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-10-22 9:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-22 9:41 [gcc r12-4625] bootstrap/102681 - properly CSE PHIs with default def args Richard Biener
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).