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

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 1 11:17:15 PST 2018


LGTM

Eli, do you agree?

Cheers,
Rafael

varkor via Phabricator via llvm-commits <llvm-commits at lists.llvm.org>
writes:

> varkor updated this revision to Diff 132388.
> varkor added a comment.
>
> As Rafael pointed out, we should still be checking the alignment of bss data — it's just no longer specified with `p2align`. I've updated the test to check for the alignment of `arr8`. I think this should now be ready to take a look at again!
>
>
> https://reviews.llvm.org/D41705
>
> Files:
>   lib/Target/TargetLoweringObjectFile.cpp
>   test/CodeGen/ARM/memfunc.ll
>   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,12 @@
> +; 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,8000040,3 ## @struct
> + at struct = internal global { i1, [8000000 x i8], [7 x i8], i64, { [4 x i32], { i8 }, i1 } }
> +                { i1 false, [8000000 x i8] zeroinitializer, [7 x i8] undef, i64 0,
> +                        { [4 x i32], { i8 }, i1 }
> +                        { [4 x i32] zeroinitializer, { i8 } { i8 undef }, i1 false }
> +                }, align 8
> Index: test/CodeGen/ARM/memfunc.ll
> ===================================================================
> --- test/CodeGen/ARM/memfunc.ll
> +++ test/CodeGen/ARM/memfunc.ll
> @@ -421,8 +421,10 @@
>  ; CHECK: arr5:
>  ; CHECK-NOT: .p2align
>  ; CHECK: arr6:
> -; CHECK: .p2align 4
> -; CHECK: arr8:
> +; CHECK-IOS: arr8,128,4
> +; CHECK-DARWIN: arr8,128,4
> +; CHECK-EABI: arr8,128,16
> +; CHECK-GNUEABI: arr8,128,16
>  ; CHECK: .p2align 4
>  ; CHECK: arr9:
>  
> Index: lib/Target/TargetLoweringObjectFile.cpp
> ===================================================================
> --- lib/Target/TargetLoweringObjectFile.cpp
> +++ lib/Target/TargetLoweringObjectFile.cpp
> @@ -54,11 +54,24 @@
>    delete Mang;
>  }
>  
> +static bool isNullOrUndef(const Constant *C) {
> +  // Check that the constant isn't all zeros or undefs.
> +  if (C->isNullValue() || isa<UndefValue>(C))
> +    return true;
> +  if (!isa<ConstantAggregate>(C))
> +    return false;
> +  for (auto Operand : C->operand_values()) {
> +    if (!isNullOrUndef(cast<Constant>(Operand)))
> +      return false;
> +  }
> +  return true;
> +}
> +
>  static bool isSuitableForBSS(const GlobalVariable *GV, bool NoZerosInBSS) {
>    const Constant *C = GV->getInitializer();
>  
>    // Must have zero initializer.
> -  if (!C->isNullValue())
> +  if (!isNullOrUndef(C))
>      return false;
>  
>    // Leave constant zeros in readonly constant sections, so they can be shared.
>
>
> Index: test/CodeGen/X86/undef-globals-bss.ll
> ===================================================================
> --- /dev/null
> +++ test/CodeGen/X86/undef-globals-bss.ll
> @@ -0,0 +1,12 @@
> +; 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,8000040,3 ## @struct
> + at struct = internal global { i1, [8000000 x i8], [7 x i8], i64, { [4 x i32], { i8 }, i1 } }
> +                { i1 false, [8000000 x i8] zeroinitializer, [7 x i8] undef, i64 0,
> +                        { [4 x i32], { i8 }, i1 }
> +                        { [4 x i32] zeroinitializer, { i8 } { i8 undef }, i1 false }
> +                }, align 8
> Index: test/CodeGen/ARM/memfunc.ll
> ===================================================================
> --- test/CodeGen/ARM/memfunc.ll
> +++ test/CodeGen/ARM/memfunc.ll
> @@ -421,8 +421,10 @@
>  ; CHECK: arr5:
>  ; CHECK-NOT: .p2align
>  ; CHECK: arr6:
> -; CHECK: .p2align 4
> -; CHECK: arr8:
> +; CHECK-IOS: arr8,128,4
> +; CHECK-DARWIN: arr8,128,4
> +; CHECK-EABI: arr8,128,16
> +; CHECK-GNUEABI: arr8,128,16
>  ; CHECK: .p2align 4
>  ; CHECK: arr9:
>  
> Index: lib/Target/TargetLoweringObjectFile.cpp
> ===================================================================
> --- lib/Target/TargetLoweringObjectFile.cpp
> +++ lib/Target/TargetLoweringObjectFile.cpp
> @@ -54,11 +54,24 @@
>    delete Mang;
>  }
>  
> +static bool isNullOrUndef(const Constant *C) {
> +  // Check that the constant isn't all zeros or undefs.
> +  if (C->isNullValue() || isa<UndefValue>(C))
> +    return true;
> +  if (!isa<ConstantAggregate>(C))
> +    return false;
> +  for (auto Operand : C->operand_values()) {
> +    if (!isNullOrUndef(cast<Constant>(Operand)))
> +      return false;
> +  }
> +  return true;
> +}
> +
>  static bool isSuitableForBSS(const GlobalVariable *GV, bool NoZerosInBSS) {
>    const Constant *C = GV->getInitializer();
>  
>    // Must have zero initializer.
> -  if (!C->isNullValue())
> +  if (!isNullOrUndef(C))
>      return false;
>  
>    // Leave constant zeros in readonly constant sections, so they can be shared.
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list