]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
phiprop: Fix speculating aggregate copies [PR124746]
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Wed, 1 Apr 2026 17:43:17 +0000 (10:43 -0700)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Thu, 2 Apr 2026 13:45:23 +0000 (06:45 -0700)
r16-5555-g952e145796da0f introduced a problem for aggregates.
Allowing speculating non-trapping loads is ok but allowing
speculating non-trapping aggregate copies is not valid as
there is no ssa renaming for the lhs. So for aggregates,
we need to treat it similar as a trapping load to find if
it is speculating. Since we already reject 'delayed' loads
for aggregates, we will skip over this load.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/124746
gcc/ChangeLog:

* tree-ssa-phiprop.cc (propagate_with_phi): Treat
and aggregate copy as it is a trapping load.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr124746-1.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
gcc/testsuite/gcc.dg/tree-ssa/pr124746-1.c [new file with mode: 0644]
gcc/tree-ssa-phiprop.cc

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr124746-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr124746-1.c
new file mode 100644 (file)
index 0000000..27ddce6
--- /dev/null
@@ -0,0 +1,37 @@
+/* { dg-do run } */
+/* { dg-options "-O2 -fno-tree-fre -fdump-tree-phiprop-details" } */
+
+/* PR tree-optimization/124746 */
+
+struct a {
+  int b;
+} c, e = {1}, f;
+int d, g, j, *k = &d, n;
+static int i;
+static struct a *h = &e;
+int main() {
+  for (; n < 1; n++) {
+    int l;
+    struct a *m = &c;
+  L:
+    if (k) {
+      d = l = 0;
+      for (; l < 1; l++) {
+        j = i;
+        if (j) {
+          struct a **o = &m;
+          if (g)
+            goto L;
+          *o = &f;
+        }
+      }
+    } else
+      *h = *m;
+  }
+  if (e.b != 1)
+    __builtin_abort();
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-not "Inserting PHI for result of load e =" "phiprop2" } }  */
+
index ca8c7cfe04d0b0ea7adc0329e50727805e1d21e2..668a302597c065ad9332796e384c72095564fc11 100644 (file)
@@ -358,13 +358,18 @@ propagate_with_phi (basic_block bb, gphi *vphi, gphi *phi,
            && !gimple_has_volatile_ops (use_stmt)))
        continue;
 
-      if (canpossible_trap
+      bool aggregate = false;
+      if (!is_gimple_reg_type (TREE_TYPE (gimple_assign_lhs (use_stmt))))
+       aggregate = true;
+
+      if ((canpossible_trap || aggregate)
          && !dom_info_available_p (cfun, CDI_POST_DOMINATORS))
        calculate_dominance_info (CDI_POST_DOMINATORS);
 
       /* Only replace loads in blocks that post-dominate the PHI node.  That
-        makes sure we don't end up speculating trapping loads.  */
-      if (canpossible_trap
+        makes sure we don't end up speculating trapping loads or
+        aggregate stores won't happen speculating.  */
+      if ((canpossible_trap || aggregate)
          && !dominated_by_p (CDI_POST_DOMINATORS,
                              bb, gimple_bb (use_stmt)))
        delay = true;
@@ -409,7 +414,7 @@ propagate_with_phi (basic_block bb, gphi *vphi, gphi *phi,
 
       /* Found a proper dereference with an aggregate copy.  Just
          insert aggregate copies on the edges instead.  */
-      if (!is_gimple_reg_type (TREE_TYPE (gimple_assign_lhs (use_stmt))))
+      if (aggregate)
        {
          /* aggregate copies are too hard to handled if delayed.  */
          if (delay)