aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2024-05-15 13:06:30 +0200
committerRichard Biener <rguenther@suse.de>2024-05-15 18:10:52 +0200
commitab25eef36400e8c1d28e3ed059c5f95a38b45f17 (patch)
tree4488be857344657b4e503ecc888c2b9687546ecf
parent680af0e1e90d4b80260d173636dfe15654fd470d (diff)
downloadgcc-ab25eef36400e8c1d28e3ed059c5f95a38b45f17.zip
gcc-ab25eef36400e8c1d28e3ed059c5f95a38b45f17.tar.gz
gcc-ab25eef36400e8c1d28e3ed059c5f95a38b45f17.tar.bz2
middle-end/111422 - wrong stack var coalescing, handle PHIs
The gcc.c-torture/execute/pr111422.c testcase after installing the sink pass improvement reveals that we also need to handle _65 = &g + _58; _44 = &g + _43; # _59 = PHI <_65, _44> *_59 = 8; g = {v} {CLOBBER(eos)}; ... n[0] = &f; *_59 = 8; g = {v} {CLOBBER(eos)}; where we fail to see the conflict between n and g after the first clobber of g. Before the sinking improvement there was a conflict recorded on a path where _65/_44 are unused, so the real conflict was missed but the fake one avoided the miscompile. The following handles PHI defs in add_scope_conflicts_2 which fixes the issue. PR middle-end/111422 * cfgexpand.cc (add_scope_conflicts_2): Handle PHIs by recursing to their arguments.
-rw-r--r--gcc/cfgexpand.cc19
1 files changed, 15 insertions, 4 deletions
diff --git a/gcc/cfgexpand.cc b/gcc/cfgexpand.cc
index 557cb28..8de5f2b 100644
--- a/gcc/cfgexpand.cc
+++ b/gcc/cfgexpand.cc
@@ -584,10 +584,21 @@ add_scope_conflicts_2 (tree use, bitmap work,
|| INTEGRAL_TYPE_P (TREE_TYPE (use))))
{
gimple *g = SSA_NAME_DEF_STMT (use);
- if (is_gimple_assign (g))
- if (tree op = gimple_assign_rhs1 (g))
- if (TREE_CODE (op) == ADDR_EXPR)
- visit (g, TREE_OPERAND (op, 0), op, work);
+ if (gassign *a = dyn_cast <gassign *> (g))
+ {
+ if (tree op = gimple_assign_rhs1 (a))
+ if (TREE_CODE (op) == ADDR_EXPR)
+ visit (a, TREE_OPERAND (op, 0), op, work);
+ }
+ else if (gphi *p = dyn_cast <gphi *> (g))
+ for (unsigned i = 0; i < gimple_phi_num_args (p); ++i)
+ if (TREE_CODE (use = gimple_phi_arg_def (p, i)) == SSA_NAME)
+ if (gassign *a = dyn_cast <gassign *> (SSA_NAME_DEF_STMT (use)))
+ {
+ if (tree op = gimple_assign_rhs1 (a))
+ if (TREE_CODE (op) == ADDR_EXPR)
+ visit (a, TREE_OPERAND (op, 0), op, work);
+ }
}
}