1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
2f4a2713aSLionel Sambuc
3f4a2713aSLionel Sambuc // Validate that volatile _Complex loads and stores are generated
4f4a2713aSLionel Sambuc // properly, including their alignment (even when overaligned).
5f4a2713aSLionel Sambuc //
6f4a2713aSLionel Sambuc // This test assumes that floats are 32-bit aligned and doubles are
7f4a2713aSLionel Sambuc // 64-bit aligned, and uses x86-64 as a target that should have this
8*0a6a1f1dSLionel Sambuc // property.
9f4a2713aSLionel Sambuc
10f4a2713aSLionel Sambuc volatile _Complex float cf;
11f4a2713aSLionel Sambuc volatile _Complex double cd;
12f4a2713aSLionel Sambuc volatile _Complex float cf32 __attribute__((aligned(32)));
13f4a2713aSLionel Sambuc volatile _Complex double cd32 __attribute__((aligned(32)));
14f4a2713aSLionel Sambuc
15*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define void @test_cf()
test_cf()16f4a2713aSLionel Sambuc void test_cf() {
17f4a2713aSLionel Sambuc // CHECK: load volatile float* getelementptr inbounds ({ float, float }* @cf, i32 0, i32 0), align 4
18f4a2713aSLionel Sambuc // CHECK-NEXT: load volatile float* getelementptr inbounds ({ float, float }* @cf, i32 0, i32 1), align 4
19f4a2713aSLionel Sambuc (void)(cf);
20f4a2713aSLionel Sambuc // CHECK-NEXT: [[R:%.*]] = load volatile float* getelementptr inbounds ({ float, float }* @cf, i32 0, i32 0), align 4
21f4a2713aSLionel Sambuc // CHECK-NEXT: [[I:%.*]] = load volatile float* getelementptr inbounds ({ float, float }* @cf, i32 0, i32 1), align 4
22f4a2713aSLionel Sambuc // CHECK-NEXT: store volatile float [[R]], float* getelementptr inbounds ({ float, float }* @cf, i32 0, i32 0), align 4
23f4a2713aSLionel Sambuc // CHECK-NEXT: store volatile float [[I]], float* getelementptr inbounds ({ float, float }* @cf, i32 0, i32 1), align 4
24f4a2713aSLionel Sambuc (void)(cf=cf);
25f4a2713aSLionel Sambuc // CHECK-NEXT: ret void
26f4a2713aSLionel Sambuc }
27f4a2713aSLionel Sambuc
28*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define void @test_cd()
test_cd()29f4a2713aSLionel Sambuc void test_cd() {
30f4a2713aSLionel Sambuc // CHECK: load volatile double* getelementptr inbounds ({ double, double }* @cd, i32 0, i32 0), align 8
31f4a2713aSLionel Sambuc // CHECK-NEXT: load volatile double* getelementptr inbounds ({ double, double }* @cd, i32 0, i32 1), align 8
32f4a2713aSLionel Sambuc (void)(cd);
33f4a2713aSLionel Sambuc // CHECK-NEXT: [[R:%.*]] = load volatile double* getelementptr inbounds ({ double, double }* @cd, i32 0, i32 0), align 8
34f4a2713aSLionel Sambuc // CHECK-NEXT: [[I:%.*]] = load volatile double* getelementptr inbounds ({ double, double }* @cd, i32 0, i32 1), align 8
35f4a2713aSLionel Sambuc // CHECK-NEXT: store volatile double [[R]], double* getelementptr inbounds ({ double, double }* @cd, i32 0, i32 0), align 8
36f4a2713aSLionel Sambuc // CHECK-NEXT: store volatile double [[I]], double* getelementptr inbounds ({ double, double }* @cd, i32 0, i32 1), align 8
37f4a2713aSLionel Sambuc (void)(cd=cd);
38f4a2713aSLionel Sambuc // CHECK-NEXT: ret void
39f4a2713aSLionel Sambuc }
40f4a2713aSLionel Sambuc
41*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define void @test_cf32()
test_cf32()42f4a2713aSLionel Sambuc void test_cf32() {
43f4a2713aSLionel Sambuc // CHECK: load volatile float* getelementptr inbounds ({ float, float }* @cf32, i32 0, i32 0), align 32
44f4a2713aSLionel Sambuc // CHECK-NEXT: load volatile float* getelementptr inbounds ({ float, float }* @cf32, i32 0, i32 1), align 4
45f4a2713aSLionel Sambuc (void)(cf32);
46f4a2713aSLionel Sambuc // CHECK-NEXT: [[R:%.*]] = load volatile float* getelementptr inbounds ({ float, float }* @cf32, i32 0, i32 0), align 32
47f4a2713aSLionel Sambuc // CHECK-NEXT: [[I:%.*]] = load volatile float* getelementptr inbounds ({ float, float }* @cf32, i32 0, i32 1), align 4
48f4a2713aSLionel Sambuc // CHECK-NEXT: store volatile float [[R]], float* getelementptr inbounds ({ float, float }* @cf32, i32 0, i32 0), align 32
49f4a2713aSLionel Sambuc // CHECK-NEXT: store volatile float [[I]], float* getelementptr inbounds ({ float, float }* @cf32, i32 0, i32 1), align 4
50f4a2713aSLionel Sambuc (void)(cf32=cf32);
51f4a2713aSLionel Sambuc // CHECK-NEXT: ret void
52f4a2713aSLionel Sambuc }
53f4a2713aSLionel Sambuc
54*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define void @test_cd32()
test_cd32()55f4a2713aSLionel Sambuc void test_cd32() {
56f4a2713aSLionel Sambuc // CHECK: load volatile double* getelementptr inbounds ({ double, double }* @cd32, i32 0, i32 0), align 32
57f4a2713aSLionel Sambuc // CHECK-NEXT: load volatile double* getelementptr inbounds ({ double, double }* @cd32, i32 0, i32 1), align 8
58f4a2713aSLionel Sambuc (void)(cd32);
59f4a2713aSLionel Sambuc // CHECK-NEXT: [[R:%.*]] = load volatile double* getelementptr inbounds ({ double, double }* @cd32, i32 0, i32 0), align 32
60f4a2713aSLionel Sambuc // CHECK-NEXT: [[I:%.*]] = load volatile double* getelementptr inbounds ({ double, double }* @cd32, i32 0, i32 1), align 8
61f4a2713aSLionel Sambuc // CHECK-NEXT: store volatile double [[R]], double* getelementptr inbounds ({ double, double }* @cd32, i32 0, i32 0), align 32
62f4a2713aSLionel Sambuc // CHECK-NEXT: store volatile double [[I]], double* getelementptr inbounds ({ double, double }* @cd32, i32 0, i32 1), align 8
63f4a2713aSLionel Sambuc (void)(cd32=cd32);
64f4a2713aSLionel Sambuc // CHECK-NEXT: ret void
65f4a2713aSLionel Sambuc }
66