[PATCH] D85543: Limit Max Vector alignment on COFF targets to 8192
Erich Keane via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 7 12:11:58 PDT 2020
erichkeane created this revision.
erichkeane added reviewers: craig.topper, lebedev.ri.
erichkeane requested review of this revision.
COFF targets have a max object alignment of 8192, so trying to create
one with a larger size results in an unreachable in WinCOFFObjectWriter.
For the reproducer I have uses thread local storage, however other
alignments are likely affected as well.
This patch sets the MaxVectorAlign for COFF to 8192. Additionally,
though there is no longer a way to reproduce that I could find, it
correctly sets the MaxTLSAlign for COFF to that value as well, so that
if anyone comes up with a situation where this is true, it will cause an
error.
https://reviews.llvm.org/D85543
Files:
clang/include/clang/Basic/TargetInfo.h
clang/lib/Basic/Targets/X86.h
clang/test/CodeGen/alignment.c
Index: clang/test/CodeGen/alignment.c
===================================================================
--- clang/test/CodeGen/alignment.c
+++ clang/test/CodeGen/alignment.c
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,NONCOFF
+// RUN: %clang_cc1 -triple i386-unknown-windows-pc -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,COFF
__attribute((aligned(16))) float a[128];
union {int a[4]; __attribute((aligned(16))) float b[4];} b;
@@ -7,7 +8,7 @@
// CHECK: @b = {{.*}}zeroinitializer, align 16
long long int test5[1024];
-// CHECK-DAG: @test5 = global [1024 x i64] zeroinitializer, align 8
+// CHECK-DAG: @test5 = {{.*}}global [1024 x i64] zeroinitializer, align 8
// PR5279 - Reduced alignment on typedef.
typedef int myint __attribute__((aligned(1)));
@@ -67,3 +68,11 @@
}
// CHECK-LABEL: @test6
// CHECK: load <4 x float>, <4 x float>* {{.*}}, align 2
+
+typedef int __attribute__((ext_vector_type(200 * 16))) BigVecTy;
+void test7() {
+ BigVecTy V;
+}
+// CHECK-LABEL: @test7
+// NONCOFF: alloca <3200 x i32>, align 16384
+// COFF: alloca <3200 x i32>, align 8192
Index: clang/lib/Basic/Targets/X86.h
===================================================================
--- clang/lib/Basic/Targets/X86.h
+++ clang/lib/Basic/Targets/X86.h
@@ -144,6 +144,11 @@
LongDoubleFormat = &llvm::APFloat::x87DoubleExtended();
AddrSpaceMap = &X86AddrSpaceMap;
HasStrictFP = true;
+
+ bool IsWinCOFF =
+ getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF();
+ if (IsWinCOFF)
+ MaxVectorAlign = MaxTLSAlign = 8192u * getCharWidth();
}
const char *getLongDoubleMangling() const override {
Index: clang/include/clang/Basic/TargetInfo.h
===================================================================
--- clang/include/clang/Basic/TargetInfo.h
+++ clang/include/clang/Basic/TargetInfo.h
@@ -100,8 +100,8 @@
unsigned char MinGlobalAlign;
unsigned short NewAlign;
- unsigned short MaxVectorAlign;
- unsigned short MaxTLSAlign;
+ unsigned MaxVectorAlign;
+ unsigned MaxTLSAlign;
const llvm::fltSemantics *HalfFormat, *BFloat16Format, *FloatFormat,
*DoubleFormat, *LongDoubleFormat, *Float128Format;
@@ -1271,9 +1271,7 @@
///
/// Gets the maximum alignment (in bits) of a TLS variable on this target.
/// Returns zero if there is no such constraint.
- unsigned short getMaxTLSAlign() const {
- return MaxTLSAlign;
- }
+ unsigned getMaxTLSAlign() const { return MaxTLSAlign; }
/// Whether target supports variable-length arrays.
bool isVLASupported() const { return VLASupported; }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85543.283976.patch
Type: text/x-patch
Size: 2760 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200807/dd12f0c2/attachment.bin>
More information about the cfe-commits
mailing list