]> gcc.gnu.org Git - gcc.git/commitdiff
Don't use PHI equivalences in range-on-entry.
authorAndrew MacLeod <amacleod@redhat.com>
Fri, 16 Dec 2022 21:53:31 +0000 (16:53 -0500)
committerAndrew MacLeod <amacleod@redhat.com>
Tue, 20 Dec 2022 14:15:23 +0000 (09:15 -0500)
If there is only one argument to a PHI which is defined, an equivalency is
created between the def and the argument.  It is safe to consider the def
equal to the argument, but it is dangerous to assume the argument is also
equivalent to the def as there may be branches which change the range on the
path to the PHI on that argument

This patch avoid using that relation in range-on-entry calculations.

PR tree-optimization/108139
gcc/
* gimple-range-cache.cc (ranger_cache::fill_block_cache): Do not
use equivalences originating from PHIS.

gcc/testsuite/
* gcc.dg/pr108139.c: New.

gcc/gimple-range-cache.cc
gcc/testsuite/gcc.dg/pr108139.c [new file with mode: 0644]

index ce5a0c8155e6716f1eda0b38d7e5405e6f10667a..9848d140242f7137325bbb8df06f78e70b31063e 100644 (file)
@@ -1235,6 +1235,13 @@ ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb)
              if (!m_gori.has_edge_range_p (equiv_name))
                continue;
 
+             // PR 108139. It is hazardous to assume an equivalence with
+             // a PHI is the same value.  The PHI may be an equivalence
+             // via UNDEFINED arguments which is really a one way equivalence.
+             // PHIDEF == name, but name may not be == PHIDEF.
+             if (is_a<gphi *> (SSA_NAME_DEF_STMT (equiv_name)))
+               continue;
+
              // Check if the equiv definition dominates this block
              if (equiv_bb == bb ||
                  (equiv_bb && !dominated_by_p (CDI_DOMINATORS, bb, equiv_bb)))
diff --git a/gcc/testsuite/gcc.dg/pr108139.c b/gcc/testsuite/gcc.dg/pr108139.c
new file mode 100644 (file)
index 0000000..6f224e3
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile { target int128 } } */
+/* { dg-options "-O1 -ftree-vrp -fdump-tree-vrp" } */
+
+int a, b;
+int main() {
+  int c;
+  if (a > 1)
+    a++;
+  while (a)
+    if (c == b)
+      c = a;
+  return 0;
+}
+
+
+/* { dg-final { scan-tree-dump-not "Folding predicate" "vrp2" } } */
+
+
This page took 0.077115 seconds and 5 git commands to generate.