[PATCH] D51410: [SLC] Add an alignment to printf->puts global string

Dave Green via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 29 03:52:26 PDT 2018


dmgreen created this revision.
dmgreen added reviewers: efriedma, davide, echristo, hfinkel.

Previously the alignment on the newly created puts string was not set,
meaning that DataLayout::getPreferredAlignment was free to overalign
it to 16 bytes. This causes unnecessary code bloat.


https://reviews.llvm.org/D51410

Files:
  lib/Transforms/Utils/SimplifyLibCalls.cpp
  test/Transforms/InstCombine/printf-1.ll


Index: test/Transforms/InstCombine/printf-1.ll
===================================================================
--- test/Transforms/InstCombine/printf-1.ll
+++ test/Transforms/InstCombine/printf-1.ll
@@ -14,7 +14,7 @@
 @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*, ...)
 
Index: lib/Transforms/Utils/SimplifyLibCalls.cpp
===================================================================
--- lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -1885,7 +1885,8 @@
     // Create a string literal with no \n on it.  We expect the constant merge
     // pass to be run after this pass, to merge duplicate strings.
     FormatStr = FormatStr.drop_back();
-    Value *GV = B.CreateGlobalString(FormatStr, "str");
+    GlobalVariable *GV = B.CreateGlobalString(FormatStr, "str");
+    GV->setAlignment(1); // Prevent the string from being over-aligned
     return emitPutS(GV, B, TLI);
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51410.163037.patch
Type: text/x-patch
Size: 1220 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180829/0283c456/attachment.bin>


More information about the llvm-commits mailing list