[PATCH] D41705: Place undefined globals in .bss instead of .data

varkor via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 3 10:27:02 PST 2018


varkor created this revision.
varkor added a reviewer: efriedma.

Following up on the discussion from http://lists.llvm.org/pipermail/llvm-dev/2017-April/112305.html, undef values are now placed in the .bss as well as null values. This prevents undef global values taking up potentially huge amounts of space in the .data section.

The following two lines now both generate equivalent .bss data:

  @vals1 = internal unnamed_addr global [20000000 x i32] zeroinitializer, align 4
  @vals2 = internal unnamed_addr global [20000000 x i32] undef, align 4 ; previously unaccounted for


https://reviews.llvm.org/D41705

Files:
  lib/Target/TargetLoweringObjectFile.cpp


Index: lib/Target/TargetLoweringObjectFile.cpp
===================================================================
--- lib/Target/TargetLoweringObjectFile.cpp
+++ lib/Target/TargetLoweringObjectFile.cpp
@@ -58,7 +58,7 @@
   const Constant *C = GV->getInitializer();
 
   // Must have zero initializer.
-  if (!C->isNullValue())
+  if (!C->isNullValue() && !isa<UndefValue>(C))
     return false;
 
   // Leave constant zeros in readonly constant sections, so they can be shared.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41705.128535.patch
Type: text/x-patch
Size: 479 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180103/94de4cca/attachment.bin>


More information about the llvm-commits mailing list