> diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c > index 09ca3590039..0406d5588d2 100644 > --- a/gcc/ipa-pure-const.c > +++ b/gcc/ipa-pure-const.c > @@ -910,7 +910,8 @@ malloc_candidate_p (function *fun, bool ipa) > #define DUMP_AND_RETURN(reason) \ > { \ > if (dump_file && (dump_flags & TDF_DETAILS)) \ > - fprintf (dump_file, "%s", (reason)); \ > + fprintf (dump_file, "\n%s is not a malloc candidate, reason: %s\n", \ > + (node->name()), (reason)); \ > return false; \ > } > > @@ -961,11 +962,14 @@ malloc_candidate_p (function *fun, bool ipa) > for (unsigned i = 0; i < gimple_phi_num_args (phi); ++i) > { > tree arg = gimple_phi_arg_def (phi, i); > + if (arg == null_pointer_node) > + continue;
I think you want operand_equal_p here and also check for flag_delete_null_pointer_checks because otherwise 0 can be legal memory block addrss. > + > if (TREE_CODE (arg) != SSA_NAME) > - DUMP_AND_RETURN("phi arg is not SSA_NAME.") > - if (!(arg == null_pointer_node || check_retval_uses (arg, phi))) > - DUMP_AND_RETURN("phi arg has uses outside phi" > - " and comparisons against 0.") > + 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.") So the case of phi(0,0) is not really correctness issue just missed optimization? I would still add code to handle it (it is easy). Do you also handle a case where parameter of phi is another phi? Honza > > gimple *arg_def = SSA_NAME_DEF_STMT (arg); > gcall *call_stmt = dyn_cast<gcall *> (arg_def); > diff --git a/gcc/testsuite/gcc.dg/ipa/pr83648.c > b/gcc/testsuite/gcc.dg/ipa/pr83648.c > new file mode 100644 > index 00000000000..03b45de671b > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/ipa/pr83648.c > @@ -0,0 +1,9 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-local-pure-const-details" } */ > + > +void *g(unsigned n) > +{ > + return n ? __builtin_malloc (n) : 0; > +} > + > +/* { dg-final { scan-tree-dump "Function found to be malloc: g" > "local-pure-const1" } } */