[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 13:05:25 PST 2018
varkor updated this revision to Diff 128552.
varkor added a comment.
- Added support for structs with a combination of null and undef fields.
- Added a regression test.
https://reviews.llvm.org/D41705
Files:
lib/Target/TargetLoweringObjectFile.cpp
test/CodeGen/X86/undef-globals-bss.ll
Index: test/CodeGen/X86/undef-globals-bss.ll
===================================================================
--- /dev/null
+++ test/CodeGen/X86/undef-globals-bss.ll
@@ -0,0 +1,8 @@
+; RUN: llc < %s | FileCheck %s
+target triple = "x86_64-apple-darwin"
+
+; CHECK: .zerofill __DATA,__bss,_vals,8000000,2 ## @vals
+ at vals = internal unnamed_addr global [2000000 x i32] undef, align 4
+
+; CHECK: .zerofill __DATA,__bss,_struct,8000016,3 ## @struct
+ at struct = internal global { i1, [8000000 x i8], [7 x i8], i64 } { i1 false, [8000000 x i8] zeroinitializer, [7 x i8] undef, i64 0 }, align 8
Index: lib/Target/TargetLoweringObjectFile.cpp
===================================================================
--- lib/Target/TargetLoweringObjectFile.cpp
+++ lib/Target/TargetLoweringObjectFile.cpp
@@ -58,8 +58,16 @@
const Constant *C = GV->getInitializer();
// Must have zero initializer.
- if (!C->isNullValue())
- return false;
+ if (!C->isNullValue() && !isa<UndefValue>(C)) {
+ if (!isa<ConstantAggregate>(C))
+ return false;
+ // Check that it isn't all zeros or undefs.
+ for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i) {
+ Constant *E = cast<Constant>(C->getOperand(i));
+ if (!E->isNullValue() && !isa<UndefValue>(E))
+ return false;
+ }
+ }
// Leave constant zeros in readonly constant sections, so they can be shared.
if (GV->isConstant())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41705.128552.patch
Type: text/x-patch
Size: 1414 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180103/e108e9ad/attachment.bin>
More information about the llvm-commits
mailing list