From bec3ee81e3c60bc4e8001871ede2b0b07ff417f1 Mon Sep 17 00:00:00 2001 From: Prathamesh Kulkarni Date: Fri, 18 May 2018 12:31:04 +0000 Subject: [PATCH] re PR middle-end/85817 (ICE in expand_call at gcc/calls.c:4291) 2018-05-18 Prathamesh Kulkarni PR middle-end/85817 * ipa-pure-const.c (malloc_candidate_p): Remove the check integer_zerop for retval and return false if all args to phi are zero. testsuite/ * gcc.dg/tree-ssa/pr83648.c: Change scan-tree-dump to scan-tree-dump-not for h. From-SVN: r260358 --- gcc/ChangeLog | 6 +++ gcc/ipa-pure-const.c | 70 +++++++++++++------------ gcc/testsuite/ChangeLog | 6 +++ gcc/testsuite/gcc.dg/tree-ssa/pr83648.c | 2 +- 4 files changed, 50 insertions(+), 34 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4795777850b..479b032c040 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-05-18 Prathamesh Kulkarni + + PR middle-end/85817 + * ipa-pure-const.c (malloc_candidate_p): Remove the check integer_zerop + for retval and return false if all args to phi are zero. + 2018-05-18 Richard Biener * gimple-ssa-evrp.c (class evrp_folder): Add simplify_stmt_using_ranges diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c index 567b615fb60..528ea6695ac 100644 --- a/gcc/ipa-pure-const.c +++ b/gcc/ipa-pure-const.c @@ -940,9 +940,6 @@ malloc_candidate_p (function *fun, bool ipa) if (!retval) DUMP_AND_RETURN("No return value.") - if (integer_zerop (retval)) - continue; - if (TREE_CODE (retval) != SSA_NAME || TREE_CODE (TREE_TYPE (retval)) != POINTER_TYPE) DUMP_AND_RETURN("Return value is not SSA_NAME or not a pointer type.") @@ -972,37 +969,44 @@ malloc_candidate_p (function *fun, bool ipa) } else if (gphi *phi = dyn_cast (def)) - for (unsigned i = 0; i < gimple_phi_num_args (phi); ++i) - { - tree arg = gimple_phi_arg_def (phi, i); - if (integer_zerop (arg)) - continue; + { + bool all_args_zero = true; + for (unsigned i = 0; i < gimple_phi_num_args (phi); ++i) + { + tree arg = gimple_phi_arg_def (phi, i); + if (integer_zerop (arg)) + continue; + + all_args_zero = false; + if (TREE_CODE (arg) != SSA_NAME) + DUMP_AND_RETURN ("phi arg is not SSA_NAME."); + if (!check_retval_uses (arg, phi)) + DUMP_AND_RETURN ("phi arg has uses outside phi" + " and comparisons against 0.") + + gimple *arg_def = SSA_NAME_DEF_STMT (arg); + gcall *call_stmt = dyn_cast (arg_def); + if (!call_stmt) + return false; + tree callee_decl = gimple_call_fndecl (call_stmt); + if (!callee_decl) + return false; + if (!ipa && !DECL_IS_MALLOC (callee_decl)) + DUMP_AND_RETURN("callee_decl does not have malloc attribute" + " for non-ipa mode.") + + cgraph_edge *cs = node->get_edge (call_stmt); + if (cs) + { + ipa_call_summary *es = ipa_call_summaries->get (cs); + gcc_assert (es); + es->is_return_callee_uncaptured = true; + } + } - if (TREE_CODE (arg) != SSA_NAME) - DUMP_AND_RETURN ("phi arg is not SSA_NAME."); - if (!check_retval_uses (arg, phi)) - DUMP_AND_RETURN ("phi arg has uses outside phi" - " and comparisons against 0.") - - gimple *arg_def = SSA_NAME_DEF_STMT (arg); - gcall *call_stmt = dyn_cast (arg_def); - if (!call_stmt) - return false; - tree callee_decl = gimple_call_fndecl (call_stmt); - if (!callee_decl) - return false; - if (!ipa && !DECL_IS_MALLOC (callee_decl)) - DUMP_AND_RETURN("callee_decl does not have malloc attribute for" - " non-ipa mode.") - - cgraph_edge *cs = node->get_edge (call_stmt); - if (cs) - { - ipa_call_summary *es = ipa_call_summaries->get (cs); - gcc_assert (es); - es->is_return_callee_uncaptured = true; - } - } + if (all_args_zero) + DUMP_AND_RETURN ("Return value is a phi with all args equal to 0."); + } else DUMP_AND_RETURN("def_stmt of return value is not a call or phi-stmt.") diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 185ce2fb6c3..cbd2266c498 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-05-18 Prathamesh Kulkarni + + PR middle-end/85817 + * gcc.dg/tree-ssa/pr83648.c: Change scan-tree-dump to + scan-tree-dump-not for h. + 2018-05-18 Richard Biener * gcc.dg/tree-ssa/pr21559.c: Adjust. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr83648.c b/gcc/testsuite/gcc.dg/tree-ssa/pr83648.c index febfd7d9319..884faf81167 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/pr83648.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr83648.c @@ -12,4 +12,4 @@ void *h() } /* { dg-final { scan-tree-dump "Function found to be malloc: g" "local-pure-const1" } } */ -/* { dg-final { scan-tree-dump "Function found to be malloc: h" "local-pure-const1" } } */ +/* { dg-final { scan-tree-dump-not "Function found to be malloc: h" "local-pure-const1" } } */ -- 2.30.2