https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70701
Bug ID: 70701
Summary: incomplete value numbering when memcpy-ing from array
Product: gcc
Version: 6.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: glisse at gcc dot gnu.org
Target Milestone: ---
Looking at PR58483 (seems more relevant than PR62156), I tried this simple
testcase:
int a[]={1,2,3};
int f(){
// a[0]=42;
int*b=__builtin_malloc(12);
__builtin_memcpy(b,a,12);
return b[0];
}
Compiling with -O3 -fdisable-tree-forwprop1 -fdisable-tree-forwprop2
-fdisable-tree-forwprop3 (otherwise forwprop turns memcpy into a MEM
assignment), we fail to optimize b[0] to 1. We do go through the memcpy path in
vn_reference_lookup_3 and that part seems to work fine, but then that's it, we
don't grab the value. If I add a statement a[0]=42; at the beginning of the
function, then we do get that value in FRE1.