]> granicus.if.org Git - clang/commit
CodeGen: use non-zero memset when possible for automatic variables
authorJF Bastien <jfbastien@apple.com>
Wed, 25 Jul 2018 04:29:03 +0000 (04:29 +0000)
committerJF Bastien <jfbastien@apple.com>
Wed, 25 Jul 2018 04:29:03 +0000 (04:29 +0000)
commit1df8e57db9c247fc74542ce89cf0e90ec1d0881f
tree8bf65289c085a5104c13a18666cb91cb3c6667ce
parent32655dde06d972cb8fab41a9d9e56f71c7093a60
CodeGen: use non-zero memset when possible for automatic variables

Summary:
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>

Reviewers: dexonsmith

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D49771

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337887 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/CGDecl.cpp
test/CodeGen/init.c