]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
phiopt: Set cfgchanged if cselim-limited happened
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Thu, 16 Apr 2026 21:26:43 +0000 (14:26 -0700)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Sat, 2 May 2026 21:40:34 +0000 (14:40 -0700)
I noticed while improving cselim-limited that if
not creating a new phi, there are a few empty basic blocks.
So this sets cfgcleanup when cselim-limited does
something in phiopt. cselim-5.c shows the case I
was looking into.

gcc/ChangeLog:

* tree-ssa-phiopt.cc (pass_phiopt::execute): Set cfgcleanup
if cselim_limited returns true.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/cselim-5.c: New test.

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

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/cselim-5.c b/gcc/testsuite/gcc.dg/tree-ssa/cselim-5.c
new file mode 100644 (file)
index 0000000..8d1335f
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-phiopt1" } */
+
+int t;
+void f(int a, int b, int c, int d)
+{
+  if (b)
+   t = 0;
+  else
+   t = 0;
+}
+
+/* We should sink/merge the stores and end up with a single BB.  */
+
+/* { dg-final { scan-tree-dump-times "t = 0;" 1 "phiopt1" } } */
+/* { dg-final { scan-tree-dump-times "<bb " 1 "phiopt1" } } */
index 0bf7e58b8f030f9f69edd7b27c21654d778aea03..324559e6a7deee1862225bbed369743215dc53b6 100644 (file)
@@ -4048,10 +4048,11 @@ pass_phiopt::execute (function *)
            hoist_adjacent_loads (bb, bb1, bb2, bb3);
 
          /* Try to see if there are only store in each side of the if
-            and try to remove that; don't do this for -Og.  */
+            and try to remove that; don't do this for -Og.
+            With sinking the stores we might end up with empty blocks.  */
          if (EDGE_COUNT (bb3->preds) == 2 && !optimize_debug)
            while (cond_if_else_store_replacement_limited (bb1, bb2, bb3))
-             ;
+             cfgchanged = true;
        }
 
       gimple_stmt_iterator gsi;