Bug 59611 - std::copy performs worse than naive implementation when copying a single known byte
Summary: std::copy performs worse than naive implementation when copying a single know...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: ---
Assignee: Richard Biener
URL:
Keywords: missed-optimization
Depends on: 61473
Blocks:
  Show dependency treegraph
 
Reported: 2013-12-27 16:55 UTC by Eelis
Modified: 2014-07-14 11:50 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-12-27 00:00:00


Attachments
Testcase (240 bytes, text/x-c++src)
2013-12-27 16:55 UTC, Eelis
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Eelis 2013-12-27 16:55:37 UTC
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.)
Comment 1 Eelis 2013-12-27 16:57:47 UTC
(With -O3)
Comment 2 Marc Glisse 2013-12-27 22:29:42 UTC
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.
Comment 3 Richard Biener 2014-06-26 14:49:03 UTC
Mine.
Comment 4 Richard Biener 2014-06-27 10:40:37 UTC
Fixed by the patch for PR61473.
Comment 5 Richard Biener 2014-07-14 11:50:14 UTC
Verified that the 61473 fix fixed this as well.