phiopt: Set cfgchanged if cselim-limited happened

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>
This commit is contained in:
Andrew Pinski
2026-04-16 14:26:43 -07:00
parent 357207648f
commit 891ea0b202
2 changed files with 19 additions and 2 deletions

View File

@@ -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" } } */

View 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;