https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90401
Bug ID: 90401 Summary: Missed propagation of by-ref constant argument to callee function Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: ipa Assignee: unassigned at gcc dot gnu.org Reporter: fxue at os dot amperecomputing.com CC: marxin at gcc dot gnu.org Target Milestone: --- Created attachment 46318 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46318&action=edit The case that ipa_cp is failed on by_ref constant argument IPA-cp can not identify a constant by-ref argument to a function, if value definition of the argument is not in same basic block where the callsite lies in. In Fortran, this is very common that a constant function argument is placed in a local variable instead of literal constant. The following is a C++ case, compiling option is "-O3 -fno-inline", here using "-fno-inline" to give a change for ipa-cp on small function. If we move the statement "int a = 1" from inside conditional block to begin of function, ipa-cp fails to do function versioning on "callee()". int data; int callee(int &v) { if (v < 2) { return 0; } else { data = v; return 1; } } int caller(int c, int &r) { // int a = 1; <----. /* ipa-cp on callee(), failed */ | if (c) { | // int a = 1; -----' /* ipa-cp on callee(), ok */ return callee(a); } else { r = 1; return callee(r); } }