aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2021-03-22 11:09:46 +0100
committerRichard Biener <rguenther@suse.de>2021-03-22 14:37:26 +0100
commitb931e4792b8696f3da69f70988720c4d1ec6142a (patch)
treea666bbbf3e9d9ea76035565ddb390247569e4354
parentc4519fe3db366d781f342b7f04c4a09e4cc9fbd9 (diff)
downloadgcc-b931e4792b8696f3da69f70988720c4d1ec6142a.zip
gcc-b931e4792b8696f3da69f70988720c4d1ec6142a.tar.gz
gcc-b931e4792b8696f3da69f70988720c4d1ec6142a.tar.bz2
tree-optimization/99694 - fix value-numbering PHIs
This avoids endless cycling when a PHI node with unchanged backedge value (the PHI result appearing there) is subject to CSE since doing that effectively alters the hash entry. The way to avoid this is to ignore such edges when processing the PHI node. 2021-03-22 Richard Biener <rguenther@suse.de> PR tree-optimization/99694 * tree-ssa-sccvn.c (visit_phi): Ignore edges with the PHI result. * gcc.dg/torture/pr99694.c: New testcase.
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr99694.c27
-rw-r--r--gcc/tree-ssa-sccvn.c2
2 files changed, 29 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/torture/pr99694.c b/gcc/testsuite/gcc.dg/torture/pr99694.c
new file mode 100644
index 0000000..df31696
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr99694.c
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-w" } */
+
+#include <stdint.h>
+
+int a, b, c;
+void d() {
+ uint16_t e;
+ int32_t *f;
+ int32_t *g;
+ if (a) {
+ int32_t *k;
+ for (;; *k += 1) {
+ int32_t **i = &f;
+ int32_t **l = &g;
+ for (e = 6; e; e++) {
+ g = k = f;
+ j:
+ **l = 0;
+ }
+ *i = c;
+ }
+ }
+ uint16_t i = &e;
+ b = i / 0;
+ goto j;
+}
diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c
index 99759a8..1c0500c 100644
--- a/gcc/tree-ssa-sccvn.c
+++ b/gcc/tree-ssa-sccvn.c
@@ -5199,6 +5199,8 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p)
{
tree def = PHI_ARG_DEF_FROM_EDGE (phi, e);
+ if (def == PHI_RESULT (phi))
+ continue;
++n_executable;
if (TREE_CODE (def) == SSA_NAME)
{