On 01/02/2018 11:03 PM, Prathamesh Kulkarni wrote: > Hi, > malloc_candidate_p() in ipa-pure-const misses detecting that a > function is malloc-like if the return value is result of PHI and one > of the arguments of PHI is 0. > For example: > > void g(unsigned n) > { > return (n) ? __builtin_malloc (n) : 0; > } > > The reason is that the following check: > if (TREE_CODE (arg) != SSA_NAME) > DUMP_AND_RETURN ("phi arg is not SSA_NAME.") > > fails for arg with constant value 0 and malloc_candidate_p returns false. > The patch simply skips the arg if it equals null_pointer_node. > Does it look OK ? > > One concern I have is that with the patch, malloc_candidate_p will > return true if all the args to PHI are NULL: > retval = PHI<0, 0> > return retval > > However I expect that PHI with all 0 args would be constant folded to > 0 earlier, so this case shouldn't occur in practice ? > > Bootstrapped+tested on x86_64-unknown-linux-gnu. > Cross-testing on arm*-*-* and aarch64*-*-* in progress. A degenerate PHI should be folded/propagated, but you can't absolutely depend on it -- ie, you must handle it gracefully.
I think the way to do that here is verify that at least one argument is an SSA_NAME. jeff