[PATCH] D107522: [PowerPC][AIX] attribute aligned cannot decrease align of a vector var.
Sean Fertile via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 4 19:18:48 PDT 2021
sfertile created this revision.
sfertile added reviewers: stevewan, Jake-Egan, hubert.reinterpretcast.
Herald added subscribers: shchenz, nemanjai.
Herald added a reviewer: aaron.ballman.
sfertile requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
On AIX an aligned attribute cannot decrease the alignment of a variable when placed on a variable declaration of vector type.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D107522
Files:
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/CodeGen/aix-vector-attr-aligned.c
clang/test/Sema/aix-attr-aligned-vector-typedef.c
Index: clang/test/Sema/aix-attr-aligned-vector-typedef.c
===================================================================
--- /dev/null
+++ clang/test/Sema/aix-attr-aligned-vector-typedef.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple powerpc64-unknown-aix -target-feature +altivec -target-cpu pwr7 -verify -fsyntax-only %s
+// RUN: %clang_cc1 -triple powerpc-unknown-aix -target-feature +altivec -target-cpu pwr7 -verify -fsyntax-only %s
+
+int escape(vector int*);
+
+typedef vector int __attribute__((aligned(8))) UnderAlignedVI;
+UnderAlignedVI TypedefedGlobal;
+
+int localTypedefed(void) {
+ UnderAlignedVI TypedefedLocal;
+ return escape(&TypedefedLocal); // expected-warning {{passing 8-byte aligned argument to 16-byte aligned parameter 1 of 'escape' may result in an unaligned pointer access}}
+}
Index: clang/test/CodeGen/aix-vector-attr-aligned.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/aix-vector-attr-aligned.c
@@ -0,0 +1,33 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -triple powerpc-unknown-aix -target-feature +altivec -target-cpu pwr7 -emit-llvm -o - %s | \
+// RUN: FileCheck %s
+// RUN: %clang_cc1 -triple powerpc64-unknown-aix -target-feature +altivec -target-cpu pwr7 -emit-llvm -o - %s | \
+// RUN: FileCheck %s
+
+typedef vector int __attribute__((aligned(8))) UnderAlignedVI;
+
+vector int g32 __attribute__((aligned(32)));
+vector int g8 __attribute__((aligned(8)));
+UnderAlignedVI TypedefedGlobal;
+
+int escape(vector int*);
+
+int local32(void) {
+ vector int l32 __attribute__((aligned(32)));
+ return escape(&l32);
+}
+
+int local8(void) {
+ vector int l8 __attribute__((aligned(8)));
+ return escape(&l8);
+}
+
+// CHECK: @g32 = global <4 x i32> zeroinitializer, align 32
+// CHECK: @g8 = global <4 x i32> zeroinitializer, align 16
+// CHECK: @TypedefedGlobal = global <4 x i32> zeroinitializer, align 8
+
+// CHECK-LABEL: @local32
+// CHECK: %l32 = alloca <4 x i32>, align 32
+//
+// CHECK-LABEL: @local8
+// CHECK: %l8 = alloca <4 x i32>, align 16
Index: clang/lib/Sema/SemaDeclAttr.cpp
===================================================================
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -4060,11 +4060,11 @@
return;
}
+ const auto *VD = dyn_cast<VarDecl>(D);
if (Context.getTargetInfo().isTLSSupported()) {
unsigned MaxTLSAlign =
Context.toCharUnitsFromBits(Context.getTargetInfo().getMaxTLSAlign())
.getQuantity();
- const auto *VD = dyn_cast<VarDecl>(D);
if (MaxTLSAlign && AlignVal > MaxTLSAlign && VD &&
VD->getTLSKind() != VarDecl::TLS_None) {
Diag(VD->getLocation(), diag::err_tls_var_aligned_over_maximum)
@@ -4073,6 +4073,14 @@
}
}
+ // On AIX, an aligned attribute can not decrease the alignemnt when applied
+ // to a variable declaration with vector type.
+ if (VD && Context.getTargetInfo().getTriple().isOSAIX()) {
+ const Type *Ty = VD->getType().getTypePtr();
+ if (Ty->isVectorType() && AlignVal < 16)
+ return;
+ }
+
AlignedAttr *AA = ::new (Context) AlignedAttr(Context, CI, true, ICE.get());
AA->setPackExpansion(IsPackExpansion);
D->addAttr(AA);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107522.364321.patch
Type: text/x-patch
Size: 3256 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210805/5a4056cb/attachment.bin>
More information about the llvm-commits
mailing list