tree-optimization/122016 - PRE insertion breaks abnormal coalescing

When PRE asks VN to simplify a NARY but not insert, that bypasses
the abnormal guard in maybe_push_res_to_seq and we blindly accept
new uses of abnormals.  The following fixes this.

	PR tree-optimization/122016
	* tree-ssa-sccvn.cc (vn_nary_simplify): Do not use the
	simplified expression when it references abnormals.

	* gcc.dg/torture/pr122016.c: New testcase.
This commit is contained in:
Richard Biener
2025-09-22 10:14:31 +02:00
committed by Richard Biener
parent 32a8a1c26b
commit 52b53cfb53
2 changed files with 33 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
/* { dg-do compile } */
/* { dg-additional-options "-ftree-pre" } */
int merge_parse_args_argc;
char merge_parse_args_argv_0;
int strncmp(char *, char *, long);
void _setjmp();
typedef enum { FALSE, TRUE } boool;
void directory_exists();
void merge_parse_args() {
int i;
boool help_found = FALSE;
while (i < merge_parse_args_argc && !help_found) {
if (strncmp("", &merge_parse_args_argv_0, 2))
help_found = TRUE;
else {
for (;;) {
_setjmp();
break;
}
i++;
directory_exists();
}
i++;
}
_setjmp();
}

View File

@@ -2622,6 +2622,12 @@ vn_nary_simplify (vn_nary_op_t nary)
nary->type, nary->length);
memcpy (op.ops, nary->op, sizeof (tree) * nary->length);
tree res = vn_nary_build_or_lookup_1 (&op, false, true);
/* Do not update *NARY with a simplified result that contains abnormals.
This matches what maybe_push_res_to_seq does when requesting insertion. */
for (unsigned i = 0; i < op.num_ops; ++i)
if (TREE_CODE (op.ops[i]) == SSA_NAME
&& SSA_NAME_OCCURS_IN_ABNORMAL_PHI (op.ops[i]))
return res;
if (op.code.is_tree_code ()
&& op.num_ops <= nary->length
&& (tree_code) op.code != CONSTRUCTOR)