This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/57742] New: memset(malloc(n),0,n) -> calloc(n,1)
- From: "glisse at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 27 Jun 2013 22:28:37 +0000
- Subject: [Bug tree-optimization/57742] New: memset(malloc(n),0,n) -> calloc(n,1)
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57742
Bug ID: 57742
Summary: memset(malloc(n),0,n) -> calloc(n,1)
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: glisse at gcc dot gnu.org
Hello,
calloc can sometimes be significantly faster than malloc+bzero because it has
special knowledge that some memory is already zero. When other optimizations
simplify some code to malloc+memset(0), it would thus be nice to replace it
with calloc. Sadly, I don't think there is a way to do a similar optimization
in C++ with new, which is where such code most easily appears (creating
std::vector<int>(10000) for instance). And there would also be the complication
there that the size of the memset would be a bit smaller than that of the
malloc (using calloc would still be fine, but it gets harder to know if it is
an improvement).