[llvm] r341527 - [SLC] Add an alignment to CreateGlobalString

David Green via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 6 01:42:18 PDT 2018


Author: dmgreen
Date: Thu Sep  6 01:42:17 2018
New Revision: 341527

URL: http://llvm.org/viewvc/llvm-project?rev=341527&view=rev
Log:
[SLC] Add an alignment to CreateGlobalString

Previously the alignment on the newly created global strings was not set,
meaning that DataLayout::getPreferredAlignment was free to overalign it
to 16 bytes. This caused unnecessary code bloat with the padding between
variables.

The main example of this happening was the printf->puts optimisation in
SimplifyLibCalls, but as the change here is made in
IRBuilderBase::CreateGlobalString, other globals using this will now be
aligned too.

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

Modified:
    llvm/trunk/lib/IR/IRBuilder.cpp
    llvm/trunk/test/Transforms/InstCombine/printf-1.ll

Modified: llvm/trunk/lib/IR/IRBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/IRBuilder.cpp?rev=341527&r1=341526&r2=341527&view=diff
==============================================================================
--- llvm/trunk/lib/IR/IRBuilder.cpp (original)
+++ llvm/trunk/lib/IR/IRBuilder.cpp Thu Sep  6 01:42:17 2018
@@ -50,6 +50,7 @@ GlobalVariable *IRBuilderBase::CreateGlo
                                 nullptr, GlobalVariable::NotThreadLocal,
                                 AddressSpace);
   GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
+  GV->setAlignment(1);
   return GV;
 }
 

Modified: llvm/trunk/test/Transforms/InstCombine/printf-1.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/printf-1.ll?rev=341527&r1=341526&r2=341527&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/printf-1.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/printf-1.ll Thu Sep  6 01:42:17 2018
@@ -14,7 +14,7 @@ target datalayout = "e-p:32:32:32-i1:8:8
 @percent_f = constant [3 x i8] c"%f\00"
 @percent_s = constant [4 x i8] c"%s\0A\00"
 @empty = constant [1 x i8] c"\00"
-; CHECK: [[$STR:@[a-z0-9]+]] = private unnamed_addr constant [12 x i8] c"hello world\00"
+; CHECK: [[$STR:@[a-z0-9]+]] = private unnamed_addr constant [12 x i8] c"hello world\00", align 1
 
 declare i32 @printf(i8*, ...)
 




More information about the llvm-commits mailing list