1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -x c++ %s -O0 -triple=x86_64-apple-darwin -target-feature +avx2 -fmax-type-align=16 -emit-llvm -o - -Werror | FileCheck %s
2*0a6a1f1dSLionel Sambuc // rdar://16254558
3*0a6a1f1dSLionel Sambuc
4*0a6a1f1dSLionel Sambuc typedef float AVX2Float __attribute__((__vector_size__(32)));
5*0a6a1f1dSLionel Sambuc
6*0a6a1f1dSLionel Sambuc
TestAlign(void)7*0a6a1f1dSLionel Sambuc volatile float TestAlign(void)
8*0a6a1f1dSLionel Sambuc {
9*0a6a1f1dSLionel Sambuc volatile AVX2Float *p = new AVX2Float;
10*0a6a1f1dSLionel Sambuc *p = *p;
11*0a6a1f1dSLionel Sambuc AVX2Float r = *p;
12*0a6a1f1dSLionel Sambuc return r[0];
13*0a6a1f1dSLionel Sambuc }
14*0a6a1f1dSLionel Sambuc
15*0a6a1f1dSLionel Sambuc // CHECK: [[R:%.*]] = alloca <8 x float>, align 32
16*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[CALL:%.*]] = call noalias i8* @_Znwm(i64 32)
17*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[ZERO:%.*]] = bitcast i8* [[CALL]] to <8 x float>*
18*0a6a1f1dSLionel Sambuc // CHECK-NEXT: store <8 x float>* [[ZERO]], <8 x float>** [[P:%.*]], align 8
19*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[ONE:%.*]] = load <8 x float>** [[P]], align 8
20*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[TWO:%.*]] = load volatile <8 x float>* [[ONE]], align 16
21*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[THREE:%.*]] = load <8 x float>** [[P]], align 8
22*0a6a1f1dSLionel Sambuc // CHECK-NEXT: store volatile <8 x float> [[TWO]], <8 x float>* [[THREE]], align 16
23*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[FOUR:%.*]] = load <8 x float>** [[P]], align 8
24*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[FIVE:%.*]] = load volatile <8 x float>* [[FOUR]], align 16
25*0a6a1f1dSLionel Sambuc // CHECK-NEXT: store <8 x float> [[FIVE]], <8 x float>* [[R]], align 32
26*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[SIX:%.*]] = load <8 x float>* [[R]], align 32
27*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[VECEXT:%.*]] = extractelement <8 x float> [[SIX]], i32 0
28*0a6a1f1dSLionel Sambuc // CHECK-NEXT: ret float [[VECEXT]]
29*0a6a1f1dSLionel Sambuc
30*0a6a1f1dSLionel Sambuc typedef float AVX2Float_Explicitly_aligned __attribute__((__vector_size__(32))) __attribute__((aligned (32)));
31*0a6a1f1dSLionel Sambuc
32*0a6a1f1dSLionel Sambuc typedef AVX2Float_Explicitly_aligned AVX2Float_indirect;
33*0a6a1f1dSLionel Sambuc
34*0a6a1f1dSLionel Sambuc typedef AVX2Float_indirect AVX2Float_use_existing_align;
35*0a6a1f1dSLionel Sambuc
TestAlign2(void)36*0a6a1f1dSLionel Sambuc volatile float TestAlign2(void)
37*0a6a1f1dSLionel Sambuc {
38*0a6a1f1dSLionel Sambuc volatile AVX2Float_use_existing_align *p = new AVX2Float_use_existing_align;
39*0a6a1f1dSLionel Sambuc *p = *p;
40*0a6a1f1dSLionel Sambuc AVX2Float_use_existing_align r = *p;
41*0a6a1f1dSLionel Sambuc return r[0];
42*0a6a1f1dSLionel Sambuc }
43*0a6a1f1dSLionel Sambuc
44*0a6a1f1dSLionel Sambuc // CHECK: [[R:%.*]] = alloca <8 x float>, align 32
45*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[CALL:%.*]] = call noalias i8* @_Znwm(i64 32)
46*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[ZERO:%.*]] = bitcast i8* [[CALL]] to <8 x float>*
47*0a6a1f1dSLionel Sambuc // CHECK-NEXT: store <8 x float>* [[ZERO]], <8 x float>** [[P:%.*]], align 8
48*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[ONE:%.*]] = load <8 x float>** [[P]], align 8
49*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[TWO:%.*]] = load volatile <8 x float>* [[ONE]], align 32
50*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[THREE:%.*]] = load <8 x float>** [[P]], align 8
51*0a6a1f1dSLionel Sambuc // CHECK-NEXT: store volatile <8 x float> [[TWO]], <8 x float>* [[THREE]], align 32
52*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[FOUR:%.*]] = load <8 x float>** [[P]], align 8
53*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[FIVE:%.*]] = load volatile <8 x float>* [[FOUR]], align 32
54*0a6a1f1dSLionel Sambuc // CHECK-NEXT: store <8 x float> [[FIVE]], <8 x float>* [[R]], align 32
55*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[SIX:%.*]] = load <8 x float>* [[R]], align 32
56*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[VECEXT:%.*]] = extractelement <8 x float> [[SIX]], i32 0
57*0a6a1f1dSLionel Sambuc // CHECK-NEXT: ret float [[VECEXT]]
58