r246229 - [X86] Conditionalize Darwin MaxVectorAlign on the presence of AVX.

Eric Christopher via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 9 15:10:53 PDT 2015


On Mon, Aug 31, 2015 at 4:03 PM Ahmed Bougacha <ahmed.bougacha at gmail.com>
wrote:

> On Thu, Aug 27, 2015 at 7:19 PM, Eric Christopher <echristo at gmail.com>
> wrote:
>
>> Hi Ahmed,
>>
>> A quick note: I think this is going to fail in the presence of the target
>> attribute. I.e. if someone decorates a function with
>> __attribute__((target("avx512"))) this is unlikely to catch that.
>>
>
> You're right; any ideas on how to handle this? In particular, has any of
> IRGen (except attributes of course) needed to know about it until know?
> IIRC it's directly lowered to IR function attributes, so this sounds like a
> big change. Worst case we can restore the unconditional max alignment?
>
>

This is harder. I mean, right now we depend ABI based on the command line
options for the whole file which seems reasonable from a calling convention
standpoint. I think right now you could construct an unaligned vector
testcase and use it with a builtin?

I think we can get it to where you can look at a function and get the
proper feature set for it in short order - I'm working on that anyhow,
right now it would be messy though.

What would you like to do about this right now though?


> Also, should we do this for all of the x86 OSes?
>>
>
> I'm not sure: MaxVectorAlign was only set for the Darwin targets, but I
> think it would make sense everywhere.
> Let's see what people say: http://reviews.llvm.org/D12505
>
>
I've ack'd that. Thanks for doing it.

-eric


> Thanks for the comments!
> -Ahmed
>
>
>> -eric
>>
>> On Thu, Aug 27, 2015 at 3:31 PM Ahmed Bougacha via cfe-commits <
>> cfe-commits at lists.llvm.org> wrote:
>>
>>> Author: ab
>>> Date: Thu Aug 27 17:30:38 2015
>>> New Revision: 246229
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=246229&view=rev
>>> Log:
>>> [X86] Conditionalize Darwin MaxVectorAlign on the presence of AVX.
>>>
>>> There's no point in using a larger alignment if we have no instructions
>>> that would benefit from it.
>>>
>>> Differential Revision: http://reviews.llvm.org/D12389
>>>
>>> Modified:
>>>     cfe/trunk/lib/Basic/Targets.cpp
>>>     cfe/trunk/test/CodeGen/vector-alignment.c
>>>
>>> Modified: cfe/trunk/lib/Basic/Targets.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=246229&r1=246228&r2=246229&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/lib/Basic/Targets.cpp (original)
>>> +++ cfe/trunk/lib/Basic/Targets.cpp Thu Aug 27 17:30:38 2015
>>> @@ -3629,13 +3629,21 @@ public:
>>>      LongDoubleWidth = 128;
>>>      LongDoubleAlign = 128;
>>>      SuitableAlign = 128;
>>> -    MaxVectorAlign = 256;
>>>      SizeType = UnsignedLong;
>>>      IntPtrType = SignedLong;
>>>      DataLayoutString = "e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128";
>>>      HasAlignMac68kSupport = true;
>>>    }
>>>
>>> +  bool handleTargetFeatures(std::vector<std::string> &Features,
>>> +                            DiagnosticsEngine &Diags) override {
>>> +    if
>>> (!DarwinTargetInfo<X86_32TargetInfo>::handleTargetFeatures(Features,
>>> +
>>> Diags))
>>> +      return false;
>>> +    // Now that we know if we have AVX, we can decide how to align
>>> vectors.
>>> +    MaxVectorAlign = hasFeature("avx") ? 256 : 128;
>>> +    return true;
>>> +  }
>>>  };
>>>
>>>  // x86-32 Windows target
>>> @@ -3986,13 +3994,22 @@ public:
>>>    DarwinX86_64TargetInfo(const llvm::Triple &Triple)
>>>        : DarwinTargetInfo<X86_64TargetInfo>(Triple) {
>>>      Int64Type = SignedLongLong;
>>> -    MaxVectorAlign = 256;
>>>      // The 64-bit iOS simulator uses the builtin bool type for
>>> Objective-C.
>>>      llvm::Triple T = llvm::Triple(Triple);
>>>      if (T.isiOS())
>>>        UseSignedCharForObjCBool = false;
>>>      DataLayoutString = "e-m:o-i64:64-f80:128-n8:16:32:64-S128";
>>>    }
>>> +
>>> +  bool handleTargetFeatures(std::vector<std::string> &Features,
>>> +                            DiagnosticsEngine &Diags) override {
>>> +    if
>>> (!DarwinTargetInfo<X86_64TargetInfo>::handleTargetFeatures(Features,
>>> +
>>> Diags))
>>> +      return false;
>>> +    // Now that we know if we have AVX, we can decide how to align
>>> vectors.
>>> +    MaxVectorAlign = hasFeature("avx") ? 256 : 128;
>>> +    return true;
>>> +  }
>>>  };
>>>
>>>  class OpenBSDX86_64TargetInfo : public
>>> OpenBSDTargetInfo<X86_64TargetInfo> {
>>>
>>> Modified: cfe/trunk/test/CodeGen/vector-alignment.c
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/vector-alignment.c?rev=246229&r1=246228&r2=246229&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/test/CodeGen/vector-alignment.c (original)
>>> +++ cfe/trunk/test/CodeGen/vector-alignment.c Thu Aug 27 17:30:38 2015
>>> @@ -1,38 +1,51 @@
>>> -// RUN: %clang_cc1 -w -triple x86_64-apple-darwin10 -emit-llvm -o - %s
>>> | FileCheck %s
>>> +// RUN: %clang_cc1 -w -triple x86_64-apple-darwin10 \
>>> +// RUN:  -emit-llvm -o - %s | FileCheck %s --check-prefix=ALL
>>> --check-prefix=SSE
>>> +// RUN: %clang_cc1 -w -triple   i386-apple-darwin10 \
>>> +// RUN:  -emit-llvm -o - %s | FileCheck %s --check-prefix=ALL
>>> --check-prefix=SSE
>>> +// RUN: %clang_cc1 -w -triple x86_64-apple-darwin10 -target-feature
>>> +avx \
>>> +// RUN:  -emit-llvm -o - %s | FileCheck %s --check-prefix=ALL
>>> --check-prefix=AVX
>>> +// RUN: %clang_cc1 -w -triple   i386-apple-darwin10 -target-feature
>>> +avx \
>>> +// RUN:  -emit-llvm -o - %s | FileCheck %s --check-prefix=ALL
>>> --check-prefix=AVX
>>>  // 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
>>> +// SSE: @v1 {{.*}}, align 16
>>> +// AVX: @v1 {{.*}}, align 16
>>>  double __attribute__((vector_size(32))) v2;
>>> -// CHECK: @v2 {{.*}}, align 32
>>> +// SSE: @v2 {{.*}}, align 16
>>> +// AVX: @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
>>> +// SSE: @v3 {{.*}}, align 16
>>> +// AVX: @v3 {{.*}}, align 32
>>>  double __attribute__((vector_size(1024))) v4;
>>> -// CHECK: @v4 {{.*}}, align 32
>>> +// SSE: @v4 {{.*}}, align 16
>>> +// AVX: @v4 {{.*}}, align 32
>>>
>>>  // Aliged attribute should always override.
>>>  double __attribute__((vector_size(16), aligned(16))) v5;
>>> -// CHECK: @v5 {{.*}}, align 16
>>> +// ALL: @v5 {{.*}}, align 16
>>>  double __attribute__((vector_size(16), aligned(64))) v6;
>>> -// CHECK: @v6 {{.*}}, align 64
>>> +// ALL: @v6 {{.*}}, align 64
>>>  double __attribute__((vector_size(32), aligned(16))) v7;
>>> -// CHECK: @v7 {{.*}}, align 16
>>> +// ALL: @v7 {{.*}}, align 16
>>>  double __attribute__((vector_size(32), aligned(64))) v8;
>>> -// CHECK: @v8 {{.*}}, align 64
>>> +// ALL: @v8 {{.*}}, align 64
>>>
>>>  // Check non-power of 2 widths.
>>>  double __attribute__((vector_size(24))) v9;
>>> -// CHECK: @v9 {{.*}}, align 32
>>> +// SSE: @v9 {{.*}}, align 16
>>> +// AVX: @v9 {{.*}}, align 32
>>>  double __attribute__((vector_size(40))) v10;
>>> -// CHECK: @v10 {{.*}}, align 32
>>> +// SSE: @v10 {{.*}}, align 16
>>> +// AVX: @v10 {{.*}}, align 32
>>>
>>>  // Check non-power of 2 widths with aligned attribute.
>>>  double __attribute__((vector_size(24), aligned(64))) v11;
>>> -// CHECK: @v11 {{.*}}, align 64
>>> +// ALL: @v11 {{.*}}, align 64
>>>  double __attribute__((vector_size(80), aligned(16))) v12;
>>> -// CHECK: @v12 {{.*}}, align 16
>>> +// ALL: @v12 {{.*}}, align 16
>>>
>>>
>>> _______________________________________________
>>> cfe-commits mailing list
>>> cfe-commits at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150909/959e9a74/attachment-0001.html>


More information about the cfe-commits mailing list