Created attachment 31524 [details] Testcase The attached testcase shows how using a naive implementation (mycopy) causes gcc to generate better code than using std::copy. (Clang /does/ generate optimal code when using std::copy in this case.)
(With -O3)
The call to memcpy is folded rather early to: MEM[(char * {ref-all})p_2(D)] = MEM[(char * {ref-all})&a]; and then we don't touch it anymore, maybe because we don't go through an SSA_NAME. We thus miss that the RHS is a constant.
Mine.
Fixed by the patch for PR61473.
Verified that the 61473 fix fixed this as well.