[cfe-commits] r160209 - in /cfe/trunk: include/clang/Basic/TargetInfo.h lib/AST/ASTContext.cpp lib/Basic/TargetInfo.cpp lib/Basic/Targets.cpp test/CodeGen/vector-alignment.c

Chad Rosier mcrosier at apple.com
Fri Jul 13 16:57:43 PDT 2012


Author: mcrosier
Date: Fri Jul 13 18:57:43 2012
New Revision: 160209

URL: http://llvm.org/viewvc/llvm-project?rev=160209&view=rev
Log:
Add a per target max vector alignment field (e.g., 32-byte alignment for x86 due to
AVX).  Currently, if no aligned attribute is specified the alignment of a vector is
inferred from its size.  Thus, very large vectors will be over-aligned with no 
benefit.  Target owners should set this target max.

Added:
    cfe/trunk/test/CodeGen/vector-alignment.c
Modified:
    cfe/trunk/include/clang/Basic/TargetInfo.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/Basic/TargetInfo.cpp
    cfe/trunk/lib/Basic/Targets.cpp

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=160209&r1=160208&r2=160209&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Fri Jul 13 18:57:43 2012
@@ -80,6 +80,7 @@
   unsigned char LongLongWidth, LongLongAlign;
   unsigned char SuitableAlign;
   unsigned char MaxAtomicPromoteWidth, MaxAtomicInlineWidth;
+  unsigned short MaxVectorAlign;
   const char *DescriptionString;
   const char *UserLabelPrefix;
   const char *MCountName;
@@ -308,6 +309,9 @@
   /// inlined given the supported features of the given target.
   unsigned getMaxAtomicInlineWidth() const { return MaxAtomicInlineWidth; }
 
+  /// \brief Return the maximum vector alignment supported for the given target.
+  unsigned getMaxVectorAlign() const { return MaxVectorAlign; }
+
   /// \brief Return the size of intmax_t and uintmax_t for this target, in bits.
   unsigned getIntMaxTWidth() const {
     return getTypeWidth(IntMaxType);

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=160209&r1=160208&r2=160209&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Fri Jul 13 18:57:43 2012
@@ -1047,6 +1047,10 @@
       Align = llvm::NextPowerOf2(Align);
       Width = llvm::RoundUpToAlignment(Width, Align);
     }
+    // Adjust the alignment based on the target max.
+    uint64_t TargetVectorAlign = Target->getMaxVectorAlign();
+    if (TargetVectorAlign && TargetVectorAlign < Align)
+      Align = TargetVectorAlign;
     break;
   }
 

Modified: cfe/trunk/lib/Basic/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=160209&r1=160208&r2=160209&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/lib/Basic/TargetInfo.cpp Fri Jul 13 18:57:43 2012
@@ -47,6 +47,7 @@
   LargeArrayMinWidth = 0;
   LargeArrayAlign = 0;
   MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 0;
+  MaxVectorAlign = 0;
   SizeType = UnsignedLong;
   PtrDiffType = SignedLong;
   IntMaxType = SignedLongLong;

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=160209&r1=160208&r2=160209&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Fri Jul 13 18:57:43 2012
@@ -2448,6 +2448,7 @@
     LongDoubleWidth = 128;
     LongDoubleAlign = 128;
     SuitableAlign = 128;
+    MaxVectorAlign = 256;
     SizeType = UnsignedLong;
     IntPtrType = SignedLong;
     DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
@@ -2755,6 +2756,7 @@
   DarwinX86_64TargetInfo(const std::string& triple)
       : DarwinTargetInfo<X86_64TargetInfo>(triple) {
     Int64Type = SignedLongLong;
+    MaxVectorAlign = 256;
   }
 };
 } // end anonymous namespace

Added: cfe/trunk/test/CodeGen/vector-alignment.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/vector-alignment.c?rev=160209&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/vector-alignment.c (added)
+++ cfe/trunk/test/CodeGen/vector-alignment.c Fri Jul 13 18:57:43 2012
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -w -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s
+// rdar://11759609
+
+// At or below target max alignment with no aligned attribute should align based
+// on the size of vector.
+double __attribute__((vector_size(16))) v1;
+// CHECK: @v1 {{.*}}, align 16
+double __attribute__((vector_size(32))) v2;
+// CHECK: @v2 {{.*}}, align 32
+
+// Alignment above target max alignment with no aligned attribute should align
+// based on the target max.
+double __attribute__((vector_size(64))) v3;
+// CHECK: @v3 {{.*}}, align 32
+double __attribute__((vector_size(1024))) v4;
+// CHECK: @v4 {{.*}}, align 32
+
+// Aliged attribute should always override.
+double __attribute__((vector_size(16), aligned(16))) v5;
+// CHECK: @v5 {{.*}}, align 16
+double __attribute__((vector_size(16), aligned(64))) v6;
+// CHECK: @v6 {{.*}}, align 64
+double __attribute__((vector_size(32), aligned(16))) v7;
+// CHECK: @v7 {{.*}}, align 16
+double __attribute__((vector_size(32), aligned(64))) v8;
+// CHECK: @v8 {{.*}}, align 64
+
+// Check non-power of 2 widths.
+double __attribute__((vector_size(24))) v9;
+// CHECK: @v9 {{.*}}, align 32
+double __attribute__((vector_size(40))) v10;
+// CHECK: @v10 {{.*}}, align 32
+
+// Check non-power of 2 widths with aligned attribute.
+double __attribute__((vector_size(24), aligned(64))) v11;
+// CHECK: @v11 {{.*}}, align 64
+double __attribute__((vector_size(80), aligned(16))) v12;
+// CHECK: @v12 {{.*}}, align 16





More information about the cfe-commits mailing list