cond_store_replacement_limited mistaken a clobber for a store, meaning
that it would use {CLOBBER(eos)} as a phi argument.

So this fixes that issue by rejecting that case.

Pushed as obvious after bootstrap/test on x86_64-linux-gnu.

        PR tree-optimization/126569

gcc/ChangeLog:

        * tree-ssa-phiopt.cc (cond_store_replacement_limited): A
        clobber is not a store.

gcc/testsuite/ChangeLog:

        * gcc.dg/pr126569-1.c: New test.

Signed-off-by: Andrea Pinski <[email protected]>
---
 gcc/testsuite/gcc.dg/pr126569-1.c | 20 ++++++++++++++++++++
 gcc/tree-ssa-phiopt.cc            |  2 ++
 2 files changed, 22 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/pr126569-1.c

diff --git a/gcc/testsuite/gcc.dg/pr126569-1.c 
b/gcc/testsuite/gcc.dg/pr126569-1.c
new file mode 100644
index 00000000000..5e2348c2ff1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr126569-1.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-O2  -fno-tree-dce -fno-tree-dse" } */
+/* PR tree-optimization/126569 */
+
+int wx, qi, gw, ak;
+
+void
+f (void)
+{
+  while (wx)
+    {
+      int k2 = ak;
+    ja:
+      *(int **) &k2 = &gw;
+      while (qi)
+        ++qi;
+    }
+  gw = 1;
+  goto ja;
+}
diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index 2ff26bfab73..d63a47cc615 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -3683,6 +3683,8 @@ cond_store_replacement_limited (basic_block middle_bb, 
basic_block join_bb,
       tree beforelhs = gimple_assign_lhs (vdef_before);
       /* Only allow the store to be right before the condition.  */
       if (gimple_bb (vdef_before) == cond_bb
+         /* This can't be a clobber */
+         && !gimple_clobber_p (vdef_before)
          /* An exact match is only supported.
             FIXME: Allow for clique/base mismatch?  */
          && operand_equal_p (lhs, beforelhs))
-- 
2.43.0

Reply via email to