https://github.com/dominik-steenken updated https://github.com/llvm/llvm-project/pull/142346
>From 318f0536ce71780f808ef70a1817af515f9861bd Mon Sep 17 00:00:00 2001 From: Dominik Steenken <d...@de.ibm.com> Date: Mon, 26 May 2025 14:53:41 +0200 Subject: [PATCH 1/2] Align global strings according to data layout When creating global strings, some targets have requirements that need to be taken into account. Previously, the global strings created by `IRBuilder::createGlobalString` had a hard-coded alignment of `1`. This commit makes it so that the alignment is taken from the data layout instead, giving targets the chance to align global strings according to their preferences. --- llvm/lib/IR/IRBuilder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/IR/IRBuilder.cpp b/llvm/lib/IR/IRBuilder.cpp index 580b0af709337..9e061257a7baa 100644 --- a/llvm/lib/IR/IRBuilder.cpp +++ b/llvm/lib/IR/IRBuilder.cpp @@ -52,7 +52,7 @@ GlobalVariable *IRBuilderBase::CreateGlobalString(StringRef Str, *M, StrConstant->getType(), true, GlobalValue::PrivateLinkage, StrConstant, Name, nullptr, GlobalVariable::NotThreadLocal, AddressSpace); GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global); - GV->setAlignment(Align(1)); + GV->setAlignment(M->getDataLayout().getPrefTypeAlign(getInt8Ty())); return GV; } >From 59f7f10e4c29d497e5cea1c169678fad1c57043c Mon Sep 17 00:00:00 2001 From: Dominik Steenken <d...@de.ibm.com> Date: Fri, 30 May 2025 15:01:45 +0200 Subject: [PATCH 2/2] [SystemZ] Add codegen test for global string alignment This commit adds a test to the `clang` test suite for the SystemZ backend that checks for the correct alignment of global strings created by the PrintFOptimizer for the case `printf("foo\n")` -> `puts("foo")`. --- .../CodeGen/SystemZ/align-systemz-globalstring.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 clang/test/CodeGen/SystemZ/align-systemz-globalstring.c diff --git a/clang/test/CodeGen/SystemZ/align-systemz-globalstring.c b/clang/test/CodeGen/SystemZ/align-systemz-globalstring.c new file mode 100644 index 0000000000000..2264bb3ddb922 --- /dev/null +++ b/clang/test/CodeGen/SystemZ/align-systemz-globalstring.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -O1 -triple s390x-linux-gnu -emit-llvm %s -o - | FileCheck %s + +// #include <stdio.h> + +// CHECK: @msg1 = local_unnamed_addr constant [13 x i8] c"Hello World\0A\00", align 2 +// CHECK: @str = private unnamed_addr constant [12 x i8] c"Hello World\00", align 2 + +const char msg1 [] = "Hello World\n"; + +extern int printf(const char *__restrict __format, ...); + +void foo() { + printf(msg1); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits