[PATCH] D49771: CodeGen: use non-zero memset when possible for automatic variables

JF Bastien via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 24 17:16:20 PDT 2018


jfb created this revision.
jfb added a reviewer: dexonsmith.
Herald added a subscriber: cfe-commits.

Right now automatic variables are either initialized with bzero followed by a few stores, or memcpy'd from a synthesized global. We end up encountering a fair amount of code where memcpy of non-zero byte patterns would be better than memcpy from a global because it touches less memory and generates a smaller binary. The optimizer could reason about this, but it's not really worth it when clang already knows.

This code could definitely be more clever but I'm not sure it's worth it. In particular we could track a histogram of bytes seen and figure out (as we do with bzero) if a memset could be followed by a handful of stores. Similarly, we could tune the heuristics for GlobalSize, but using the same as for bzero seems conservatively OK for now.

rdar://problem/42563091


Repository:
  rC Clang

https://reviews.llvm.org/D49771

Files:
  lib/CodeGen/CGDecl.cpp
  test/CodeGen/init.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49771.157176.patch
Type: text/x-patch
Size: 10776 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180725/2d0f70e4/attachment.bin>


More information about the cfe-commits mailing list