From: Richard Biener Date: Tue, 4 Jul 2023 10:52:27 +0000 (+0200) Subject: tree-optimization/110491 - PHI-OPT and undefs X-Git-Tag: basepoints/gcc-15~7843 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=819285ef10a87d663f8c181c06aa88d1d9f75aed;p=thirdparty%2Fgcc.git tree-optimization/110491 - PHI-OPT and undefs The following makes sure to not make conditional undefs in PHI arguments unconditional by folding cond ? arg1 : arg2. PR tree-optimization/110491 * tree-ssa-phiopt.cc (match_simplify_replacement): Check whether the PHI args are possibly undefined before folding the COND_EXPR. * gcc.dg/torture/pr110491.c: New testcase. --- diff --git a/gcc/testsuite/gcc.dg/torture/pr110491.c b/gcc/testsuite/gcc.dg/torture/pr110491.c new file mode 100644 index 000000000000..00b3bdfc122e --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr110491.c @@ -0,0 +1,29 @@ +/* { dg-do run } */ + +int a, c, d, e; +short b; +void f(int *g) { c &= *g; } +void h(void); +void i() { + a = 1; + h(); + f(&a); +} +void h() { + int *j = &c; + *j = 5; +k: + for (; 4 + b <= 0;) + ; + for (; d;) { + c = e == 0; + goto k; + } +} +int main() +{ + i(); + if (c != 1) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index 31a7c39e4052..467c9fd108a8 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -785,6 +785,13 @@ match_simplify_replacement (basic_block cond_bb, basic_block middle_bb, arg_false = arg0; } + /* Do not make conditional undefs unconditional. */ + if ((TREE_CODE (arg_true) == SSA_NAME + && ssa_name_maybe_undef_p (arg_true)) + || (TREE_CODE (arg_false) == SSA_NAME + && ssa_name_maybe_undef_p (arg_false))) + return false; + tree type = TREE_TYPE (gimple_phi_result (phi)); result = gimple_simplify_phiopt (early_p, type, stmt, arg_true, arg_false,