From e6918ca2b32269faa7629c9cd2786a7748f0ba58 Mon Sep 17 00:00:00 2001 From: David Green Date: Thu, 6 Sep 2018 08:42:17 +0000 Subject: [PATCH] [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 llvm-svn: 341527 --- llvm/lib/IR/IRBuilder.cpp | 1 + llvm/test/Transforms/InstCombine/printf-1.ll | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/llvm/lib/IR/IRBuilder.cpp b/llvm/lib/IR/IRBuilder.cpp index 405a56b..91c950d 100644 --- a/llvm/lib/IR/IRBuilder.cpp +++ b/llvm/lib/IR/IRBuilder.cpp @@ -50,6 +50,7 @@ GlobalVariable *IRBuilderBase::CreateGlobalString(StringRef Str, nullptr, GlobalVariable::NotThreadLocal, AddressSpace); GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global); + GV->setAlignment(1); return GV; } diff --git a/llvm/test/Transforms/InstCombine/printf-1.ll b/llvm/test/Transforms/InstCombine/printf-1.ll index ce1a91d..9d13b36 100644 --- a/llvm/test/Transforms/InstCombine/printf-1.ll +++ b/llvm/test/Transforms/InstCombine/printf-1.ll @@ -14,7 +14,7 @@ target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f3 @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*, ...) -- 2.7.4