tree-optimization/101394 - fix PRE full redundancy wrt abnormals
authorRichard Biener <rguenther@suse.de>
Mon, 12 Jul 2021 08:49:03 +0000 (10:49 +0200)
committerRichard Biener <rguenther@suse.de>
Mon, 12 Jul 2021 10:18:37 +0000 (12:18 +0200)
This avoids adding a copy from an abnormal picked up from PHI
translation much like we'd avoid inserting the translated
expression on pred edges.

2021-07-12  Richard Biener  <rguenther@suse.de>

PR tree-optimization/101394
* tree-ssa-pre.c (do_pre_regular_insertion): Avoid inserting
copies from abnormals for a full redundancy.

* gcc.dg/torture/pr101394.c: New testcase.

gcc/testsuite/gcc.dg/torture/pr101394.c [new file with mode: 0644]
gcc/tree-ssa-pre.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr101394.c b/gcc/testsuite/gcc.dg/torture/pr101394.c
new file mode 100644 (file)
index 0000000..87fbdad
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+
+int a, b, c, d;
+void h();
+int e() __attribute__((returns_twice));
+void f() {
+  int *g = (int *)(__INTPTR_TYPE__)c;
+  if (b) {
+    h();
+    g--;
+    if (a)
+      if (d)
+        h();
+  }
+  if (g++)
+    e();
+  c = (__INTPTR_TYPE__)g;
+}
index d86fe26..69141c2 100644 (file)
@@ -3412,7 +3412,11 @@ do_pre_regular_insertion (basic_block block, basic_block dom,
          /* If all edges produce the same value and that value is
             an invariant, then the PHI has the same value on all
             edges.  Note this.  */
-         else if (!cant_insert && all_same)
+         else if (!cant_insert
+                  && all_same
+                  && (edoubleprime->kind != NAME
+                      || !SSA_NAME_OCCURS_IN_ABNORMAL_PHI
+                            (PRE_EXPR_NAME (edoubleprime))))
            {
              gcc_assert (edoubleprime->kind == CONSTANT
                          || edoubleprime->kind == NAME);