Debian Codegraph @

clang/test/CIR/CodeGen/complex.cpp

raw
1 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-cir %s -o %t.cir
2 // RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
3 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll
4 // RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
5 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll
6 // RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
7
8 int _Complex ci;
9
10 float _Complex cf;
11
12 int _Complex ci2 = { 1, 2 };
13
14 float _Complex cf2 = { 1.0f, 2.0f };
15
16 // CIR: cir.global external @ci = #cir.zero : !cir.complex<!s32i>
17 // CIR: cir.global external @cf = #cir.zero : !cir.complex<!cir.float>
18 // CIR: cir.global external @ci2 = #cir.const_complex<#cir.int<1> : !s32i, #cir.int<2> : !s32i> : !cir.complex<!s32i>
19 // CIR: cir.global external @cf2 = #cir.const_complex<#cir.fp<1.000000e+00> : !cir.float, #cir.fp<2.000000e+00> : !cir.float> : !cir.complex<!cir.float>
20
21 // LLVM: {{.*}} = global { i32, i32 } zeroinitializer, align 4
22 // LLVM: {{.*}} = global { float, float } zeroinitializer, align 4
23 // LLVM: {{.*}} = global { i32, i32 } { i32 1, i32 2 }, align 4
24 // LLVM: {{.*}} = global { float, float } { float 1.000000e+00, float 2.000000e+00 }, align 4
25
26 // OGCG: {{.*}} = global { i32, i32 } zeroinitializer, align 4
27 // OGCG: {{.*}} = global { float, float } zeroinitializer, align 4
28 // OGCG: {{.*}} = global { i32, i32 } { i32 1, i32 2 }, align 4
29 // OGCG: {{.*}} = global { float, float } { float 1.000000e+00, float 2.000000e+00 }, align 4
30
31 void foo() { int _Complex c = {}; }
32
33 // CIR: %[[INIT:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["c", init]
34 // CIR: %[[COMPLEX:.*]] = cir.const #cir.zero : !cir.complex<!s32i>
35 // CIR: cir.store{{.*}} %[[COMPLEX]], %[[INIT]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
36
37 // LLVM: %[[INIT:.*]] = alloca { i32, i32 }, i64 1, align 4
38 // LLVM: store { i32, i32 } zeroinitializer, ptr %[[INIT]], align 4
39
40 // OGCG: %[[COMPLEX:.*]] = alloca { i32, i32 }, align 4
41 // OGCG: %[[C_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX]], i32 0, i32 0
42 // OGCG: %[[C_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX]], i32 0, i32 1
43 // OGCG: store i32 0, ptr %[[C_REAL_PTR]], align 4
44 // OGCG: store i32 0, ptr %[[C_IMAG_PTR]], align 4
45
46 void foo2() { int _Complex c = {1, 2}; }
47
48 // CIR: %[[INIT:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["c", init]
49 // CIR: %[[COMPLEX:.*]] = cir.const #cir.const_complex<#cir.int<1> : !s32i, #cir.int<2> : !s32i> : !cir.complex<!s32i>
50 // CIR: cir.store{{.*}} %[[COMPLEX]], %[[INIT]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
51
52 // LLVM: %[[INIT:.*]] = alloca { i32, i32 }, i64 1, align 4
53 // LLVM: store { i32, i32 } { i32 1, i32 2 }, ptr %[[INIT]], align 4
54
55 // OGCG: %[[COMPLEX:.*]] = alloca { i32, i32 }, align 4
56 // OGCG: %[[C_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX]], i32 0, i32 0
57 // OGCG: %[[C_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX]], i32 0, i32 1
58 // OGCG: store i32 1, ptr %[[C_REAL_PTR]], align 4
59 // OGCG: store i32 2, ptr %[[C_IMAG_PTR]], align 4
60
61 void foo3() {
62 int a;
63 int b;
64 int _Complex c = {a, b};
65 }
66
67 // CIR: %[[INIT:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["c", init]
68 // CIR: %[[TMP_A:.*]] = cir.load{{.*}} {{.*}} : !cir.ptr<!s32i>
69 // CIR: %[[TMP_B:.*]] = cir.load{{.*}} {{.*}} : !cir.ptr<!s32i>
70 // CIR: %[[COMPLEX:.*]] = cir.complex.create %[[TMP_A]], %[[TMP_B]] : !s32i -> !cir.complex<!s32i>
71 // CIR: cir.store{{.*}} %[[COMPLEX]], %[[INIT]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
72
73 // LLVM: %[[INIT:.*]] = alloca { i32, i32 }, i64 1, align 4
74 // LLVM: %[[TMP_A:.*]] = load i32, ptr {{.*}}, align 4
75 // LLVM: %[[TMP_B:.*]] = load i32, ptr {{.*}}, align 4
76 // LLVM: %[[TMP:.*]] = insertvalue { i32, i32 } undef, i32 %[[TMP_A]], 0
77 // LLVM: %[[TMP_2:.*]] = insertvalue { i32, i32 } %[[TMP]], i32 %[[TMP_B]], 1
78 // LLVM: store { i32, i32 } %[[TMP_2]], ptr %[[INIT]], align 4
79
80 // OGCG: %[[COMPLEX:.*]] = alloca { i32, i32 }, align 4
81 // OGCG: %[[REAL_VAL:.*]] = load i32, ptr {{.*}}, align 4
82 // OGCG: %[[IMAG_VAL:.*]] = load i32, ptr {{.*}}, align 4
83 // OGCG: %[[C_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX]], i32 0, i32 0
84 // OGCG: %[[C_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX]], i32 0, i32 1
85 // OGCG: store i32 %[[REAL_VAL]], ptr %[[C_REAL_PTR]], align 4
86 // OGCG: store i32 %[[IMAG_VAL]], ptr %[[C_IMAG_PTR]], align 4
87
88 void foo4() {
89 int a;
90 int _Complex c = {1, a};
91 }
92
93 // CIR: %[[INIT:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["c", init]
94 // CIR: %[[CONST_1:.*]] = cir.const #cir.int<1> : !s32i
95 // CIR: %[[TMP_A:.*]] = cir.load{{.*}} {{.*}} : !cir.ptr<!s32i>, !s32i
96 // CIR: %[[COMPLEX:.*]] = cir.complex.create %[[CONST_1]], %[[TMP_A]] : !s32i -> !cir.complex<!s32i>
97 // CIR: cir.store{{.*}} %[[COMPLEX]], %[[INIT]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
98
99 // LLVM: %[[INIT:.*]] = alloca { i32, i32 }, i64 1, align 4
100 // LLVM: %[[TMP_A:.*]] = load i32, ptr {{.*}}, align 4
101 // LLVM: %[[COMPLEX:.*]] = insertvalue { i32, i32 } { i32 1, i32 undef }, i32 %[[TMP_A]], 1
102 // LLVM: store { i32, i32 } %[[COMPLEX]], ptr %[[INIT]], align 4
103
104 // OGCG: %[[COMPLEX:.*]] = alloca { i32, i32 }, align 4
105 // OGCG: %[[TMP_A:.*]] = load i32, ptr {{.*}}, align 4
106 // OGCG: %[[C_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX]], i32 0, i32 0
107 // OGCG: %[[C_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX]], i32 0, i32 1
108 // OGCG: store i32 1, ptr %[[C_REAL_PTR]], align 4
109 // OGCG: store i32 %[[TMP_A]], ptr %[[C_IMAG_PTR]], align 4
110
111 void foo5() {
112 float _Complex c = {1.0f, 2.0f};
113 }
114
115 // CIR: %[[INIT:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["c", init]
116 // CIR: %[[COMPLEX:.*]] = cir.const #cir.const_complex<#cir.fp<1.000000e+00> : !cir.float, #cir.fp<2.000000e+00> : !cir.float> : !cir.complex<!cir.float>
117 // CIR: cir.store{{.*}} %[[COMPLEX]], %[[INIT]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
118
119 // LLVM: %[[INIT:.*]] = alloca { float, float }, i64 1, align 4
120 // LLVM: store { float, float } { float 1.000000e+00, float 2.000000e+00 }, ptr %[[INIT]], align 4
121
122 // OGCG: %[[COMPLEX]] = alloca { float, float }, align 4
123 // OGCG: %[[C_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[COMPLEX]], i32 0, i32 0
124 // OGCG: %[[C_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[COMPLEX]], i32 0, i32 1
125 // OGCG: store float 1.000000e+00, ptr %[[C_REAL_PTR]], align 4
126 // OGCG: store float 2.000000e+00, ptr %[[C_IMAG_PTR]], align 4
127
128 void foo6() {
129 float a;
130 float b;
131 float _Complex c = {a, b};
132 }
133
134 // CIR: %[[INIT:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["c", init]
135 // CIR: %[[TMP_A:.*]] = cir.load{{.*}} {{.*}} : !cir.ptr<!cir.float>, !cir.float
136 // CIR: %[[TMP_B:.*]] = cir.load{{.*}} {{.*}} : !cir.ptr<!cir.float>, !cir.float
137 // CIR: %[[COMPLEX:.*]] = cir.complex.create %[[TMP_A]], %[[TMP_B]] : !cir.float -> !cir.complex<!cir.float>
138 // CIR: cir.store{{.*}} %[[COMPLEX]], %[[INIT]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
139
140 // LLVM: %[[COMPLEX:.*]] = alloca { float, float }, i64 1, align 4
141 // LLVM: %[[TMP_A:.*]] = load float, ptr {{.*}}, align 4
142 // LLVM: %[[TMP_B:.*]] = load float, ptr {{.*}}, align 4
143 // LLVM: %[[TMP:.*]] = insertvalue { float, float } undef, float %[[TMP_A]], 0
144 // LLVM: %[[TMP_2:.*]] = insertvalue { float, float } %[[TMP]], float %[[TMP_B]], 1
145 // LLVM: store { float, float } %[[TMP_2]], ptr %[[COMPLEX]], align 4
146
147 // OGCG: %[[COMPLEX]] = alloca { float, float }, align 4
148 // OGCG: %[[TMP_A:.*]] = load float, ptr {{.*}}, align 4
149 // OGCG: %[[TMP_B:.*]] = load float, ptr {{.*}}, align 4
150 // OGCG: %[[C_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[COMPLEX]], i32 0, i32 0
151 // OGCG: %[[C_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[COMPLEX]], i32 0, i32 1
152 // OGCG: store float %[[TMP_A]], ptr %[[C_REAL_PTR]], align 4
153 // OGCG: store float %[[TMP_B]], ptr %[[C_IMAG_PTR]], align 4
154
155 void foo7() {
156 float a;
157 float _Complex c = {a, 2.0f};
158 }
159
160 // CIR: %[[INIT:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["c", init]
161 // CIR: %[[TMP_A:.*]] = cir.load{{.*}} {{.*}} : !cir.ptr<!cir.float>, !cir.float
162 // CIR: %[[CONST_2F:.*]] = cir.const #cir.fp<2.000000e+00> : !cir.float
163 // CIR: %[[COMPLEX:.*]] = cir.complex.create %[[TMP_A]], %[[CONST_2F]] : !cir.float -> !cir.complex<!cir.float>
164 // CIR: cir.store{{.*}} %[[COMPLEX]], %[[INIT]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
165
166 // LLVM: %[[COMPLEX:.*]] = alloca { float, float }, i64 1, align 4
167 // LLVM: %[[TMP_A:.*]] = load float, ptr {{.*}}, align 4
168 // LLVM: %[[TMP:.*]] = insertvalue { float, float } undef, float %[[TMP_A]], 0
169 // LLVM: %[[TMP_2:.*]] = insertvalue { float, float } %[[TMP]], float 2.000000e+00, 1
170 // LLVM: store { float, float } %[[TMP_2]], ptr %[[COMPLEX]], align 4
171
172 // OGCG: %[[COMPLEX:.*]] = alloca { float, float }, align 4
173 // OGCG: %[[TMP_A:.*]] = load float, ptr {{.*}}, align 4
174 // OGCG: %[[C_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[COMPLEX]], i32 0, i32 0
175 // OGCG: %[[C_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[COMPLEX]], i32 0, i32 1
176 // OGCG: store float %[[TMP_A]], ptr %[[C_REAL_PTR]], align 4
177 // OGCG: store float 2.000000e+00, ptr %[[C_IMAG_PTR]], align 4
178
179 void foo8() {
180 double _Complex c = 2.00i;
181 }
182
183 // CIR: %[[COMPLEX:.*]] = cir.const #cir.const_complex<#cir.fp<0.000000e+00> : !cir.double, #cir.fp<2.000000e+00> : !cir.double> : !cir.complex<!cir.double>
184
185 // LLVM: %[[COMPLEX:.*]] = alloca { double, double }, i64 1, align 8
186 // LLVM: store { double, double } { double 0.000000e+00, double 2.000000e+00 }, ptr %[[COMPLEX]], align 8
187
188 // OGCG: %[[COMPLEX:.*]] = alloca { double, double }, align 8
189 // OGCG: %[[C_REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX]], i32 0, i32 0
190 // OGCG: %[[C_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX]], i32 0, i32 1
191 // OGCG: store double 0.000000e+00, ptr %[[C_REAL_PTR]], align 8
192 // OGCG: store double 2.000000e+00, ptr %[[C_IMAG_PTR]], align 8
193
194 void foo9(double a, double b) {
195 double _Complex c = __builtin_complex(a, b);
196 }
197
198 // CIR: %[[INIT:.*]] = cir.alloca !cir.complex<!cir.double>, !cir.ptr<!cir.complex<!cir.double>>, ["c", init]
199 // CIR: %[[TMP_A:.*]] = cir.load{{.*}} {{.*}} : !cir.ptr<!cir.double>, !cir.double
200 // CIR: %[[TMP_B:.*]] = cir.load{{.*}} {{.*}} : !cir.ptr<!cir.double>, !cir.double
201 // CIR: %[[COMPLEX:.*]] = cir.complex.create %[[TMP_A]], %[[TMP_B]] : !cir.double -> !cir.complex<!cir.double>
202 // CIR: cir.store{{.*}} %[[COMPLEX]], %[[INIT]] : !cir.complex<!cir.double>, !cir.ptr<!cir.complex<!cir.double>>
203
204 // LLVM: %[[COMPLEX:.*]] = alloca { double, double }, i64 1, align 8
205 // LLVM: %[[TMP_A:.*]] = load double, ptr {{.*}}, align 8
206 // LLVM: %[[TMP_B:.*]] = load double, ptr {{.*}}, align 8
207 // LLVM: %[[TMP:.*]] = insertvalue { double, double } undef, double %[[TMP_A]], 0
208 // LLVM: %[[TMP_2:.*]] = insertvalue { double, double } %[[TMP]], double %[[TMP_B]], 1
209 // LLVM: store { double, double } %[[TMP_2]], ptr %[[COMPLEX]], align 8
210
211 // OGCG: %[[COMPLEX]] = alloca { double, double }, align 8
212 // OGCG: %[[TMP_A:.*]] = load double, ptr {{.*}}, align 8
213 // OGCG: %[[TMP_B:.*]] = load double, ptr {{.*}}, align 8
214 // OGCG: %[[C_REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX]], i32 0, i32 0
215 // OGCG: %[[C_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX]], i32 0, i32 1
216 // OGCG: store double %[[TMP_A]], ptr %[[C_REAL_PTR]], align 8
217 // OGCG: store double %[[TMP_B]], ptr %[[C_IMAG_PTR]], align 8
218
219 void foo10() {
220 double _Complex c;
221 double *realPtr = &__real__ c;
222 }
223
224 // CIR: %[[COMPLEX:.*]] = cir.alloca !cir.complex<!cir.double>, !cir.ptr<!cir.complex<!cir.double>>, ["c"]
225 // CIR: %[[REAL_PTR:.*]] = cir.complex.real_ptr %[[COMPLEX]] : !cir.ptr<!cir.complex<!cir.double>> -> !cir.ptr<!cir.double>
226
227 // LLVM: %[[COMPLEX:.*]] = alloca { double, double }, i64 1, align 8
228 // LLVM: %[[REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX]], i32 0, i32 0
229
230 // OGCG: %[[COMPLEX:.*]] = alloca { double, double }, align 8
231 // OGCG: %[[REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX]], i32 0, i32 0
232
233 void foo11() {
234 double _Complex c;
235 double *imagPtr = &__imag__ c;
236 }
237
238 // CIR: %[[COMPLEX:.*]] = cir.alloca !cir.complex<!cir.double>, !cir.ptr<!cir.complex<!cir.double>>, ["c"]
239 // CIR: %[[IMAG_PTR:.*]] = cir.complex.imag_ptr %[[COMPLEX]] : !cir.ptr<!cir.complex<!cir.double>> -> !cir.ptr<!cir.double>
240
241 // LLVM: %[[COMPLEX:.*]] = alloca { double, double }, i64 1, align 8
242 // LLVM: %[[IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX]], i32 0, i32 1
243
244 // OGCG: %[[COMPLEX:.*]] = alloca { double, double }, align 8
245 // OGCG: %[[IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX]], i32 0, i32 1
246
247 void foo12() {
248 double _Complex c;
249 double imag = __imag__ c;
250 }
251
252 // CIR: %[[COMPLEX:.*]] = cir.alloca !cir.complex<!cir.double>, !cir.ptr<!cir.complex<!cir.double>>, ["c"]
253 // CIR: %[[INIT:.*]] = cir.alloca !cir.double, !cir.ptr<!cir.double>, ["imag", init]
254 // CIR: %[[TMP:.*]] = cir.load{{.*}} %[[COMPLEX]] : !cir.ptr<!cir.complex<!cir.double>>, !cir.complex<!cir.double>
255 // CIR: %[[IMAG:.*]] = cir.complex.imag %[[TMP]] : !cir.complex<!cir.double> -> !cir.double
256 // CIR: cir.store{{.*}} %[[IMAG]], %[[INIT]] : !cir.double, !cir.ptr<!cir.double>
257
258 // LLVM: %[[COMPLEX:.*]] = alloca { double, double }, i64 1, align 8
259 // LLVM: %[[INIT:.*]] = alloca double, i64 1, align 8
260 // LLVM: %[[TMP:.*]] = load { double, double }, ptr %[[COMPLEX]], align 8
261 // LLVM: %[[IMAG:.*]] = extractvalue { double, double } %[[TMP]], 1
262 // LLVM: store double %[[IMAG]], ptr %[[INIT]], align 8
263
264 // OGCG: %[[COMPLEX:.*]] = alloca { double, double }, align 8
265 // OGCG: %[[INIT:.*]] = alloca double, align 8
266 // OGCG: %[[IMAG:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX]], i32 0, i32 1
267 // OGCG: %[[TMP:.*]] = load double, ptr %[[IMAG]], align 8
268 // OGCG: store double %[[TMP]], ptr %[[INIT]], align 8
269
270 void foo13() {
271 double _Complex c;
272 double real = __real__ c;
273 }
274
275 // CIR: %[[COMPLEX:.*]] = cir.alloca !cir.complex<!cir.double>, !cir.ptr<!cir.complex<!cir.double>>, ["c"]
276 // CIR: %[[INIT:.*]] = cir.alloca !cir.double, !cir.ptr<!cir.double>, ["real", init]
277 // CIR: %[[TMP:.*]] = cir.load{{.*}} %[[COMPLEX]] : !cir.ptr<!cir.complex<!cir.double>>, !cir.complex<!cir.double>
278 // CIR: %[[REAL:.*]] = cir.complex.real %[[TMP]] : !cir.complex<!cir.double> -> !cir.double
279 // CIR: cir.store{{.*}} %[[REAL]], %[[INIT]] : !cir.double, !cir.ptr<!cir.double>
280
281 // LLVM: %[[COMPLEX:.*]] = alloca { double, double }, i64 1, align 8
282 // LLVM: %[[INIT:.*]] = alloca double, i64 1, align 8
283 // LLVM: %[[TMP:.*]] = load { double, double }, ptr %[[COMPLEX]], align 8
284 // LLVM: %[[REAL:.*]] = extractvalue { double, double } %[[TMP]], 0
285 // LLVM: store double %[[REAL]], ptr %[[INIT]], align 8
286
287 // OGCG: %[[COMPLEX:.*]] = alloca { double, double }, align 8
288 // OGCG: %[[INIT:.*]] = alloca double, align 8
289 // OGCG: %[[REAL:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX]], i32 0, i32 0
290 // OGCG: %[[TMP:.*]] = load double, ptr %[[REAL]], align 8
291 // OGCG: store double %[[TMP]], ptr %[[INIT]], align 8
292
293
294 void foo14() {
295 int _Complex c = 2i;
296 }
297
298 // CIR: %[[COMPLEX:.*]] = cir.const #cir.const_complex<#cir.int<0> : !s32i, #cir.int<2> : !s32i> : !cir.complex<!s32i>
299
300 // LLVM: %[[COMPLEX:.*]] = alloca { i32, i32 }, i64 1, align 4
301 // LLVM: store { i32, i32 } { i32 0, i32 2 }, ptr %[[COMPLEX]], align 4
302
303 // OGCG: %[[COMPLEX:.*]] = alloca { i32, i32 }, align 4
304 // OGCG: %[[C_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX]], i32 0, i32 0
305 // OGCG: %[[C_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX]], i32 0, i32 1
306 // OGCG: store i32 0, ptr %[[C_REAL_PTR]], align 4
307 // OGCG: store i32 2, ptr %[[C_IMAG_PTR]], align 4
308
309 void foo15() {
310 int _Complex a;
311 int _Complex b = a;
312 }
313
314 // CIR: %[[COMPLEX_A:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["a"]
315 // CIR: %[[COMPLEX_B:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["b", init]
316 // CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[COMPLEX_A]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
317 // CIR: cir.store{{.*}} %[[TMP_A]], %[[COMPLEX_B]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
318
319 // LLVM: %[[COMPLEX_A:.*]] = alloca { i32, i32 }, i64 1, align 4
320 // LLVM: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, i64 1, align 4
321 // LLVM: %[[TMP_A:.*]] = load { i32, i32 }, ptr %[[COMPLEX_A]], align 4
322 // LLVM: store { i32, i32 } %[[TMP_A]], ptr %[[COMPLEX_B]], align 4
323
324 // OGCG: %[[COMPLEX_A:.*]] = alloca { i32, i32 }, align 4
325 // OGCG: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, align 4
326 // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_A]], i32 0, i32 0
327 // OGCG: %[[A_REAL:.*]] = load i32, ptr %[[A_REAL_PTR]], align 4
328 // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_A]], i32 0, i32 1
329 // OGCG: %[[A_IMAG:.*]] = load i32, ptr %[[A_IMAG_PTR]], align 4
330 // OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 0
331 // OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 1
332 // OGCG: store i32 %[[A_REAL]], ptr %[[B_REAL_PTR]], align 4
333 // OGCG: store i32 %[[A_IMAG]], ptr %[[B_IMAG_PTR]], align 4
334
335 int foo16(int _Complex a, int _Complex b) {
336 return __imag__ a + __imag__ b;
337 }
338
339 // CIR: %[[RET:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["__retval"]
340 // CIR: %[[COMPLEX_A:.*]] = cir.load{{.*}} {{.*}} : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
341 // CIR: %[[A_IMAG:.*]] = cir.complex.imag %[[COMPLEX_A]] : !cir.complex<!s32i> -> !s32i
342 // CIR: %[[COMPLEX_B:.*]] = cir.load{{.*}} {{.*}} : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
343 // CIR: %[[B_IMAG:.*]] = cir.complex.imag %[[COMPLEX_B]] : !cir.complex<!s32i> -> !s32i
344 // CIR: %[[ADD:.*]] = cir.binop(add, %[[A_IMAG]], %[[B_IMAG]]) nsw : !s32i
345 // CIR: cir.store %[[ADD]], %[[RET]] : !s32i, !cir.ptr<!s32i>
346 // CIR: %[[TMP:.*]] = cir.load %[[RET]] : !cir.ptr<!s32i>, !s32i
347 // CIR: cir.return %[[TMP]] : !s32i
348
349 // LLVM: %[[RET:.*]] = alloca i32, i64 1, align 4
350 // LLVM: %[[COMPLEX_A:.*]] = load { i32, i32 }, ptr {{.*}}, align 4
351 // LLVM: %[[A_IMAG:.*]] = extractvalue { i32, i32 } %[[COMPLEX_A]], 1
352 // LLVM: %[[COMPLEX_B:.*]] = load { i32, i32 }, ptr {{.*}}, align 4
353 // LLVM: %[[B_IMAG:.*]] = extractvalue { i32, i32 } %[[COMPLEX_B]], 1
354 // LLVM: %[[ADD:.*]] = add nsw i32 %[[A_IMAG]], %[[B_IMAG]]
355 // LLVM: store i32 %[[ADD]], ptr %[[RET]], align 4
356 // LLVM: %[[TMP:.*]] = load i32, ptr %[[RET]], align 4
357 // LLVM: ret i32 %[[TMP]]
358
359 // OGCG: %[[COMPLEX_A:.*]] = alloca { i32, i32 }, align 4
360 // OGCG: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, align 4
361 // OGCG: %[[A_IMAG:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_A]], i32 0, i32 1
362 // OGCG: %[[TMP_A:.*]] = load i32, ptr %[[A_IMAG]], align 4
363 // OGCG: %[[B_IMAG:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 1
364 // OGCG: %[[TMP_B:.*]] = load i32, ptr %[[B_IMAG]], align 4
365 // OGCG: %[[ADD:.*]] = add nsw i32 %[[TMP_A]], %[[TMP_B]]
366 // OGCG: ret i32 %[[ADD]]
367
368 int foo17(int _Complex a, int _Complex b) {
369 return __real__ a + __real__ b;
370 }
371
372 // CIR: %[[RET:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["__retval"]
373 // CIR: %[[COMPLEX_A:.*]] = cir.load{{.*}} {{.*}} : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
374 // CIR: %[[A_REAL:.*]] = cir.complex.real %[[COMPLEX_A]] : !cir.complex<!s32i> -> !s32i
375 // CIR: %[[COMPLEX_B:.*]] = cir.load{{.*}} {{.*}} : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
376 // CIR: %[[B_REAL:.*]] = cir.complex.real %[[COMPLEX_B]] : !cir.complex<!s32i> -> !s32i
377 // CIR: %[[ADD:.*]] = cir.binop(add, %[[A_REAL]], %[[B_REAL]]) nsw : !s32i
378 // CIR: cir.store %[[ADD]], %[[RET]] : !s32i, !cir.ptr<!s32i>
379 // CIR: %[[TMP:.*]] = cir.load %[[RET]] : !cir.ptr<!s32i>, !s32i
380 // CIR: cir.return %[[TMP]] : !s32i
381
382 // LLVM: %[[RET:.*]] = alloca i32, i64 1, align 4
383 // LLVM: %[[COMPLEX_A:.*]] = load { i32, i32 }, ptr {{.*}}, align 4
384 // LLVM: %[[A_REAL:.*]] = extractvalue { i32, i32 } %[[COMPLEX_A]], 0
385 // LLVM: %[[COMPLEX_B:.*]] = load { i32, i32 }, ptr {{.*}}, align 4
386 // LLVM: %[[B_REAL:.*]] = extractvalue { i32, i32 } %[[COMPLEX_B]], 0
387 // LLVM: %[[ADD:.*]] = add nsw i32 %[[A_REAL]], %[[B_REAL]]
388 // LLVM: store i32 %[[ADD]], ptr %[[RET]], align 4
389 // LLVM: %[[TMP:.*]] = load i32, ptr %[[RET]], align 4
390 // LLVM: ret i32 %[[TMP]]
391
392 // OGCG: %[[COMPLEX_A:.*]] = alloca { i32, i32 }, align 4
393 // OGCG: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, align 4
394 // OGCG: %[[A_REAL:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_A]], i32 0, i32 0
395 // OGCG: %[[TMP_A:.*]] = load i32, ptr %[[A_REAL]], align 4
396 // OGCG: %[[B_REAL:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 0
397 // OGCG: %[[TMP_B:.*]] = load i32, ptr %[[B_REAL]], align 4
398 // OGCG: %[[ADD:.*]] = add nsw i32 %[[TMP_A]], %[[TMP_B]]
399 // OGCG: ret i32 %[[ADD]]
400
401 bool foo18(int _Complex a, int _Complex b) {
402 return a == b;
403 }
404
405 // CIR: %[[COMPLEX_A:.*]] = cir.load{{.*}} {{.*}} : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
406 // CIR: %[[COMPLEX_B:.*]] = cir.load{{.*}} {{.*}} : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
407 // CIR: %[[RESULT:.*]] = cir.cmp(eq, %[[COMPLEX_A]], %[[COMPLEX_B]]) : !cir.complex<!s32i>, !cir.bool
408
409 // LLVM: %[[COMPLEX_A:.*]] = load { i32, i32 }, ptr {{.*}}, align 4
410 // LLVM: %[[COMPLEX_B:.*]] = load { i32, i32 }, ptr {{.*}}, align 4
411 // LLVM: %[[A_REAL:.*]] = extractvalue { i32, i32 } %[[COMPLEX_A]], 0
412 // LLVM: %[[A_IMAG:.*]] = extractvalue { i32, i32 } %[[COMPLEX_A]], 1
413 // LLVM: %[[B_REAL:.*]] = extractvalue { i32, i32 } %[[COMPLEX_B]], 0
414 // LLVM: %[[B_IMAG:.*]] = extractvalue { i32, i32 } %[[COMPLEX_B]], 1
415 // LLVM: %[[CMP_REAL:.*]] = icmp eq i32 %[[A_REAL]], %[[B_REAL]]
416 // LLVM: %[[CMP_IMAG:.*]] = icmp eq i32 %[[A_IMAG]], %[[B_IMAG]]
417 // LLVM: %[[RESULT:.*]] = and i1 %[[CMP_REAL]], %[[CMP_IMAG]]
418
419 // OGCG: %[[COMPLEX_A:.*]] = alloca { i32, i32 }, align 4
420 // OGCG: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, align 4
421 // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_A]], i32 0, i32 0
422 // OGCG: %[[A_REAL:.*]] = load i32, ptr %[[A_REAL_PTR]], align 4
423 // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_A]], i32 0, i32 1
424 // OGCG: %[[A_IMAG:.*]] = load i32, ptr %[[A_IMAG_PTR]], align 4
425 // OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 0
426 // OGCG: %[[B_REAL:.*]] = load i32, ptr %[[B_REAL_PTR]], align 4
427 // OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 1
428 // OGCG: %[[B_IMAG:.*]] = load i32, ptr %[[B_IMAG_PTR]], align 4
429 // OGCG: %[[CMP_REAL:.*]] = icmp eq i32 %[[A_REAL]], %[[B_REAL]]
430 // OGCG: %[[CMP_IMAG:.*]] = icmp eq i32 %[[A_IMAG]], %[[B_IMAG]]
431 // OGCG: %[[RESULT:.*]] = and i1 %[[CMP_REAL]], %[[CMP_IMAG]]
432
433 bool foo19(double _Complex a, double _Complex b) {
434 return a == b;
435 }
436
437 // CIR: %[[COMPLEX_A:.*]] = cir.load{{.*}} {{.*}} : !cir.ptr<!cir.complex<!cir.double>>, !cir.complex<!cir.double>
438 // CIR: %[[COMPLEX_B:.*]] = cir.load{{.*}} {{.*}} : !cir.ptr<!cir.complex<!cir.double>>, !cir.complex<!cir.double>
439 // CIR: %[[RESULT:.*]] = cir.cmp(eq, %[[COMPLEX_A]], %[[COMPLEX_B]]) : !cir.complex<!cir.double>, !cir.bool
440
441
442 // LLVM: %[[COMPLEX_A:.*]] = load { double, double }, ptr {{.*}}, align 8
443 // LLVM: %[[COMPLEX_B:.*]] = load { double, double }, ptr {{.*}}, align 8
444 // LLVM: %[[A_REAL:.*]] = extractvalue { double, double } %[[COMPLEX_A]], 0
445 // LLVM: %[[A_IMAG:.*]] = extractvalue { double, double } %[[COMPLEX_A]], 1
446 // LLVM: %[[B_REAL:.*]] = extractvalue { double, double } %[[COMPLEX_B]], 0
447 // LLVM: %[[B_IMAG:.*]] = extractvalue { double, double } %[[COMPLEX_B]], 1
448 // LLVM: %[[CMP_REAL:.*]] = fcmp oeq double %[[A_REAL]], %[[B_REAL]]
449 // LLVM: %[[CMP_IMAG:.*]] = fcmp oeq double %[[A_IMAG]], %[[B_IMAG]]
450 // LLVM: %[[RESULT:.*]] = and i1 %[[CMP_REAL]], %[[CMP_IMAG]]
451
452 // OGCG: %[[COMPLEX_A:.*]] = alloca { double, double }, align 8
453 // OGCG: %[[COMPLEX_B:.*]] = alloca { double, double }, align 8
454 // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX_A]], i32 0, i32 0
455 // OGCG: store double {{.*}}, ptr %[[A_REAL_PTR]], align 8
456 // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX_A]], i32 0, i32 1
457 // OGCG: store double {{.*}}, ptr %[[A_IMAG_PTR]], align 8
458 // OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX_B]], i32 0, i32 0
459 // OGCG: store double {{.*}}, ptr %[[B_REAL_PTR]], align 8
460 // OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX_B]], i32 0, i32 1
461 // OGCG: store double {{.*}}, ptr %[[B_IMAG_PTR]], align 8
462 // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX_A]], i32 0, i32 0
463 // OGCG: %[[A_REAL:.*]] = load double, ptr %[[A_REAL_PTR]], align 8
464 // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX_A]], i32 0, i32 1
465 // OGCG: %[[A_IMAG:.*]] = load double, ptr %[[A_IMAG_PTR]], align 8
466 // OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX_B]], i32 0, i32 0
467 // OGCG: %[[B_REAL:.*]] = load double, ptr %[[B_REAL_PTR]], align 8
468 // OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX_B]], i32 0, i32 1
469 // OGCG: %[[B_IMAG:.*]] = load double, ptr %[[B_IMAG_PTR]], align 8
470 // OGCG: %[[CMP_REAL:.*]] = fcmp oeq double %[[A_REAL]], %[[B_REAL]]
471 // OGCG: %[[CMP_IMAG:.*]] = fcmp oeq double %[[A_IMAG]], %[[B_IMAG]]
472 // OGCG: %[[RESULT:.*]] = and i1 %[[CMP_REAL]], %[[CMP_IMAG]]
473
474
475 bool foo20(int _Complex a, int _Complex b) {
476 return a != b;
477 }
478
479 // CIR: %[[COMPLEX_A:.*]] = cir.load{{.*}} {{.*}} : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
480 // CIR: %[[COMPLEX_B:.*]] = cir.load{{.*}} {{.*}} : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
481 // CIR: %[[RESULT:.*]] = cir.cmp(ne, %[[COMPLEX_A]], %[[COMPLEX_B]]) : !cir.complex<!s32i>, !cir.bool
482
483 // LLVM: %[[COMPLEX_A:.*]] = load { i32, i32 }, ptr {{.*}}, align 4
484 // LLVM: %[[COMPLEX_B:.*]] = load { i32, i32 }, ptr {{.*}}, align 4
485 // LLVM: %[[A_REAL:.*]] = extractvalue { i32, i32 } %[[COMPLEX_A]], 0
486 // LLVM: %[[A_IMAG:.*]] = extractvalue { i32, i32 } %[[COMPLEX_A]], 1
487 // LLVM: %[[B_REAL:.*]] = extractvalue { i32, i32 } %[[COMPLEX_B]], 0
488 // LLVM: %[[B_IMAG:.*]] = extractvalue { i32, i32 } %[[COMPLEX_B]], 1
489 // LLVM: %[[CMP_REAL:.*]] = icmp ne i32 %[[A_REAL]], %[[B_REAL]]
490 // LLVM: %[[CMP_IMAG:.*]] = icmp ne i32 %[[A_IMAG]], %[[B_IMAG]]
491 // LLVM: %[[RESULT:.*]] = or i1 %[[CMP_REAL]], %[[CMP_IMAG]]
492
493 // OGCG: %[[COMPLEX_A:.*]] = alloca { i32, i32 }, align 4
494 // OGCG: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, align 4
495 // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_A]], i32 0, i32 0
496 // OGCG: %[[A_REAL:.*]] = load i32, ptr %[[A_REAL_PTR]], align 4
497 // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_A]], i32 0, i32 1
498 // OGCG: %[[A_IMAG:.*]] = load i32, ptr %[[A_IMAG_PTR]], align 4
499 // OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 0
500 // OGCG: %[[B_REAL:.*]] = load i32, ptr %[[B_REAL_PTR]], align 4
501 // OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 1
502 // OGCG: %[[B_IMAG:.*]] = load i32, ptr %[[B_IMAG_PTR]], align 4
503 // OGCG: %[[CMP_REAL:.*]] = icmp ne i32 %[[A_REAL]], %[[B_REAL]]
504 // OGCG: %[[CMP_IMAG:.*]] = icmp ne i32 %[[A_IMAG]], %[[B_IMAG]]
505 // OGCG: %[[RESULT:.*]] = or i1 %[[CMP_REAL]], %[[CMP_IMAG]]
506
507 bool foo21(double _Complex a, double _Complex b) {
508 return a != b;
509 }
510
511 // CIR: %[[COMPLEX_A:.*]] = cir.load{{.*}} {{.*}} : !cir.ptr<!cir.complex<!cir.double>>, !cir.complex<!cir.double>
512 // CIR: %[[COMPLEX_B:.*]] = cir.load{{.*}} {{.*}} : !cir.ptr<!cir.complex<!cir.double>>, !cir.complex<!cir.double>
513 // CIR: %[[RESULT:.*]] = cir.cmp(ne, %[[COMPLEX_A]], %[[COMPLEX_B]]) : !cir.complex<!cir.double>, !cir.bool
514
515 // LLVM: %[[COMPLEX_A:.*]] = load { double, double }, ptr {{.*}}, align 8
516 // LLVM: %[[COMPLEX_B:.*]] = load { double, double }, ptr {{.*}}, align 8
517 // LLVM: %[[A_REAL:.*]] = extractvalue { double, double } %[[COMPLEX_A]], 0
518 // LLVM: %[[A_IMAG:.*]] = extractvalue { double, double } %[[COMPLEX_A]], 1
519 // LLVM: %[[B_REAL:.*]] = extractvalue { double, double } %[[COMPLEX_B]], 0
520 // LLVM: %[[B_IMAG:.*]] = extractvalue { double, double } %[[COMPLEX_B]], 1
521 // LLVM: %[[CMP_REAL:.*]] = fcmp une double %[[A_REAL]], %[[B_REAL]]
522 // LLVM: %[[CMP_IMAG:.*]] = fcmp une double %[[A_IMAG]], %[[B_IMAG]]
523 // LLVM: %[[RESULT:.*]] = or i1 %[[CMP_REAL]], %[[CMP_IMAG]]
524
525 // OGCG: %[[COMPLEX_A:.*]] = alloca { double, double }, align 8
526 // OGCG: %[[COMPLEX_B:.*]] = alloca { double, double }, align 8
527 // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX_A]], i32 0, i32 0
528 // OGCG: store double {{.*}}, ptr %[[A_REAL_PTR]], align 8
529 // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX_A]], i32 0, i32 1
530 // OGCG: store double {{.*}}, ptr %[[A_IMAG_PTR]], align 8
531 // OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX_B]], i32 0, i32 0
532 // OGCG: store double {{.*}}, ptr %[[B_REAL_PTR]], align 8
533 // OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX_B]], i32 0, i32 1
534 // OGCG: store double {{.*}}, ptr %[[B_IMAG_PTR]], align 8
535 // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX_A]], i32 0, i32 0
536 // OGCG: %[[A_REAL:.*]] = load double, ptr %[[A_REAL_PTR]], align 8
537 // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX_A]], i32 0, i32 1
538 // OGCG: %[[A_IMAG:.*]] = load double, ptr %[[A_IMAG_PTR]], align 8
539 // OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX_B]], i32 0, i32 0
540 // OGCG: %[[B_REAL:.*]] = load double, ptr %[[B_REAL_PTR]], align 8
541 // OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX_B]], i32 0, i32 1
542 // OGCG: %[[B_IMAG:.*]] = load double, ptr %[[B_IMAG_PTR]], align 8
543 // OGCG: %[[CMP_REAL:.*]] = fcmp une double %[[A_REAL]], %[[B_REAL]]
544 // OGCG: %[[CMP_IMAG:.*]] = fcmp une double %[[A_IMAG]], %[[B_IMAG]]
545 // OGCG: %[[RESULT:.*]] = or i1 %[[CMP_REAL]], %[[CMP_IMAG]]
546
547 void foo22(int _Complex a, int _Complex b) {
548 int _Complex c = (a, b);
549 }
550
551 // CIR: %[[COMPLEX_A:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["a", init]
552 // CIR: %[[COMPLEX_B:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["b", init]
553 // CIR: %[[RESULT:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["c", init]
554 // CIR: %[[TMP_B:.*]] = cir.load{{.*}} %[[COMPLEX_B]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
555 // CIR: cir.store{{.*}} %[[TMP_B]], %[[RESULT]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
556
557 // LLVM: %[[COMPLEX_A:.*]] = alloca { i32, i32 }, i64 1, align 4
558 // LLVM: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, i64 1, align 4
559 // LLVM: %[[RESULT:.*]] = alloca { i32, i32 }, i64 1, align 4
560 // LLVM: %[[TMP_B:.*]] = load { i32, i32 }, ptr %[[COMPLEX_B]], align 4
561 // LLVM: store { i32, i32 } %[[TMP_B]], ptr %[[RESULT]], align 4
562
563 // OGCG: %[[COMPLEX_A:.*]] = alloca { i32, i32 }, align 4
564 // OGCG: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, align 4
565 // OGCG: %[[RESULT:.*]] = alloca { i32, i32 }, align 4
566 // OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 0
567 // OGCG: %[[B_REAL:.*]] = load i32, ptr %[[B_REAL_PTR]], align 4
568 // OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 1
569 // OGCG: %[[B_IMAG:.*]] = load i32, ptr %[[B_IMAG_PTR]], align 4
570 // OGCG: %[[RESULT_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[RESULT]], i32 0, i32 0
571 // OGCG: %[[RESULT_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[RESULT]], i32 0, i32 1
572 // OGCG: store i32 %[[B_REAL]], ptr %[[RESULT_REAL_PTR]], align 4
573 // OGCG: store i32 %[[B_IMAG]], ptr %[[RESULT_IMAG_PTR]], align 4
574
575 void foo23(int _Complex a, int _Complex b) {
576 float _Complex f;
577 int _Complex c = _Generic(a, int _Complex: b, default: f);
578 }
579
580 // CIR: %[[COMPLEX_A:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["a", init]
581 // CIR: %[[COMPLEX_B:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["b", init]
582 // CIR: %[[COMPLEX_F:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["f"]
583 // CIR: %[[RESULT:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["c", init]
584 // CIR: %[[TMP:.*]] = cir.load{{.*}} %[[COMPLEX_B]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
585 // CIR: cir.store{{.*}} %[[TMP]], %[[RESULT]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
586
587 // LLVM: %[[COMPLEX_A:.*]] = alloca { i32, i32 }, i64 1, align 4
588 // LLVM: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, i64 1, align 4
589 // LLVM: %[[COMPLEX_F:.*]] = alloca { float, float }, i64 1, align 4
590 // LLVM: %[[RESULT:.*]] = alloca { i32, i32 }, i64 1, align 4
591 // LLVM: %[[TMP:.*]] = load { i32, i32 }, ptr %[[COMPLEX_B]], align 4
592 // LLVM: store { i32, i32 } %[[TMP]], ptr %[[RESULT]], align 4
593
594 // OGCG: %[[COMPLEX_A:.*]] = alloca { i32, i32 }, align 4
595 // OGCG: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, align 4
596 // OGCG: %[[COMPLEX_F:.*]] = alloca { float, float }, align 4
597 // OGCG: %[[RESULT:.*]] = alloca { i32, i32 }, align 4
598 // OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 0
599 // OGCG: %[[B_REAL:.*]] = load i32, ptr %[[B_REAL_PTR]], align 4
600 // OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 1
601 // OGCG: %[[B_IMAG:.*]] = load i32, ptr %[[B_IMAG_PTR]], align 4
602 // OGCG: %[[RESULT_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[RESULT]], i32 0, i32 0
603 // OGCG: %[[RESULT_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[RESULT]], i32 0, i32 1
604 // OGCG: store i32 %[[B_REAL]], ptr %[[RESULT_REAL_PTR]], align 4
605 // OGCG: store i32 %[[B_IMAG]], ptr %[[RESULT_IMAG_PTR]], align 4
606
607 void foo24() {
608 int _Complex arr[2];
609 int _Complex r = arr[1];
610 }
611
612 // CIR: %[[ARR:.*]] = cir.alloca !cir.array<!cir.complex<!s32i> x 2>, !cir.ptr<!cir.array<!cir.complex<!s32i> x 2>>, ["arr"]
613 // CIR: %[[RESULT:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["r", init]
614 // CIR: %[[IDX:.*]] = cir.const #cir.int<1> : !s32i
615 // CIR: %[[RESULT_VAL:.*]] = cir.get_element %[[ARR]][%[[IDX]] : !s32i] : !cir.ptr<!cir.array<!cir.complex<!s32i> x 2>> -> !cir.ptr<!cir.complex<!s32i>>
616 // CIR: %[[TMP:.*]] = cir.load{{.*}} %[[RESULT_VAL]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
617 // CIR: cir.store{{.*}} %[[TMP]], %[[RESULT]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
618
619 // LLVM: %[[ARR:.*]] = alloca [2 x { i32, i32 }], i64 1, align 16
620 // LLVM: %[[RESULT:.*]] = alloca { i32, i32 }, i64 1, align 4
621 // LLVM: %[[RESULT_VAL:.*]] = getelementptr [2 x { i32, i32 }], ptr %[[ARR]], i32 0, i64 1
622 // LLVM: %[[TMP:.*]] = load { i32, i32 }, ptr %[[RESULT_VAL]], align 8
623 // LLVM: store { i32, i32 } %[[TMP]], ptr %[[RESULT]], align 4
624
625 // OGCG: %[[ARR:.*]] = alloca [2 x { i32, i32 }], align 16
626 // OGCG: %[[RESULT:.*]] = alloca { i32, i32 }, align 4
627 // OGCG: %[[ELEM_PTR:.*]] = getelementptr inbounds [2 x { i32, i32 }], ptr %[[ARR]], i64 0, i64 1
628 // OGCG: %[[ELEM_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[ELEM_PTR]], i32 0, i32 0
629 // OGCG: %[[ELEM_REAL:.*]] = load i32, ptr %[[ELEM_REAL_PTR]]
630 // OGCG: %[[ELEM_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[ELEM_PTR]], i32 0, i32 1
631 // OGCG: %[[ELEM_IMAG:.*]] = load i32, ptr %[[ELEM_IMAG_PTR]]
632 // OGCG: %[[RESULT_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[RESULT]], i32 0, i32 0
633 // OGCG: %[[RESULT_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[RESULT]], i32 0, i32 1
634 // OGCG: store i32 %[[ELEM_REAL]], ptr %[[RESULT_REAL_PTR]], align 4
635 // OGCG: store i32 %[[ELEM_IMAG]], ptr %[[RESULT_IMAG_PTR]], align 4
636
637 template <double _Complex N> void template_foo() { double _Complex C = N; }
638
639 void foo25() {
640 template_foo<__builtin_complex(1.0, 2.0)>();
641 }
642
643 // CIR: %[[INIT:.*]] = cir.alloca !cir.complex<!cir.double>, !cir.ptr<!cir.complex<!cir.double>>, ["C", init]
644 // CIR: %[[COMPLEX:.*]] = cir.const #cir.const_complex<#cir.fp<1.000000e+00> : !cir.double, #cir.fp<2.000000e+00> : !cir.double> : !cir.complex<!cir.double>
645 // CIR: cir.store{{.*}} %[[COMPLEX]], %[[INIT]] : !cir.complex<!cir.double>, !cir.ptr<!cir.complex<!cir.double>>
646
647 // LLVM: %[[INIT:.*]] = alloca { double, double }, i64 1, align 8
648 // LLVM: store { double, double } { double 1.000000e+00, double 2.000000e+00 }, ptr %[[INIT]], align 8
649
650 // OGCG: %[[INIT:.*]] = alloca { double, double }, align 8
651 // OGCG: %[[INIT_REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[INIT]], i32 0, i32 0
652 // OGCG: %[[INIT_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[INIT]], i32 0, i32 1
653 // OGCG: store double 1.000000e+00, ptr %[[INIT_REAL_PTR]], align 8
654 // OGCG: store double 2.000000e+00, ptr %[[INIT_IMAG_PTR]], align 8
655
656 void foo26(int _Complex* a) {
657 int _Complex b = *a;
658 }
659
660 // CIR: %[[COMPLEX_A_PTR:.*]] = cir.alloca !cir.ptr<!cir.complex<!s32i>>, !cir.ptr<!cir.ptr<!cir.complex<!s32i>>>, ["a", init]
661 // CIR: %[[COMPLEX_B:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["b", init]
662 // CIR: %[[COMPLEX_A:.*]] = cir.load deref {{.*}} %[[COMPLEX_A_PTR]] : !cir.ptr<!cir.ptr<!cir.complex<!s32i>>>, !cir.ptr<!cir.complex<!s32i>>
663 // CIR: %[[TMP:.*]] = cir.load{{.*}} %[[COMPLEX_A]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
664 // CIR: cir.store{{.*}} %[[TMP]], %[[COMPLEX_B]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
665
666 // LLVM: %[[COMPLEX_A_PTR:.*]] = alloca ptr, i64 1, align 8
667 // LLVM: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, i64 1, align 4
668 // LLVM: %[[COMPLEX_A:.*]] = load ptr, ptr %[[COMPLEX_A_PTR]], align 8
669 // LLVM: %[[TMP:.*]] = load { i32, i32 }, ptr %[[COMPLEX_A]], align 4
670 // LLVM: store { i32, i32 } %[[TMP]], ptr %[[COMPLEX_B]], align 4
671
672 // OGCG: %[[COMPLEX_A_PTR:.*]] = alloca ptr, align 8
673 // OGCG: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, align 4
674 // OGCG: %[[COMPLEX_A:.*]] = load ptr, ptr %[[COMPLEX_A_PTR]], align 8
675 // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_A]], i32 0, i32 0
676 // OGCG: %[[A_REAL:.*]] = load i32, ptr %[[A_REAL_PTR]], align 4
677 // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_A]], i32 0, i32 1
678 // OGCG: %[[A_IMAG:.*]] = load i32, ptr %[[A_IMAG_PTR]], align 4
679 // OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 0
680 // OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 1
681 // OGCG: store i32 %[[A_REAL]], ptr %[[B_REAL_PTR]], align 4
682 // OGCG: store i32 %[[A_IMAG]], ptr %[[B_IMAG_PTR]], align 4
683
684 void foo27(bool cond, int _Complex a, int _Complex b) {
685 int _Complex c = cond ? a : b;
686 }
687
688 // CIR: %[[COND:.*]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["cond", init]
689 // CIR: %[[COMPLEX_A:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["a", init]
690 // CIR: %[[COMPLEX_B:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["b", init]
691 // CIR: %[[RESULT:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["c", init]
692 // CIR: %[[TMP_COND:.*]] = cir.load{{.*}} %[[COND]] : !cir.ptr<!cir.bool>, !cir.bool
693 // CIR: %[[RESULT_VAL:.*]] = cir.ternary(%[[TMP_COND]], true {
694 // CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[COMPLEX_A]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
695 // CIR: cir.yield %[[TMP_A]] : !cir.complex<!s32i>
696 // CIR: }, false {
697 // CIR: %[[TMP_B:.*]] = cir.load{{.*}} %[[COMPLEX_B]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
698 // CIR: cir.yield %[[TMP_B]] : !cir.complex<!s32i>
699 // CIR: }) : (!cir.bool) -> !cir.complex<!s32i>
700 // CIR: cir.store{{.*}} %[[RESULT_VAL]], %[[RESULT]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
701
702 // LLVM: %[[COND:.*]] = alloca i8, i64 1, align 1
703 // LLVM: %[[COMPLEX_A:.*]] = alloca { i32, i32 }, i64 1, align 4
704 // LLVM: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, i64 1, align 4
705 // LLVM: %[[RESULT:.*]] = alloca { i32, i32 }, i64 1, align 4
706 // LLVM: %[[TMP_COND:.*]] = load i8, ptr %[[COND]], align 1
707 // LLVM: %[[COND_VAL:.*]] = trunc i8 %[[TMP_COND]] to i1
708 // LLVM: br i1 %[[COND_VAL]], label %[[TRUE_BB:.*]], label %[[FALSE_BB:.*]]
709 // LLVM: [[TRUE_BB]]:
710 // LLVM: %[[TMP_A:.*]] = load { i32, i32 }, ptr %[[COMPLEX_A]], align 4
711 // LLVM: br label %[[END_BB:.*]]
712 // LLVM: [[FALSE_BB]]:
713 // LLVM: %[[TMP_B:.*]] = load { i32, i32 }, ptr %[[COMPLEX_B]], align 4
714 // LLVM: br label %[[END_BB]]
715 // LLVM: [[END_BB]]:
716 // LLVM: %[[RESULT_VAL:.*]] = phi { i32, i32 } [ %[[TMP_B]], %[[FALSE_BB]] ], [ %[[TMP_A]], %[[TRUE_BB]] ]
717 // LLVM: store { i32, i32 } %[[RESULT_VAL]], ptr %[[RESULT]], align 4
718
719 // OGCG: %[[COMPLEX_A:.*]] = alloca { i32, i32 }, align 4
720 // OGCG: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, align 4
721 // OGCG: %[[COND:.*]] = alloca i8, align 1
722 // OGCG: %[[RESULT:.*]] = alloca { i32, i32 }, align 4
723 // OGCG: %[[TMP_COND:.*]] = load i8, ptr %[[COND]], align 1
724 // OGCG: %[[COND_VAL:.*]] = trunc i8 %[[TMP_COND]] to i1
725 // OGCG: br i1 %[[COND_VAL]], label %[[TRUE_BB:.*]], label %[[FALSE_BB:.*]]
726 // OGCG: [[TRUE_BB]]:
727 // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_A]], i32 0, i32 0
728 // OGCG: %[[A_REAL:.*]] = load i32, ptr %[[A_REAL_PTR]], align 4
729 // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_A]], i32 0, i32 1
730 // OGCG: %[[A_IMAG:.*]] = load i32, ptr %[[A_IMAG_PTR]], align 4
731 // OGCG: br label %[[END_BB:.*]]
732 // OGCG: [[FALSE_BB]]:
733 // OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 0
734 // OGCG: %[[B_REAL:.*]] = load i32, ptr %[[B_REAL_PTR]], align 4
735 // OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 1
736 // OGCG: %[[B_IMAG:.*]] = load i32, ptr %[[B_IMAG_PTR]], align 4
737 // OGCG: br label %[[END_BB]]
738 // OGCG: [[END_BB]]:
739 // OGCG: %[[REAL:.*]] = phi i32 [ %[[A_REAL]], %[[TRUE_BB]] ], [ %[[B_REAL]], %[[FALSE_BB]] ]
740 // OGCG: %[[IMAG:.*]] = phi i32 [ %[[A_IMAG]], %[[TRUE_BB]] ], [ %[[B_IMAG]], %[[FALSE_BB]] ]
741 // OGCG: %[[RESULT_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[RESULT]], i32 0, i32 0
742 // OGCG: %[[RESULT_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[RESULT]], i32 0, i32 1
743 // OGCG: store i32 %[[REAL]], ptr %[[RESULT_REAL_PTR]], align 4
744 // OGCG: store i32 %[[IMAG]], ptr %[[RESULT_IMAG_PTR]], align 4
745
746 void foo28() {
747 using IntComplex = int _Complex;
748 int _Complex a = IntComplex();
749 }
750
751 // CIR: %[[INIT:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["a", init]
752 // CIR: %[[COMPLEX:.*]] = cir.const #cir.zero : !cir.complex<!s32i>
753 // CIR: cir.store align(4) %[[COMPLEX]], %[[INIT]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
754
755 // LLVM: %[[INIT:.*]] = alloca { i32, i32 }, i64 1, align 4
756 // LLVM: store { i32, i32 } zeroinitializer, ptr %[[INIT]], align 4
757
758 // OGCG: %[[INIT:.*]] = alloca { i32, i32 }, align 4
759 // OGCG: %[[INIT_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[INIT]], i32 0, i32 0
760 // OGCG: %[[INIT_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[INIT]], i32 0, i32 1
761 // OGCG: store i32 0, ptr %[[INIT_REAL_PTR]], align 4
762 // OGCG: store i32 0, ptr %[[INIT_IMAG_PTR]], align 4
763
764 void foo29() {
765 using IntComplex = int _Complex;
766 int _Complex a = IntComplex{};
767 }
768
769 // CIR: %[[INIT:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["a", init]
770 // CIR: %[[COMPLEX:.*]] = cir.const #cir.zero : !cir.complex<!s32i>
771 // CIR: cir.store{{.*}} %[[COMPLEX]], %[[INIT]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
772
773 // LLVM: %[[INIT:.*]] = alloca { i32, i32 }, i64 1, align 4
774 // LLVM: store { i32, i32 } zeroinitializer, ptr %[[INIT]], align 4
775
776 // OGCG: %[[INIT:.*]] = alloca { i32, i32 }, align 4
777 // OGCG: %[[INIT_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[INIT]], i32 0, i32 0
778 // OGCG: %[[INIT_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[INIT]], i32 0, i32 1
779 // OGCG: store i32 0, ptr %[[INIT_REAL_PTR]], align 4
780 // OGCG: store i32 0, ptr %[[INIT_IMAG_PTR]], align 4
781
782 void foo30() {
783 float _Complex a = { 1.0f };
784 }
785
786 // CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["a", init]
787 // CIR: %[[CONST_1F:.*]] = cir.const #cir.fp<1.000000e+00> : !cir.float
788 // CIR: %[[CONST_0F:.*]] = cir.const #cir.fp<0.000000e+00> : !cir.float
789 // CIR: %[[COMPLEX:.*]] = cir.complex.create %[[CONST_1F]], %[[CONST_0F]] : !cir.float -> !cir.complex<!cir.float>
790 // CIR: cir.store{{.*}} %[[COMPLEX]], %[[A_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
791
792 // LLVM: %[[A_ADDR:.*]] = alloca { float, float }, i64 1, align 4
793 // LLVM: store { float, float } { float 1.000000e+00, float 0.000000e+00 }, ptr %[[A_ADDR]], align 4
794
795 // OGCG: %[[A_ADDR:.*]] = alloca { float, float }, align 4
796 // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 0
797 // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 1
798 // OGCG: store float 1.000000e+00, ptr %[[A_REAL_PTR]], align 4
799 // OGCG: store float 0.000000e+00, ptr %[[A_IMAG_PTR]], align 4
800
801 void foo31() {
802 struct Wrapper {
803 int _Complex c;
804 };
805
806 Wrapper w;
807 int r = __real__ w.c;
808 }
809
810 // CIR: %[[W_ADDR:.*]] = cir.alloca !rec_Wrapper, !cir.ptr<!rec_Wrapper>, ["w"]
811 // CIR: %[[REAL_ADDR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["r", init]
812 // CIR: %[[ELEM_PTR:.*]] = cir.get_member %[[W_ADDR]][0] {name = "c"} : !cir.ptr<!rec_Wrapper> -> !cir.ptr<!cir.complex<!s32i>>
813 // CIR: %[[TMP_ELEM_PTR:.*]] = cir.load{{.*}} %[[ELEM_PTR]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
814 // CIR: %[[REAL:.*]] = cir.complex.real %[[TMP_ELEM_PTR]] : !cir.complex<!s32i> -> !s32i
815 // CIR: cir.store{{.*}} %[[REAL]], %[[REAL_ADDR]] : !s32i, !cir.ptr<!s32i>
816
817 // LLVM: %[[W_ADDR:.*]] = alloca %struct.Wrapper, i64 1, align 4
818 // LLVM: %[[REAL_ADDR:.*]] = alloca i32, i64 1, align 4
819 // LLVM: %[[ELEM_PTR:.*]] = getelementptr %struct.Wrapper, ptr %[[W_ADDR]], i32 0, i32 0
820 // LLVM: %[[TMP_ELEM_PTR:.*]] = load { i32, i32 }, ptr %[[ELEM_PTR]], align 4
821 // LLVM: %[[REAL:.*]] = extractvalue { i32, i32 } %[[TMP_ELEM_PTR]], 0
822 // LLVM: store i32 %[[REAL]], ptr %[[REAL_ADDR]], align 4
823
824 // OGCG: %[[W_ADDR:.*]] = alloca %struct.Wrapper, align 4
825 // OGCG: %[[REAL_ADDR:.*]] = alloca i32, align 4
826 // OGCG: %[[ELEM_PTR:.*]] = getelementptr inbounds nuw %struct.Wrapper, ptr %[[W_ADDR]], i32 0, i32 0
827 // OGCG: %[[REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[ELEM_PTR]], i32 0, i32 0
828 // OGCG: %[[REAL:.*]] = load i32, ptr %[[REAL_PTR]], align 4
829 // OGCG: store i32 %[[REAL]], ptr %[[REAL_ADDR]], align 4
830
831 struct Container {
832 static int _Complex c;
833 };
834
835 void foo32() {
836 Container con;
837 int r = __real__ con.c;
838 }
839
840 // CIR: %[[REAL_ADDR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["r", init]
841 // CIR: %[[ELEM_PTR:.*]] = cir.get_global @_ZN9Container1cE : !cir.ptr<!cir.complex<!s32i>>
842 // CIR: %[[ELEM:.*]] = cir.load{{.*}} %[[ELEM_PTR]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
843 // CIR: %[[REAL:.*]] = cir.complex.real %[[ELEM]] : !cir.complex<!s32i> -> !s32i
844 // CIR: cir.store{{.*}} %[[REAL]], %[[REAL_ADDR]] : !s32i, !cir.ptr<!s32i>
845
846 // LLVM: %[[REAL_ADDR:.*]] = alloca i32, i64 1, align 4
847 // LLVM: %[[ELEM:.*]] = load { i32, i32 }, ptr @_ZN9Container1cE, align 4
848 // LLVM: %[[REAL:.*]] = extractvalue { i32, i32 } %[[ELEM]], 0
849 // LLVM: store i32 %[[REAL]], ptr %[[REAL_ADDR]], align 4
850
851 // OGCG: %[[REAL_ADDR:.*]] = alloca i32, align 4
852 // OGCG: %[[REAL:.*]] = load i32, ptr @_ZN9Container1cE, align 4
853 // OGCG: store i32 %[[REAL]], ptr %[[REAL_ADDR]], align 4
854
855 void foo33(__builtin_va_list a) {
856 float _Complex b = __builtin_va_arg(a, float _Complex);
857 }
858
859 // CIR: %[[A_ADDR:.*]] = cir.alloca !cir.ptr<!rec___va_list_tag>, !cir.ptr<!cir.ptr<!rec___va_list_tag>>, ["a", init]
860 // CIR: %[[B_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["b", init]
861 // CIR: cir.store %[[ARG_0:.*]], %[[A_ADDR]] : !cir.ptr<!rec___va_list_tag>, !cir.ptr<!cir.ptr<!rec___va_list_tag>>
862 // CIR: %[[VA_TAG:.*]] = cir.load{{.*}} %[[A_ADDR]] : !cir.ptr<!cir.ptr<!rec___va_list_tag>>, !cir.ptr<!rec___va_list_tag>
863 // CIR: %[[COMPLEX:.*]] = cir.va_arg %[[VA_TAG]] : (!cir.ptr<!rec___va_list_tag>) -> !cir.complex<!cir.float>
864 // CIR: cir.store{{.*}} %[[COMPLEX]], %[[B_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
865
866 // LLVM: %[[A_ADDR:.*]] = alloca ptr, i64 1, align 8
867 // LLVM: %[[B_ADDR:.*]] = alloca { float, float }, i64 1, align 4
868 // LLVM: store ptr %[[ARG_0:.*]], ptr %[[A_ADDR]], align 8
869 // LLVM: %[[TMP_A:.*]] = load ptr, ptr %[[A_ADDR]], align 8
870 // LLVM: %[[COMPLEX:.*]] = va_arg ptr %[[TMP_A]], { float, float }
871 // LLVM: store { float, float } %[[COMPLEX]], ptr %[[B_ADDR]], align 4
872
873 // TODO(CIR): the difference between the CIR LLVM and OGCG is because the lack of calling convention lowering,
874 // Test will be updated when that is implemented
875
876 // OGCG: %[[A_ADDR:.*]] = alloca ptr, align 8
877 // OGCG: %[[B_ADDR:.*]] = alloca { float, float }, align 4
878 // OGCG: store ptr %[[ARG_0:.*]], ptr %[[A_ADDR]], align 8
879 // OGCG: %[[TMP_A:.*]] = load ptr, ptr %[[A_ADDR]], align 8
880 // OGCG: %[[GP_OFFSET_PTR:.*]] = getelementptr inbounds nuw %struct.__va_list_tag, ptr %[[TMP_A]], i32 0, i32 1
881 // OGCG: %[[GP_OFFSET:.*]] = load i32, ptr %[[GP_OFFSET_PTR]], align 4
882 // OGCG: %[[COND:.*]] = icmp ule i32 %[[GP_OFFSET]], 160
883 // OGCG: br i1 %[[COND]], label %[[VA_ARG_IN_REG:.*]], label %[[VA_ARG_IN_MEM:.*]]
884 //
885 // OGCG: [[VA_ARG_IN_REG]]:
886 // OGCG: %[[REG_SAVE_PTR:.*]] = getelementptr inbounds nuw %struct.__va_list_tag, ptr %[[TMP_A]], i32 0, i32 3
887 // OGCG: %[[REG_SAVE:.*]] = load ptr, ptr %[[REG_SAVE_PTR]], align 8
888 // OGCG: %[[VA_ADDR:..*]] = getelementptr i8, ptr %[[REG_SAVE]], i32 %[[GP_OFFSET]]
889 // OGCG: %[[GP_OFFSET_NEXT:.*]] = add i32 %[[GP_OFFSET]], 16
890 // OGCG: store i32 %[[GP_OFFSET_NEXT]], ptr %[[GP_OFFSET_PTR]], align 4
891 // OGCG: br label %[[VA_ARG_END:.*]]
892 //
893 // OGCG: [[VA_ARG_IN_MEM]]:
894 // OGCG: %[[OVERFLOW_PTR:.*]] = getelementptr inbounds nuw %struct.__va_list_tag, ptr %[[TMP_A]], i32 0, i32 2
895 // OGCG: %[[OVERFLOW:.*]] = load ptr, ptr %[[OVERFLOW_PTR]], align 8
896 // OGCG: %[[OVERFLOW_NEXT:.*]] = getelementptr i8, ptr %[[OVERFLOW]], i32 8
897 // OGCG: store ptr %[[OVERFLOW_NEXT]], ptr %[[OVERFLOW_PTR]], align 8
898 // OGCG: br label %[[VA_ARG_END]]
899 //
900 // OGCG: [[VA_ARG_END]]:
901 // OGCG: %[[RESULT:.*]] = phi ptr [ %[[VA_ADDR]], %[[VA_ARG_IN_REG]] ], [ %[[OVERFLOW]], %[[VA_ARG_IN_MEM]] ]
902 // OGCG: %[[RESULT_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[RESULT]], i32 0, i32 0
903 // OGCG: %[[RESULT_REAL:.*]] = load float, ptr %[[RESULT_REAL_PTR]], align 4
904 // OGCG: %[[RESULT_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[RESULT]], i32 0, i32 1
905 // OGCG: %[[RESULT_IMAG:.*]] = load float, ptr %[[RESULT_IMAG_PTR]], align 4
906 // OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[B_ADDR]], i32 0, i32 0
907 // OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[B_ADDR]], i32 0, i32 1
908 // OGCG: store float %[[RESULT_REAL]], ptr %[[B_REAL_PTR]], align 4
909 // OGCG: store float %[[RESULT_IMAG]], ptr %[[B_IMAG_PTR]], align 4
910
911 void foo34() {
912 _Atomic(float _Complex) a;
913 __c11_atomic_init(&a, {1.0f, 2.0f});
914 }
915
916 // CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["a"]
917 // CIR: %[[CONST_COMPLEX:.*]] = cir.const #cir.const_complex<#cir.fp<1.000000e+00> : !cir.float, #cir.fp<2.000000e+00> : !cir.float> : !cir.complex<!cir.float>
918 // CIR: cir.store{{.*}} %[[CONST_COMPLEX]], %[[A_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
919
920 // LLVM: %[[A_ADDR:.*]] = alloca { float, float }, i64 1, align 8
921 // LLVM: store { float, float } { float 1.000000e+00, float 2.000000e+00 }, ptr %[[A_ADDR]], align 8
922
923 // OGCG: %[[A_ADDR:.*]] = alloca { float, float }, align 8
924 // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 0
925 // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 1
926 // OGCG: store float 1.000000e+00, ptr %[[A_REAL_PTR]], align 8
927 // OGCG: store float 2.000000e+00, ptr %[[A_IMAG_PTR]], align 4
928
929 void foo35() {
930 _Float16 _Complex a;
931 _Float16 real = __real__ a;
932 }
933
934 // CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.f16>, !cir.ptr<!cir.complex<!cir.f16>>, ["a"]
935 // CIR: %[[REAL_ADDR:.*]] = cir.alloca !cir.f16, !cir.ptr<!cir.f16>, ["real", init]
936 // CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[A_ADDR]] : !cir.ptr<!cir.complex<!cir.f16>>, !cir.complex<!cir.f16>
937 // CIR: %[[A_REAL:.*]] = cir.complex.real %[[TMP_A]] : !cir.complex<!cir.f16> -> !cir.f16
938 // CIR: %[[A_IMAG:.*]] = cir.complex.imag %[[TMP_A]] : !cir.complex<!cir.f16> -> !cir.f16
939 // CIR: %[[A_REAL_F32:.*]] = cir.cast floating %[[A_REAL]] : !cir.f16 -> !cir.float
940 // CIR: %[[A_IMAG_F32:.*]] = cir.cast floating %[[A_IMAG]] : !cir.f16 -> !cir.float
941 // CIR: %[[A_COMPLEX_F32:.*]] = cir.complex.create %[[A_REAL_F32]], %[[A_IMAG_F32]] : !cir.float -> !cir.complex<!cir.float>
942 // CIR: %[[A_REAL_F32:.*]] = cir.complex.real %[[A_COMPLEX_F32]] : !cir.complex<!cir.float> -> !cir.float
943 // CIR: %[[A_REAL_F16:.*]] = cir.cast floating %[[A_REAL_F32]] : !cir.float -> !cir.f16
944 // CIR: cir.store{{.*}} %[[A_REAL_F16]], %[[REAL_ADDR]] : !cir.f16, !cir.ptr<!cir.f16>
945
946 // LLVM: %[[A_ADDR:.*]] = alloca { half, half }, i64 1, align 2
947 // LLVM: %[[REAL_ADDR:.*]] = alloca half, i64 1, align 2
948 // LLVM: %[[TMP_A:.*]] = load { half, half }, ptr %[[A_ADDR]], align 2
949 // LLVM: %[[A_REAL:.*]] = extractvalue { half, half } %[[TMP_A]], 0
950 // LLVM: %[[A_IMAG:.*]] = extractvalue { half, half } %[[TMP_A]], 1
951 // LLVM: %[[A_REAL_F32:.*]] = fpext half %[[A_REAL]] to float
952 // LLVM: %[[A_IMAG_F32:.*]] = fpext half %[[A_IMAG]] to float
953 // LLVM: %[[TMP_A_COMPLEX_F32:.*]] = insertvalue { float, float } {{.*}}, float %[[A_REAL_F32]], 0
954 // LLVM: %[[A_COMPLEX_F32:.*]] = insertvalue { float, float } %[[TMP_A_COMPLEX_F32]], float %[[A_IMAG_F32]], 1
955 // LLVM: %[[A_REAL_F16:.*]] = fptrunc float %[[A_REAL_F32]] to half
956 // LLVM: store half %[[A_REAL_F16]], ptr %[[REAL_ADDR]], align 2
957
958 // OGCG: %[[A_ADDR:.*]] = alloca { half, half }, align 2
959 // OGCG: %[[REAL_ADDR:.*]] = alloca half, align 2
960 // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { half, half }, ptr %[[A_ADDR]], i32 0, i32 0
961 // OGCG: %[[A_REAL:.*]] = load half, ptr %[[A_REAL_PTR]], align 2
962 // OGCG: %[[A_REAL_F32:.*]] = fpext half %[[A_REAL]] to float
963 // OGCG: %[[A_REAL_F16:.*]] = fptrunc float %[[A_REAL_F32]] to half
964 // OGCG: store half %[[A_REAL_F16]], ptr %[[REAL_ADDR]], align 2
965
966 void foo36() {
967 _Float16 _Complex a;
968 _Float16 imag = __imag__ a;
969 }
970
971 // CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.f16>, !cir.ptr<!cir.complex<!cir.f16>>, ["a"]
972 // CIR: %[[IMAG_ADDR:.*]] = cir.alloca !cir.f16, !cir.ptr<!cir.f16>, ["imag", init]
973 // CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[A_ADDR]] : !cir.ptr<!cir.complex<!cir.f16>>, !cir.complex<!cir.f16>
974 // CIR: %[[A_REAL:.*]] = cir.complex.real %[[TMP_A]] : !cir.complex<!cir.f16> -> !cir.f16
975 // CIR: %[[A_IMAG:.*]] = cir.complex.imag %[[TMP_A]] : !cir.complex<!cir.f16> -> !cir.f16
976 // CIR: %[[A_REAL_F32:.*]] = cir.cast floating %[[A_REAL]] : !cir.f16 -> !cir.float
977 // CIR: %[[A_IMAG_F32:.*]] = cir.cast floating %[[A_IMAG]] : !cir.f16 -> !cir.float
978 // CIR: %[[A_COMPLEX_F32:.*]] = cir.complex.create %[[A_REAL_F32]], %[[A_IMAG_F32]] : !cir.float -> !cir.complex<!cir.float>
979 // CIR: %[[A_IMAG_F32:.*]] = cir.complex.imag %[[A_COMPLEX_F32]] : !cir.complex<!cir.float> -> !cir.float
980 // CIR: %[[A_IMAG_F16:.*]] = cir.cast floating %[[A_IMAG_F32]] : !cir.float -> !cir.f16
981 // CIR: cir.store{{.*}} %[[A_IMAG_F16]], %[[IMAG_ADDR]] : !cir.f16, !cir.ptr<!cir.f16>
982
983 // LLVM: %[[A_ADDR:.*]] = alloca { half, half }, i64 1, align 2
984 // LLVM: %[[IMAG_ADDR:.*]] = alloca half, i64 1, align 2
985 // LLVM: %[[TMP_A:.*]] = load { half, half }, ptr %[[A_ADDR]], align 2
986 // LLVM: %[[A_REAL:.*]] = extractvalue { half, half } %[[TMP_A]], 0
987 // LLVM: %[[A_IMAG:.*]] = extractvalue { half, half } %[[TMP_A]], 1
988 // LLVM: %[[A_REAL_F32:.*]] = fpext half %[[A_REAL]] to float
989 // LLVM: %[[A_IMAG_F32:.*]] = fpext half %[[A_IMAG]] to float
990 // LLVM: %[[TMP_A_COMPLEX_F32:.*]] = insertvalue { float, float } {{.*}}, float %[[A_REAL_F32]], 0
991 // LLVM: %[[A_COMPLEX_F32:.*]] = insertvalue { float, float } %[[TMP_A_COMPLEX_F32]], float %[[A_IMAG_F32]], 1
992 // LLVM: %[[A_IMAG_F16:.*]] = fptrunc float %[[A_IMAG_F32]] to half
993 // LLVM: store half %[[A_IMAG_F16]], ptr %[[IMAG_ADDR]], align 2
994
995 // OGCG: %[[A_ADDR:.*]] = alloca { half, half }, align 2
996 // OGCG: %[[IMAG_ADDR:.*]] = alloca half, align 2
997 // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { half, half }, ptr %[[A_ADDR]], i32 0, i32 1
998 // OGCG: %[[A_IMAG:.*]] = load half, ptr %[[A_IMAG_PTR]], align 2
999 // OGCG: %[[A_IMAG_F32:.*]] = fpext half %[[A_IMAG]] to float
1000 // OGCG: %[[A_IMAG_F16:.*]] = fptrunc float %[[A_IMAG_F32]] to half
1001 // OGCG: store half %[[A_IMAG_F16]], ptr %[[IMAG_ADDR]], align 2
1002
1003 void foo37() {
1004 _Complex float a;
1005 _Complex float b = __extension__ a;
1006 }
1007
1008 // CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["a"]
1009 // CIR: %[[B_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["b", init]
1010 // CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[A_ADDR]] : !cir.ptr<!cir.complex<!cir.float>>, !cir.complex<!cir.float>
1011 // CIR: cir.store{{.*}} %[[TMP_A]], %[[B_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
1012
1013 // LLVM: %[[A_ADDR:.*]] = alloca { float, float }, i64 1, align 4
1014 // LLVM: %[[B_ADDR:.*]] = alloca { float, float }, i64 1, align 4
1015 // LLVM: %[[TMP_A:.*]] = load { float, float }, ptr %[[A_ADDR]], align 4
1016 // LLVM: store { float, float } %[[TMP_A]], ptr %[[B_ADDR]], align 4
1017
1018 // OGCG: %[[A_ADDR:.*]] = alloca { float, float }, align 4
1019 // OGCG: %[[B_ADDR:.*]] = alloca { float, float }, align 4
1020 // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 0
1021 // OGCG: %[[A_REAL:.*]] = load float, ptr %[[A_REAL_PTR]], align 4
1022 // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 1
1023 // OGCG: %[[A_IMAG:.*]] = load float, ptr %[[A_IMAG_PTR]], align 4
1024 // OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[B_ADDR]], i32 0, i32 0
1025 // OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[B_ADDR]], i32 0, i32 1
1026 // OGCG: store float %[[A_REAL]], ptr %[[B_REAL_PTR]], align 4
1027 // OGCG: store float %[[A_IMAG]], ptr %[[B_IMAG_PTR]], align 4
1028
1029 void real_on_non_glvalue() {
1030 float _Complex a;
1031 float b = __real__(+a);
1032 }
1033
1034 // CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["a"]
1035 // CIR: %[[B_ADDR:.*]] = cir.alloca !cir.float, !cir.ptr<!cir.float>, ["b", init]
1036 // CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[A_ADDR]] : !cir.ptr<!cir.complex<!cir.float>>, !cir.complex<!cir.float>
1037 // CIR: %[[A_REAL:.*]] = cir.complex.real %[[TMP_A]] : !cir.complex<!cir.float> -> !cir.float
1038 // CIR: %[[A_IMAG:.*]] = cir.complex.imag %[[TMP_A]] : !cir.complex<!cir.float> -> !cir.float
1039 // CIR: %[[A_REAL_PLUS:.*]] = cir.unary(plus, %[[A_REAL]]) : !cir.float, !cir.float
1040 // CIR: %[[A_IMAG_PLUS:.*]] = cir.unary(plus, %[[A_IMAG]]) : !cir.float, !cir.float
1041 // CIR: %[[RESULT:.*]] = cir.complex.create %[[A_REAL_PLUS]], %[[A_IMAG_PLUS]] : !cir.float -> !cir.complex<!cir.float>
1042 // CIR: %[[RESULT_REAL:.*]] = cir.complex.real %[[RESULT]] : !cir.complex<!cir.float> -> !cir.float
1043 // CIR: cir.store{{.*}} %[[RESULT_REAL]], %[[B_ADDR]] : !cir.float, !cir.ptr<!cir.float>
1044
1045 // LLVM: %[[A_ADDR:.*]] = alloca { float, float }, i64 1, align 4
1046 // LLVM: %[[B_ADDR:.*]] = alloca float, i64 1, align 4
1047 // LLVM: %[[TMP_A:.*]] = load { float, float }, ptr %[[A_ADDR]], align 4
1048 // LLVM: %[[A_REAL:.*]] = extractvalue { float, float } %[[TMP_A]], 0
1049 // LLVM: %[[A_IMAG:.*]] = extractvalue { float, float } %[[TMP_A]], 1
1050 // LLVM: %[[TMP_RESULT:.*]] = insertvalue { float, float } {{.*}}, float %[[A_REAL]], 0
1051 // LLVM: %[[RESULT:.*]] = insertvalue { float, float } %[[TMP_RESULT]], float %[[A_IMAG]], 1
1052 // LLVM: store float %[[A_REAL]], ptr %[[B_ADDR]], align 4
1053
1054 // OGCG: %[[A_ADDR:.*]] = alloca { float, float }, align 4
1055 // OGCG: %[[B_ADDR:.*]] = alloca float, align 4
1056 // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 0
1057 // OGCG: %[[A_REAL:.*]] = load float, ptr %[[A_REAL_PTR]], align 4
1058 // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 1
1059 // OGCG: %[[A_IMAG:.*]] = load float, ptr %[[A_IMAG_PTR]], align 4
1060 // OGCG: store float %[[A_REAL]], ptr %[[B_ADDR]], align 4
1061
1062 void imag_on_non_glvalue() {
1063 float _Complex a;
1064 float b = __imag__(+a);
1065 }
1066
1067 // CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["a"]
1068 // CIR: %[[B_ADDR:.*]] = cir.alloca !cir.float, !cir.ptr<!cir.float>, ["b", init]
1069 // CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[A_ADDR]] : !cir.ptr<!cir.complex<!cir.float>>, !cir.complex<!cir.float>
1070 // CIR: %[[A_REAL:.*]] = cir.complex.real %[[TMP_A]] : !cir.complex<!cir.float> -> !cir.float
1071 // CIR: %[[A_IMAG:.*]] = cir.complex.imag %[[TMP_A]] : !cir.complex<!cir.float> -> !cir.float
1072 // CIR: %[[A_REAL_PLUS:.*]] = cir.unary(plus, %[[A_REAL]]) : !cir.float, !cir.float
1073 // CIR: %[[A_IMAG_PLUS:.*]] = cir.unary(plus, %[[A_IMAG]]) : !cir.float, !cir.float
1074 // CIR: %[[RESULT:.*]] = cir.complex.create %[[A_REAL_PLUS]], %[[A_IMAG_PLUS]] : !cir.float -> !cir.complex<!cir.float>
1075 // CIR: %[[RESULT_IMAG:.*]] = cir.complex.imag %[[RESULT]] : !cir.complex<!cir.float> -> !cir.float
1076 // CIR: cir.store{{.*}} %[[RESULT_IMAG]], %[[B_ADDR]] : !cir.float, !cir.ptr<!cir.float>
1077
1078 // LLVM: %[[A_ADDR:.*]] = alloca { float, float }, i64 1, align 4
1079 // LLVM: %[[B_ADDR:.*]] = alloca float, i64 1, align 4
1080 // LLVM: %[[TMP_A:.*]] = load { float, float }, ptr %[[A_ADDR]], align 4
1081 // LLVM: %[[A_REAL:.*]] = extractvalue { float, float } %[[TMP_A]], 0
1082 // LLVM: %[[A_IMAG:.*]] = extractvalue { float, float } %[[TMP_A]], 1
1083 // LLVM: %[[TMP_RESULT:.*]] = insertvalue { float, float } {{.*}}, float %[[A_REAL]], 0
1084 // LLVM: %[[RESULT:.*]] = insertvalue { float, float } %[[TMP_RESULT]], float %[[A_IMAG]], 1
1085 // LLVM: store float %[[A_IMAG]], ptr %[[B_ADDR]], align 4
1086
1087 // OGCG: %[[A_ADDR:.*]] = alloca { float, float }, align 4
1088 // OGCG: %[[B_ADDR:.*]] = alloca float, align 4
1089 // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 0
1090 // OGCG: %[[A_REAL:.*]] = load float, ptr %[[A_REAL_PTR]], align 4
1091 // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 1
1092 // OGCG: %[[A_IMAG:.*]] = load float, ptr %[[A_IMAG_PTR]], align 4
1093 // OGCG: store float %[[A_IMAG]], ptr %[[B_ADDR]], align 4
1094
1095 void atomic_complex_type() {
1096 _Atomic(float _Complex) a;
1097 float _Complex b = __c11_atomic_load(&a, __ATOMIC_RELAXED);
1098 }
1099
1100 // CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["a"]
1101 // CIR: %[[B_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["b", init]
1102 // CIR: %[[ATOMIC_TMP_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["atomic-temp"]
1103 // CIR: %[[A_PTR:.*]] = cir.cast bitcast %[[A_ADDR]] : !cir.ptr<!cir.complex<!cir.float>> -> !cir.ptr<!u64i>
1104 // CIR: %[[ATOMIC_TMP_PTR:.*]] = cir.cast bitcast %[[ATOMIC_TMP_ADDR]] : !cir.ptr<!cir.complex<!cir.float>> -> !cir.ptr<!u64i>
1105 // CIR: %[[TMP_A_ATOMIC:.*]] = cir.load{{.*}} atomic(relaxed) %[[A_PTR]] : !cir.ptr<!u64i>, !u64i
1106 // CIR: cir.store{{.*}} %[[TMP_A_ATOMIC]], %[[ATOMIC_TMP_PTR]] : !u64i, !cir.ptr<!u64i>
1107 // CIR: %[[TMP_ATOMIC_PTR:.*]] = cir.cast bitcast %[[ATOMIC_TMP_PTR]] : !cir.ptr<!u64i> -> !cir.ptr<!cir.complex<!cir.float>>
1108 // CIR: %[[TMP_ATOMIC:.*]] = cir.load{{.*}} %[[TMP_ATOMIC_PTR]] : !cir.ptr<!cir.complex<!cir.float>>, !cir.complex<!cir.float>
1109 // CIR: cir.store{{.*}} %[[TMP_ATOMIC]], %[[B_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
1110
1111 // LLVM: %[[A_ADDR:.*]] = alloca { float, float }, i64 1, align 8
1112 // LLVM: %[[B_ADDR:.*]] = alloca { float, float }, i64 1, align 4
1113 // LLVM: %[[ATOMIC_TMP_ADDR:.*]] = alloca { float, float }, i64 1, align 8
1114 // LLVM: %[[TMP_A_ATOMIC:.*]] = load atomic i64, ptr %[[A_ADDR]] monotonic, align 8
1115 // LLVM: store i64 %[[TMP_A_ATOMIC]], ptr %[[ATOMIC_TMP_ADDR]], align 8
1116 // LLVM: %[[TMP_ATOMIC:.*]] = load { float, float }, ptr %[[ATOMIC_TMP_ADDR]], align 8
1117 // LLVM: store { float, float } %[[TMP_ATOMIC]], ptr %[[B_ADDR]], align 4
1118
1119 // OGCG: %[[A_ADDR:.*]] = alloca { float, float }, align 8
1120 // OGCG: %[[B_ADDR:.*]] = alloca { float, float }, align 4
1121 // OGCG: %[[ATOMIC_TMP_ADDR:.*]] = alloca { float, float }, align 8
1122 // OGCG: %[[TMP_A_ATOMIC:.*]] = load atomic i64, ptr %[[A_ADDR]] monotonic, align 8
1123 // OGCG: store i64 %[[TMP_A_ATOMIC]], ptr %[[ATOMIC_TMP_ADDR]], align 8
1124 // OGCG: %[[ATOMIC_TMP_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[ATOMIC_TMP_ADDR]], i32 0, i32 0
1125 // OGCG: %[[ATOMIC_TMP_REAL:.*]] = load float, ptr %[[ATOMIC_TMP_REAL_PTR]], align 8
1126 // OGCG: %[[ATOMIC_TMP_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[ATOMIC_TMP_ADDR]], i32 0, i32 1
1127 // OGCG: %[[ATOMIC_TMP_IMAG:.*]] = load float, ptr %[[ATOMIC_TMP_IMAG_PTR]], align 4
1128 // OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[B_ADDR]], i32 0, i32 0
1129 // OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[B_ADDR]], i32 0, i32 1
1130 // OGCG: store float %[[ATOMIC_TMP_REAL]], ptr %[[B_REAL_PTR]], align 4
1131 // OGCG: store float %[[ATOMIC_TMP_IMAG]], ptr %[[B_IMAG_PTR]], align 4
1132
1133 void real_on_scalar_glvalue() {
1134 float a;
1135 float b = __real__ a;
1136 }
1137
1138 // CIR: %[[A_ADDR:.*]] = cir.alloca !cir.float, !cir.ptr<!cir.float>, ["a"]
1139 // CIR: %[[B_ADDR:.*]] = cir.alloca !cir.float, !cir.ptr<!cir.float>, ["b", init]
1140 // CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[A_ADDR]] : !cir.ptr<!cir.float>, !cir.float
1141 // CIR: %[[A_REAL:.*]] = cir.complex.real %[[TMP_A]] : !cir.float -> !cir.float
1142 // CIR: cir.store{{.*}} %[[A_REAL]], %[[B_ADDR]] : !cir.float, !cir.ptr<!cir.float>
1143
1144 // LLVM: %[[A_ADDR:.*]] = alloca float, i64 1, align 4
1145 // LLVM: %[[B_ADDR:.*]] = alloca float, i64 1, align 4
1146 // LLVM: %[[TMP_A:.*]] = load float, ptr %[[A_ADDR]], align 4
1147 // LLVM: store float %[[TMP_A]], ptr %[[B_ADDR]], align 4
1148
1149 // OGCG: %[[A_ADDR:.*]] = alloca float, align 4
1150 // OGCG: %[[B_ADDR:.*]] = alloca float, align 4
1151 // OGCG: %[[TMP_A:.*]] = load float, ptr %[[A_ADDR]], align 4
1152 // OGCG: store float %[[TMP_A]], ptr %[[B_ADDR]], align 4
1153
1154 void imag_on_scalar_glvalue() {
1155 float a;
1156 float b = __imag__ a;
1157 }
1158
1159 // CIR: %[[A_ADDR:.*]] = cir.alloca !cir.float, !cir.ptr<!cir.float>, ["a"]
1160 // CIR: %[[B_ADDR:.*]] = cir.alloca !cir.float, !cir.ptr<!cir.float>, ["b", init]
1161 // CIR: %[[TMP_A:.*]] = cir.load %[[A_ADDR]] : !cir.ptr<!cir.float>, !cir.float
1162 // CIR: %[[A_IMAG:.*]] = cir.complex.imag %[[TMP_A]] : !cir.float -> !cir.float
1163 // CIR: cir.store{{.*}} %[[A_IMAG]], %[[B_ADDR]] : !cir.float, !cir.ptr<!cir.float>
1164
1165 // LLVM: %[[A_ADDR:.*]] = alloca float, i64 1, align 4
1166 // LLVM: %[[B_ADDR:.*]] = alloca float, i64 1, align 4
1167 // LLVM: store float 0.000000e+00, ptr %[[B_ADDR]], align 4
1168
1169 // OGCG: %[[A_ADDR:.*]] = alloca float, align 4
1170 // OGCG: %[[B_ADDR:.*]] = alloca float, align 4
1171 // OGCG: store float 0.000000e+00, ptr %[[B_ADDR]], align 4
1172
1173 void real_on_scalar_with_type_promotion() {
1174 _Float16 a;
1175 _Float16 b = __real__ a;
1176 }
1177
1178 // CIR: %[[A_ADDR:.*]] = cir.alloca !cir.f16, !cir.ptr<!cir.f16>, ["a"]
1179 // CIR: %[[B_ADDR:.*]] = cir.alloca !cir.f16, !cir.ptr<!cir.f16>, ["b", init]
1180 // CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[A_ADDR]] : !cir.ptr<!cir.f16>, !cir.f16
1181 // CIR: %[[TMP_A_F32:.*]] = cir.cast floating %[[TMP_A]] : !cir.f16 -> !cir.float
1182 // CIR: %[[A_REAL:.*]] = cir.complex.real %[[TMP_A_F32]] : !cir.float -> !cir.float
1183 // CIR: %[[TMP_A_F16:.*]] = cir.cast floating %[[A_REAL]] : !cir.float -> !cir.f16
1184 // CIR: cir.store{{.*}} %[[TMP_A_F16]], %[[B_ADDR]] : !cir.f16, !cir.ptr<!cir.f16>
1185
1186 // LLVM: %[[A_ADDR:.*]] = alloca half, i64 1, align 2
1187 // LLVM: %[[B_ADDR:.*]] = alloca half, i64 1, align 2
1188 // LLVM: %[[TMP_A:.*]] = load half, ptr %[[A_ADDR]], align 2
1189 // LLVM: %[[TMP_A_F32:.*]] = fpext half %[[TMP_A]] to float
1190 // LLVM: %[[TMP_A_F16:.*]] = fptrunc float %[[TMP_A_F32]] to half
1191 // LLVM: store half %[[TMP_A_F16]], ptr %[[B_ADDR]], align 2
1192
1193 // OGCG: %[[A_ADDR:.*]] = alloca half, align 2
1194 // OGCG: %[[B_ADDR:.*]] = alloca half, align 2
1195 // OGCG: %[[TMP_A:.*]] = load half, ptr %[[A_ADDR]], align 2
1196 // OGCG: %[[TMP_A_F32:.*]] = fpext half %[[TMP_A]] to float
1197 // OGCG: %[[TMP_A_F16:.*]] = fptrunc float %[[TMP_A_F32]] to half
1198 // OGCG: store half %[[TMP_A_F16]], ptr %[[B_ADDR]], align 2
1199
1200 void imag_on_scalar_with_type_promotion() {
1201 _Float16 a;
1202 _Float16 b = __imag__ a;
1203 }
1204
1205 // CIR: %[[A_ADDR:.*]] = cir.alloca !cir.f16, !cir.ptr<!cir.f16>, ["a"]
1206 // CIR: %[[B_ADDR:.*]] = cir.alloca !cir.f16, !cir.ptr<!cir.f16>, ["b", init]
1207 // CIR: %[[TMP_A:.*]] = cir.load %[[A_ADDR]] : !cir.ptr<!cir.f16>, !cir.f16
1208 // CIR: %[[A_IMAG:.*]] = cir.complex.imag %[[TMP_A]] : !cir.f16 -> !cir.f16
1209 // CIR: %[[A_IMAG_F16:.*]] = cir.cast floating %[[A_IMAG]] : !cir.f16 -> !cir.f16
1210 // CIR: cir.store{{.*}} %[[A_IMAG_F16]], %[[B_ADDR]] : !cir.f16, !cir.ptr<!cir.f16>
1211
1212 // LLVM: %[[A_ADDR:.*]] = alloca half, i64 1, align 2
1213 // LLVM: %[[B_ADDR:.*]] = alloca half, i64 1, align 2
1214 // LLVM: store half 0xH0000, ptr %[[B_ADDR]], align 2
1215
1216 // OGCG: %[[A_ADDR:.*]] = alloca half, align 2
1217 // OGCG: %[[B_ADDR:.*]] = alloca half, align 2
1218 // OGCG: store half 0xH0000, ptr %[[B_ADDR]], align 2
1219
1220 void imag_on_const_scalar() {
1221 float a;
1222 float b = __imag__ 1.0f;
1223 }
1224
1225 // CIR: %[[A_ADDR:.*]] = cir.alloca !cir.float, !cir.ptr<!cir.float>, ["a"]
1226 // CIR: %[[B_ADDR:.*]] = cir.alloca !cir.float, !cir.ptr<!cir.float>, ["b", init]
1227 // CIR: %[[CONST_ONE:.*]] = cir.const #cir.fp<1.000000e+00> : !cir.float
1228 // CIR: %[[CONST_IMAG:.*]] = cir.complex.imag %[[CONST_ONE]] : !cir.float -> !cir.float
1229 // CIR: cir.store{{.*}} %[[CONST_IMAG]], %[[B_ADDR]] : !cir.float, !cir.ptr<!cir.float>
1230
1231 // LLVM: %[[A_ADDR:.*]] = alloca float, i64 1, align 4
1232 // LLVM: %[[B_ADDR:.*]] = alloca float, i64 1, align 4
1233 // LLVM: store float 0.000000e+00, ptr %[[B_ADDR]], align 4
1234
1235 // OGCG: %[[A_ADDR:.*]] = alloca float, align 4
1236 // OGCG: %[[B_ADDR:.*]] = alloca float, align 4
1237 // OGCG: store float 0.000000e+00, ptr %[[B_ADDR]], align 4
1238
1239 void real_on_scalar_from_real_with_type_promotion() {
1240 _Float16 _Complex a;
1241 _Float16 b = __real__(__real__ a);
1242 }
1243
1244 // CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.f16>, !cir.ptr<!cir.complex<!cir.f16>>, ["a"]
1245 // CIR: %[[B_ADDR:.*]] = cir.alloca !cir.f16, !cir.ptr<!cir.f16>, ["b", init]
1246 // CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[A_ADDR]] : !cir.ptr<!cir.complex<!cir.f16>>, !cir.complex<!cir.f16>
1247 // CIR: %[[A_REAL:.*]] = cir.complex.real %[[TMP_A]] : !cir.complex<!cir.f16> -> !cir.f16
1248 // CIR: %[[A_IMAG:.*]] = cir.complex.imag %[[TMP_A]] : !cir.complex<!cir.f16> -> !cir.f16
1249 // CIR: %[[A_REAL_F32:.*]] = cir.cast floating %[[A_REAL]] : !cir.f16 -> !cir.float
1250 // CIR: %[[A_IMAG_F32:.*]] = cir.cast floating %[[A_IMAG]] : !cir.f16 -> !cir.float
1251 // CIR: %[[A_COMPLEX_F32:.*]] = cir.complex.create %[[A_REAL_F32]], %[[A_IMAG_F32]] : !cir.float -> !cir.complex<!cir.float>
1252 // CIR: %[[A_REAL_F32:.*]] = cir.complex.real %[[A_COMPLEX_F32]] : !cir.complex<!cir.float> -> !cir.float
1253 // CIR: %[[A_REAL:.*]] = cir.complex.real %[[A_REAL_F32]] : !cir.float -> !cir.float
1254 // CIR: %[[A_REAL_F16:.*]] = cir.cast floating %[[A_REAL]] : !cir.float -> !cir.f16
1255 // CIR: cir.store{{.*}} %[[A_REAL_F16]], %[[B_ADDR]] : !cir.f16, !cir.ptr<!cir.f16>
1256
1257 // LLVM: %[[A_ADDR:.*]] = alloca { half, half }, i64 1, align 2
1258 // LLVM: %[[B_ADDR]] = alloca half, i64 1, align 2
1259 // LLVM: %[[TMP_A:.*]] = load { half, half }, ptr %[[A_ADDR]], align 2
1260 // LLVM: %[[A_REAL:.*]] = extractvalue { half, half } %[[TMP_A]], 0
1261 // LLVM: %[[A_IMAG:.*]] = extractvalue { half, half } %[[TMP_A]], 1
1262 // LLVM: %[[A_REAL_F32:.*]] = fpext half %[[A_REAL]] to float
1263 // LLVM: %[[A_IMAG_F32:.*]] = fpext half %[[A_IMAG]] to float
1264 // LLVM: %[[TMP_A_COMPLEX_F32:.*]] = insertvalue { float, float } {{.*}}, float %[[A_REAL_F32]], 0
1265 // LLVM: %[[A_COMPLEX_F32:.*]] = insertvalue { float, float } %[[TMP_A_COMPLEX_F32]], float %[[A_IMAG_F32]], 1
1266 // LLVM: %[[A_REAL_F16:.*]] = fptrunc float %[[A_REAL_F32]] to half
1267 // LLVM: store half %[[A_REAL_F16]], ptr %[[B_ADDR]], align 2
1268
1269 // OGCG: %[[A_ADDR:.*]] = alloca { half, half }, align 2
1270 // OGCG: %[[B_ADDR:.*]] = alloca half, align 2
1271 // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { half, half }, ptr %[[A_ADDR]], i32 0, i32 0
1272 // OGCG: %[[A_REAL:.*]] = load half, ptr %[[A_REAL_PTR]], align 2
1273 // OGCG: %[[A_REAL_F32:.*]] = fpext half %[[A_REAL]] to float
1274 // OGCG: %[[A_REAL_F16:.*]] = fptrunc float %[[A_REAL_F32]] to half
1275 // OGCG: store half %[[A_REAL_F16]], ptr %[[B_ADDR]], align 2
1276
1277 void real_on_scalar_from_imag_with_type_promotion() {
1278 _Float16 _Complex a;
1279 _Float16 b = __real__(__imag__ a);
1280 }
1281
1282 // CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.f16>, !cir.ptr<!cir.complex<!cir.f16>>, ["a"]
1283 // CIR: %[[B_ADDR:.*]] = cir.alloca !cir.f16, !cir.ptr<!cir.f16>, ["b", init]
1284 // CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[A_ADDR]] : !cir.ptr<!cir.complex<!cir.f16>>, !cir.complex<!cir.f16>
1285 // CIR: %[[A_REAL:.*]] = cir.complex.real %[[TMP_A]] : !cir.complex<!cir.f16> -> !cir.f16
1286 // CIR: %[[A_IMAG:.*]] = cir.complex.imag %[[TMP_A]] : !cir.complex<!cir.f16> -> !cir.f16
1287 // CIR: %[[A_REAL_F32:.*]] = cir.cast floating %[[A_REAL]] : !cir.f16 -> !cir.float
1288 // CIR: %[[A_IMAG_F32:.*]] = cir.cast floating %[[A_IMAG]] : !cir.f16 -> !cir.float
1289 // CIR: %[[A_COMPLEX_F32:.*]] = cir.complex.create %[[A_REAL_F32]], %[[A_IMAG_F32]] : !cir.float -> !cir.complex<!cir.float>
1290 // CIR: %[[A_IMAG_F32:.*]] = cir.complex.imag %[[A_COMPLEX_F32]] : !cir.complex<!cir.float> -> !cir.float
1291 // CIR: %[[A_REAL_F32:.*]] = cir.complex.real %[[A_IMAG_F32]] : !cir.float -> !cir.float
1292 // CIR: %[[A_REAL_F16:.*]] = cir.cast floating %[[A_REAL_F32]] : !cir.float -> !cir.f16
1293 // CIR: cir.store{{.*}} %[[A_REAL_F16]], %[[B_ADDR]] : !cir.f16, !cir.ptr<!cir.f16>
1294
1295 // LLVM: %[[A_ADDR:.*]] = alloca { half, half }, i64 1, align 2
1296 // LLVM: %[[B_ADDR]] = alloca half, i64 1, align 2
1297 // LLVM: %[[TMP_A:.*]] = load { half, half }, ptr %[[A_ADDR]], align 2
1298 // LLVM: %[[A_REAL:.*]] = extractvalue { half, half } %[[TMP_A]], 0
1299 // LLVM: %[[A_IMAG:.*]] = extractvalue { half, half } %[[TMP_A]], 1
1300 // LLVM: %[[A_REAL_F32:.*]] = fpext half %[[A_REAL]] to float
1301 // LLVM: %[[A_IMAG_F32:.*]] = fpext half %[[A_IMAG]] to float
1302 // LLVM: %[[TMP_A_COMPLEX_F32:.*]] = insertvalue { float, float } {{.*}}, float %[[A_REAL_F32]], 0
1303 // LLVM: %[[A_COMPLEX_F32:.*]] = insertvalue { float, float } %[[TMP_A_COMPLEX_F32]], float %[[A_IMAG_F32]], 1
1304 // LLVM: %[[A_IMAG_F16:.*]] = fptrunc float %[[A_IMAG_F32]] to half
1305 // LLVM: store half %[[A_IMAG_F16]], ptr %[[B_ADDR]], align 2
1306
1307 // OGCG: %[[A_ADDR:.*]] = alloca { half, half }, align 2
1308 // OGCG: %[[B_ADDR:.*]] = alloca half, align 2
1309 // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { half, half }, ptr %[[A_ADDR]], i32 0, i32 1
1310 // OGCG: %[[A_IMAG:.*]] = load half, ptr %[[A_IMAG_PTR]], align 2
1311 // OGCG: %[[A_IMAG_F32:.*]] = fpext half %[[A_IMAG]] to float
1312 // OGCG: %[[A_IMAG_F16:.*]] = fptrunc float %[[A_IMAG_F32]] to half
1313 // OGCG: store half %[[A_IMAG_F16]], ptr %[[B_ADDR]], align 2
1314
1315 void complex_type_parameter(float _Complex a) {}
1316
1317 // CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["a", init]
1318 // CIR: cir.store %{{.*}}, %[[A_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
1319
1320 // TODO(CIR): the difference between the CIR LLVM and OGCG is because the lack of calling convention lowering,
1321 // Test will be updated when that is implemented
1322
1323 // LLVM: %[[A_ADDR:.*]] = alloca { float, float }, i64 1, align 4
1324 // LLVM: store { float, float } %{{.*}}, ptr %[[A_ADDR]], align 4
1325
1326 // OGCG: %[[A_ADDR:.*]] = alloca { float, float }, align 4
1327 // OGCG: store <2 x float> %a.coerce, ptr %[[A_ADDR]], align 4
1328
1329 void complex_type_argument() {
1330 float _Complex a;
1331 complex_type_parameter(a);
1332 }
1333
1334 // CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["a"]
1335 // CIR: %[[ARG_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["coerce"]
1336 // CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[A_ADDR]] : !cir.ptr<!cir.complex<!cir.float>>, !cir.complex<!cir.float>
1337 // CIR: cir.store{{.*}} %[[TMP_A]], %[[ARG_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
1338 // CIR: %[[TMP_ARG:.*]] = cir.load{{.*}} %[[ARG_ADDR]] : !cir.ptr<!cir.complex<!cir.float>>, !cir.complex<!cir.float>
1339 // CIR: cir.call @_Z22complex_type_parameterCf(%[[TMP_ARG]]) : (!cir.complex<!cir.float>) -> ()
1340
1341 // LLVM: %[[A_ADDR:.*]] = alloca { float, float }, i64 1, align 4
1342 // LLVM: %[[ARG_ADDR:.*]] = alloca { float, float }, i64 1, align 4
1343 // LLVM: %[[TMP_A:.*]] = load { float, float }, ptr %[[A_ADDR]], align 4
1344 // LLVM: store { float, float } %[[TMP_A]], ptr %[[ARG_ADDR]], align 4
1345 // LLVM: %[[TMP_ARG:.*]] = load { float, float }, ptr %[[ARG_ADDR]], align 4
1346 // LLVM: call void @_Z22complex_type_parameterCf({ float, float } %[[TMP_ARG]])
1347
1348 // OGCG: %[[A_ADDR:.*]] = alloca { float, float }, align 4
1349 // OGCG: %[[ARG_ADDR:.*]] = alloca { float, float }, align 4
1350 // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 0
1351 // OGCG: %[[A_REAL:.*]] = load float, ptr %[[A_REAL_PTR]], align 4
1352 // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 1
1353 // OGCG: %[[A_IMAG:.*]] = load float, ptr %[[A_IMAG_PTR]], align 4
1354 // OGCG: %[[ARG_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[ARG_ADDR]], i32 0, i32 0
1355 // OGCG: %[[ARG_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[ARG_ADDR]], i32 0, i32 1
1356 // OGCG: store float %[[A_REAL]], ptr %[[ARG_REAL_PTR]], align 4
1357 // OGCG: store float %[[A_IMAG]], ptr %[[ARG_IMAG_PTR]], align 4
1358 // OGCG: %[[TMP_ARG:.*]] = load <2 x float>, ptr %[[ARG_ADDR]], align 4
1359 // OGCG: call void @_Z22complex_type_parameterCf(<2 x float> noundef %[[TMP_ARG]])
1360
1361 float _Complex complex_type_return_type() {
1362 return { 1.0f, 2.0f };
1363 }
1364
1365 // CIR: %[[RET_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["__retval"]
1366 // CIR: %[[RET_VAL:.*]] = cir.const #cir.const_complex<#cir.fp<1.000000e+00> : !cir.float, #cir.fp<2.000000e+00> : !cir.float> : !cir.complex<!cir.float>
1367 // CIR: cir.store{{.*}} %[[RET_VAL]], %[[RET_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
1368 // CIR: %[[TMP_RET:.*]] = cir.load %[[RET_ADDR]] : !cir.ptr<!cir.complex<!cir.float>>, !cir.complex<!cir.float>
1369 // CIR: cir.return %[[TMP_RET]] : !cir.complex<!cir.float>
1370
1371 // TODO(CIR): the difference between the CIR LLVM and OGCG is because the lack of calling convention lowering,
1372 // LLVM: %[[RET_ADDR:.*]] = alloca { float, float }, i64 1, align 4
1373 // LLVM: store { float, float } { float 1.000000e+00, float 2.000000e+00 }, ptr %[[RET_ADDR]], align 4
1374 // LLVM: %[[TMP_RET:.*]] = load { float, float }, ptr %[[RET_ADDR]], align 4
1375 // LLVM: ret { float, float } %[[TMP_RET]]
1376
1377 // OGCG: %[[RET_ADDR:.*]] = alloca { float, float }, align 4
1378 // OGCG: %[[RET_VAL_REAL:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[RET_ADDR]], i32 0, i32 0
1379 // OGCG: %[[RET_VAL_IMAG:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[RET_ADDR]], i32 0, i32 1
1380 // OGCG: store float 1.000000e+00, ptr %[[RET_VAL_REAL]], align 4
1381 // OGCG: store float 2.000000e+00, ptr %[[RET_VAL_IMAG]], align 4
1382 // OGCG: %[[TMP_RET:.*]] = load <2 x float>, ptr %[[RET_ADDR]], align 4
1383 // OGCG: ret <2 x float> %[[TMP_RET]]
1384
1385 void real_on_scalar_bool() {
1386 bool a;
1387 bool b = __real__ a;
1388 }
1389
1390 // CIR: %[[A_ADDR:.*]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["a"]
1391 // CIR: %[[B_ADDR:.*]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["b", init]
1392 // CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[A_ADDR]] : !cir.ptr<!cir.bool>, !cir.bool
1393 // CIR: %[[A_REAL:.*]] = cir.complex.real %[[TMP_A]] : !cir.bool -> !cir.bool
1394 // CIR: cir.store{{.*}} %[[A_REAL]], %[[B_ADDR]] : !cir.bool, !cir.ptr<!cir.bool>
1395
1396 // LLVM: %[[A_ADDR:.*]] = alloca i8, i64 1, align 1
1397 // LLVM: %[[B_ADDR:.*]] = alloca i8, i64 1, align 1
1398 // LLVM: %[[TMP_A:.*]] = load i8, ptr %[[A_ADDR]], align 1
1399 // LLVM: %[[TMP_A_I1:.*]] = trunc i8 %[[TMP_A]] to i1
1400 // LLVM: %[[TMP_A_I8:.*]] = zext i1 %[[TMP_A_I1]] to i8
1401 // LLVM: store i8 %[[TMP_A_I8]], ptr %[[B_ADDR]], align 1
1402
1403 // OGCG: %[[A_ADDR:.*]] = alloca i8, align 1
1404 // OGCG: %[[B_ADDR:.*]] = alloca i8, align 1
1405 // OGCG: %[[TMP_A:.*]] = load i8, ptr %[[A_ADDR]], align 1
1406 // OGCG: %[[TMP_A_I1:.*]] = trunc i8 %[[TMP_A]] to i1
1407 // OGCG: %[[TMP_A_I8:.*]] = zext i1 %[[TMP_A_I1]] to i8
1408 // OGCG: store i8 %[[TMP_A_I8]], ptr %[[B_ADDR]], align 1
1409
1410 void imag_on_scalar_bool() {
1411 bool a;
1412 bool b = __imag__ a;
1413 }
1414
1415 // CIR: %[[A_ADDR:.*]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["a"]
1416 // CIR: %[[B_ADDR:.*]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["b", init]
1417 // CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[A_ADDR]] : !cir.ptr<!cir.bool>, !cir.bool
1418 // CIR: %[[A_IMAG:.*]] = cir.complex.imag %[[TMP_A]] : !cir.bool -> !cir.bool
1419 // CIR: cir.store{{.*}} %[[A_IMAG]], %[[B_ADDR]] : !cir.bool, !cir.ptr<!cir.bool>
1420
1421 // LLVM: %[[A_ADDR:.*]] = alloca i8, i64 1, align 1
1422 // LLVM: %[[B_ADDR:.*]] = alloca i8, i64 1, align 1
1423 // LLVM: %[[TMP_A:.*]] = load i8, ptr %[[A_ADDR]], align 1
1424 // LLVM: %[[TMP_A_I1:.*]] = trunc i8 %[[TMP_A]] to i1
1425 // LLVM: store i8 0, ptr %[[B_ADDR]], align 1
1426
1427 // OGCG: %[[A_ADDR:.*]] = alloca i8, align 1
1428 // OGCG: %[[B_ADDR:.*]] = alloca i8, align 1
1429 // OGCG: store i8 0, ptr %[[B_ADDR]], align 1
1430
1431 void function_with_complex_default_arg(
1432 float _Complex a = __builtin_complex(1.0f, 2.2f)) {}
1433
1434 // CIR: %[[ARG_0_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["a", init]
1435 // CIR: cir.store %{{.*}}, %[[ARG_0_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
1436
1437 // TODO(CIR): the difference between the CIR LLVM and OGCG is because the lack of calling convention lowering,
1438
1439 // LLVM: %[[ARG_0_ADDR:.*]] = alloca { float, float }, i64 1, align 4
1440 // LLVM: store { float, float } %{{.*}}, ptr %[[ARG_0_ADDR]], align 4
1441
1442 // OGCG: %[[ARG_0_ADDR:.*]] = alloca { float, float }, align 4
1443 // OGCG: store <2 x float> %{{.*}}, ptr %[[ARG_0_ADDR]], align 4
1444
1445 void calling_function_with_default_arg() {
1446 function_with_complex_default_arg();
1447 }
1448
1449 // CIR: %[[DEFAULT_ARG_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["coerce"]
1450 // CIR: %[[DEFAULT_ARG_VAL:.*]] = cir.const #cir.const_complex<#cir.fp<1.000000e+00> : !cir.float, #cir.fp<2.200000e+00> : !cir.float> : !cir.complex<!cir.float>
1451 // CIR: cir.store{{.*}} %[[DEFAULT_ARG_VAL]], %[[DEFAULT_ARG_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
1452 // CIR: %[[TMP_DEFAULT_ARG:.*]] = cir.load{{.*}} %[[DEFAULT_ARG_ADDR]] : !cir.ptr<!cir.complex<!cir.float>>, !cir.complex<!cir.float>
1453 // CIR: cir.call @_Z33function_with_complex_default_argCf(%[[TMP_DEFAULT_ARG]]) : (!cir.complex<!cir.float>) -> ()
1454
1455 // TODO(CIR): the difference between the CIR LLVM and OGCG is because the lack of calling convention lowering,
1456
1457 // LLVM: %[[DEFAULT_ARG_ADDR:.*]] = alloca { float, float }, i64 1, align 4
1458 // LLVM: store { float, float } { float 1.000000e+00, float 0x40019999A0000000 }, ptr %[[DEFAULT_ARG_ADDR]], align 4
1459 // LLVM: %[[TMP_DEFAULT_ARG:.*]] = load { float, float }, ptr %[[DEFAULT_ARG_ADDR]], align 4
1460 // LLVM: call void @_Z33function_with_complex_default_argCf({ float, float } %[[TMP_DEFAULT_ARG]])
1461
1462 // OGCG: %[[DEFAULT_ARG_ADDR:.*]] = alloca { float, float }, align 4
1463 // OGCG: %[[DEFAULT_ARG_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[DEFAULT_ARG_ADDR]], i32 0, i32 0
1464 // OGCG: %[[DEFAULT_ARG_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[DEFAULT_ARG_ADDR]], i32 0, i32 1
1465 // OGCG: store float 1.000000e+00, ptr %[[DEFAULT_ARG_REAL_PTR]], align 4
1466 // OGCG: store float 0x40019999A0000000, ptr %[[DEFAULT_ARG_IMAG_PTR]], align 4
1467 // OGCG: %[[TMP_DEFAULT_ARG:.*]] = load <2 x float>, ptr %[[DEFAULT_ARG_ADDR]], align 4
1468 // OGCG: call void @_Z33function_with_complex_default_argCf(<2 x float> {{.*}} %[[TMP_DEFAULT_ARG]])
1469
1470 void calling_function_that_return_complex() {
1471 float _Complex a = complex_type_return_type();
1472 }
1473
1474 // CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["a", init]
1475 // CIR: %[[RESULT:.*]] = cir.call @_Z24complex_type_return_typev() : () -> !cir.complex<!cir.float>
1476 // CIR: cir.store{{.*}} %[[RESULT]], %[[A_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
1477
1478 // TODO(CIR): the difference between the CIR LLVM and OGCG is because the lack of calling convention lowering,
1479
1480 // LLVM: %[[A_ADDR:.*]] = alloca { float, float }, i64 1, align 4
1481 // LLVM: %[[RESULT:.*]] = call { float, float } @_Z24complex_type_return_typev()
1482 // LLVM: store { float, float } %[[RESULT]], ptr %[[A_ADDR]], align 4
1483
1484 // OGCG: %[[A_ADDR:.*]] = alloca { float, float }, align 4
1485 // OGCG: %[[RESULT_ADDR:.*]] = alloca { float, float }, align 4
1486 // OGCG: %[[RESULT:.*]] = call noundef <2 x float> @_Z24complex_type_return_typev()
1487 // OGCG: store <2 x float> %[[RESULT]], ptr %[[RESULT_ADDR]], align 4
1488 // OGCG: %[[RESULT_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[RESULT_ADDR]], i32 0, i32 0
1489 // OGCG: %[[RESULT_REAL:.*]] = load float, ptr %[[RESULT_REAL_PTR]], align 4
1490 // OGCG: %[[RESULT_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[RESULT_ADDR]], i32 0, i32 1
1491 // OGCG: %[[RESULT_IMAG:.*]] = load float, ptr %[[RESULT_IMAG_PTR]], align 4
1492 // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 0
1493 // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 1
1494 // OGCG: store float %[[RESULT_REAL]], ptr %[[A_REAL_PTR]], align 4
1495 // OGCG: store float %[[RESULT_IMAG]], ptr %[[A_IMAG_PTR]], align 4
1496
1497 void imag_literal_gnu_extension() {
1498 float _Complex a = 3.0fi;
1499 double _Complex b = 3.0i;
1500 int _Complex c = 3i;
1501 }
1502
1503 // CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["a", init]
1504 // CIR: %[[B_ADDR:.*]] = cir.alloca !cir.complex<!cir.double>, !cir.ptr<!cir.complex<!cir.double>>, ["b", init]
1505 // CIR: %[[C_ADDR:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["c", init]
1506 // CIR: %[[COMPLEX_A:.*]] = cir.const #cir.const_complex<#cir.fp<0.000000e+00> : !cir.float, #cir.fp<3.000000e+00> : !cir.float> : !cir.complex<!cir.float>
1507 // CIR: cir.store{{.*}} %[[COMPLEX_A]], %[[A_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
1508 // CIR: %[[COMPLEX_B:.*]] = cir.const #cir.const_complex<#cir.fp<0.000000e+00> : !cir.double, #cir.fp<3.000000e+00> : !cir.double> : !cir.complex<!cir.double>
1509 // CIR: cir.store{{.*}} %[[COMPLEX_B]], %[[B_ADDR]] : !cir.complex<!cir.double>, !cir.ptr<!cir.complex<!cir.double>>
1510 // CIR: %[[COMPLEX_C:.*]] = cir.const #cir.const_complex<#cir.int<0> : !s32i, #cir.int<3> : !s32i> : !cir.complex<!s32i>
1511 // CIR: cir.store{{.*}} %[[COMPLEX_C]], %[[C_ADDR]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
1512
1513 // LLVM: %[[A_ADDR:.*]] = alloca { float, float }, i64 1, align 4
1514 // LLVM: %[[B_ADDR:.*]] = alloca { double, double }, i64 1, align 8
1515 // LLVM: %[[C_ADDR:.*]] = alloca { i32, i32 }, i64 1, align 4
1516 // LLVM: store { float, float } { float 0.000000e+00, float 3.000000e+00 }, ptr %[[A_ADDR]], align 4
1517 // LLVM: store { double, double } { double 0.000000e+00, double 3.000000e+00 }, ptr %[[B_ADDR]], align 8
1518 // LLVM: store { i32, i32 } { i32 0, i32 3 }, ptr %[[C_ADDR]], align 4
1519
1520 // OGCG: %[[A_ADDR:.*]] = alloca { float, float }, align 4
1521 // OGCG: %[[B_ADDR:.*]] = alloca { double, double }, align 8
1522 // OGCG: %[[C_ADDR:.*]] = alloca { i32, i32 }, align 4
1523 // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 0
1524 // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 1
1525 // OGCG: store float 0.000000e+00, ptr %[[A_REAL_PTR]], align 4
1526 // OGCG: store float 3.000000e+00, ptr %[[A_IMAG_PTR]], align 4
1527 // OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[B_ADDR]], i32 0, i32 0
1528 // OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[B_ADDR]], i32 0, i32 1
1529 // OGCG: store double 0.000000e+00, ptr %[[B_REAL_PTR]], align 8
1530 // OGCG: store double 3.000000e+00, ptr %[[B_IMAG_PTR]], align 8
1531 // OGCG: %[[C_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[C_ADDR]], i32 0, i32 0
1532 // OGCG: %[[C_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[C_ADDR]], i32 0, i32 1
1533 // OGCG: store i32 0, ptr %[[C_REAL_PTR]], align 4
1534 // OGCG: store i32 3, ptr %[[C_IMAG_PTR]], align 4
1535
1536 void load_store_volatile() {
1537 volatile double _Complex a;
1538 volatile double _Complex b;
1539 a = b;
1540
1541 volatile int _Complex c;
1542 volatile int _Complex d;
1543 c = d;
1544 }
1545
1546 // CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.double>, !cir.ptr<!cir.complex<!cir.double>>, ["a"]
1547 // CIR: %[[B_ADDR:.*]] = cir.alloca !cir.complex<!cir.double>, !cir.ptr<!cir.complex<!cir.double>>, ["b"]
1548 // CIR: %[[C_ADDR:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["c"]
1549 // CIR: %[[D_ADDR:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["d"]
1550 // CIR: %[[TMP_B:.*]] = cir.load volatile {{.*}} %[[B_ADDR]] : !cir.ptr<!cir.complex<!cir.double>>, !cir.complex<!cir.double>
1551 // CIR: cir.store volatile {{.*}} %[[TMP_B]], %[[A_ADDR]] : !cir.complex<!cir.double>, !cir.ptr<!cir.complex<!cir.double>>
1552 // CIR: %[[TMP_D:.*]] = cir.load volatile {{.*}} %[[D_ADDR]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
1553 // CIR: cir.store volatile {{.*}} %[[TMP_D]], %[[C_ADDR]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
1554
1555 // LLVM: %[[A_ADDR:.*]] = alloca { double, double }, i64 1, align 8
1556 // LLVM: %[[B_ADDR:.*]] = alloca { double, double }, i64 1, align 8
1557 // LLVM: %[[C_ADDR:.*]] = alloca { i32, i32 }, i64 1, align 4
1558 // LLVM: %[[D_ADDR:.*]] = alloca { i32, i32 }, i64 1, align 4
1559 // LLVM: %[[TMP_B:.*]] = load volatile { double, double }, ptr %[[B_ADDR]], align 8
1560 // LLVM: store volatile { double, double } %[[TMP_B]], ptr %[[A_ADDR]], align 8
1561 // LLVM: %[[TMP_D:.*]] = load volatile { i32, i32 }, ptr %[[D_ADDR]], align 4
1562 // LLVM: store volatile { i32, i32 } %[[TMP_D]], ptr %[[C_ADDR]], align 4
1563
1564 // OGCG: %[[A_ADDR:.*]] = alloca { double, double }, align 8
1565 // OGCG: %[[B_ADDR:.*]] = alloca { double, double }, align 8
1566 // OGCG: %[[C_ADDR:.*]] = alloca { i32, i32 }, align 4
1567 // OGCG: %[[D_ADDR:.*]] = alloca { i32, i32 }, align 4
1568 // OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[B_ADDR]], i32 0, i32 0
1569 // OGCG: %[[B_REAL:.*]] = load volatile double, ptr %[[B_REAL_PTR]], align 8
1570 // OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[B_ADDR]], i32 0, i32 1
1571 // OGCG: %[[B_IMAG:.*]] = load volatile double, ptr %[[B_IMAG_PTR]], align 8
1572 // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[A_ADDR]], i32 0, i32 0
1573 // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[A_ADDR]], i32 0, i32 1
1574 // OGCG: store volatile double %[[B_REAL]], ptr %[[A_REAL_PTR]], align 8
1575 // OGCG: store volatile double %[[B_IMAG]], ptr %[[A_IMAG_PTR]], align 8
1576 // OGCG: %[[D_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[D_ADDR]], i32 0, i32 0
1577 // OGCG: %[[D_REAL:.*]] = load volatile i32, ptr %[[D_REAL_PTR]], align 4
1578 // OGCG: %[[D_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[D_ADDR]], i32 0, i32 1
1579 // OGCG: %[[D_IMAG:.*]] = load volatile i32, ptr %[[D_IMAG_PTR]], align 4
1580 // OGCG: %[[C_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[C_ADDR]], i32 0, i32 0
1581 // OGCG: %[[C_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[C_ADDR]], i32 0, i32 1
1582 // OGCG: store volatile i32 %[[D_REAL]], ptr %[[C_REAL_PTR]], align 4
1583 // OGCG: store volatile i32 %[[D_IMAG]], ptr %[[C_IMAG_PTR]], align 4
1584
1585
1586 void load_store_volatile_2() {
1587 volatile double _Complex av;
1588 double _Complex a;
1589 av = a;
1590
1591 double _Complex b;
1592 volatile double _Complex bv;
1593 b = bv;
1594
1595 int _Complex c;
1596 volatile int _Complex cv;
1597 c = cv;
1598
1599 volatile int _Complex dv;
1600 int _Complex d;
1601 dv = d;
1602 }
1603
1604 // CIR: %[[AV_ADDR:.*]] = cir.alloca !cir.complex<!cir.double>, !cir.ptr<!cir.complex<!cir.double>>, ["av"]
1605 // CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.double>, !cir.ptr<!cir.complex<!cir.double>>, ["a"]
1606 // CIR: %[[B_ADDR:.*]] = cir.alloca !cir.complex<!cir.double>, !cir.ptr<!cir.complex<!cir.double>>, ["b"]
1607 // CIR: %[[BV_ADDR:.*]] = cir.alloca !cir.complex<!cir.double>, !cir.ptr<!cir.complex<!cir.double>>, ["bv"]
1608 // CIR: %[[C_ADDR:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["c"]
1609 // CIR: %[[CV_ADDR:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["cv"]
1610 // CIR: %[[DV_ADDR:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["dv"]
1611 // CIR: %[[D_ADDR:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["d"]
1612 // CIR: %[[TMP_A:.*]] = cir.load {{.*}} %[[A_ADDR]] : !cir.ptr<!cir.complex<!cir.double>>, !cir.complex<!cir.double>
1613 // CIR: cir.store volatile {{.*}} %[[TMP_A]], %[[AV_ADDR]] : !cir.complex<!cir.double>, !cir.ptr<!cir.complex<!cir.double>>
1614 // CIR: %[[TMP_BV:.*]] = cir.load volatile {{.*}} %[[BV_ADDR]] : !cir.ptr<!cir.complex<!cir.double>>, !cir.complex<!cir.double>
1615 // CIR: cir.store {{.*}} %[[TMP_BV]], %[[B_ADDR]] : !cir.complex<!cir.double>, !cir.ptr<!cir.complex<!cir.double>>
1616 // CIR: %[[TMP_CV:.*]] = cir.load volatile {{.*}} %[[CV_ADDR]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
1617 // CIR: cir.store {{.*}} %[[TMP_CV]], %[[C_ADDR]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
1618 // CIR: %[[TMP_D:.*]] = cir.load {{.*}} %[[D_ADDR]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
1619 // CIR: cir.store volatile {{.*}} %[[TMP_D]], %[[DV_ADDR]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
1620
1621 // LLVM: %[[AV_ADDR:.*]] = alloca { double, double }, i64 1, align 8
1622 // LLVM: %[[A_ADDR:.*]] = alloca { double, double }, i64 1, align 8
1623 // LLVM: %[[B_ADDR:.*]] = alloca { double, double }, i64 1, align 8
1624 // LLVM: %[[BV_ADDR:.*]] = alloca { double, double }, i64 1, align 8
1625 // LLVM: %[[C_ADDR:.*]] = alloca { i32, i32 }, i64 1, align 4
1626 // LLVM: %[[CV_ADDR:.*]] = alloca { i32, i32 }, i64 1, align 4
1627 // LLVM: %[[DV_ADDR:.*]] = alloca { i32, i32 }, i64 1, align 4
1628 // LLVM: %[[D_ADDR:.*]] = alloca { i32, i32 }, i64 1, align 4
1629 // LLVM: %[[TMP_A:.*]] = load { double, double }, ptr %[[A_ADDR]], align 8
1630 // LLVM: store volatile { double, double } %[[TMP_A]], ptr %[[AV_ADDR]], align 8
1631 // LLVM: %[[TMP_BV:.*]] = load volatile { double, double }, ptr %[[BV_ADDR]], align 8
1632 // LLVM: store { double, double } %[[TMP_BV]], ptr %[[B_ADDR]], align 8
1633 // LLVM: %[[TMP_CV:.*]] = load volatile { i32, i32 }, ptr %[[CV_ADDR]], align 4
1634 // LLVM: store { i32, i32 } %[[TMP_CV]], ptr %[[C_ADDR]], align 4
1635 // LLVM: %[[TMP_D:.*]] = load { i32, i32 }, ptr %[[D_ADDR]], align 4
1636 // LLVM: store volatile { i32, i32 } %[[TMP_D]], ptr %[[DV_ADDR]], align 4
1637
1638 // OGCG: %[[AV_ADDR:.*]] = alloca { double, double }, align 8
1639 // OGCG: %[[A_ADDR:.*]] = alloca { double, double }, align 8
1640 // OGCG: %[[B_ADDR:.*]] = alloca { double, double }, align 8
1641 // OGCG: %[[BV_ADDR:.*]] = alloca { double, double }, align 8
1642 // OGCG: %[[C_ADDR:.*]] = alloca { i32, i32 }, align 4
1643 // OGCG: %[[CV_ADDR:.*]] = alloca { i32, i32 }, align 4
1644 // OGCG: %[[DV_ADDR:.*]] = alloca { i32, i32 }, align 4
1645 // OGCG: %[[D_ADDR:.*]] = alloca { i32, i32 }, align 4
1646 // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[A_ADDR]], i32 0, i32 0
1647 // OGCG: %[[A_REAL:.*]] = load double, ptr %[[A_REAL_PTR]], align 8
1648 // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[A_ADDR]], i32 0, i32 1
1649 // OGCG: %[[A_IMAG:.*]] = load double, ptr %[[A_IMAG_PTR]], align 8
1650 // OGCG: %[[AV_REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[AV_ADDR]], i32 0, i32 0
1651 // OGCG: %[[AV_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[AV_ADDR]], i32 0, i32 1
1652 // OGCG: store volatile double %[[A_REAL]], ptr %[[AV_REAL_PTR]], align 8
1653 // OGCG: store volatile double %[[A_IMAG]], ptr %[[AV_IMAG_PTR]], align 8
1654 // OGCG: %[[BV_REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[BV_ADDR]], i32 0, i32 0
1655 // OGCG: %[[BV_REAL:.*]] = load volatile double, ptr %[[BV_REAL_PTR]], align 8
1656 // OGCG: %[[BV_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[BV_ADDR]], i32 0, i32 1
1657 // OGCG: %[[BV_IMAG:.*]] = load volatile double, ptr %[[BV_IMAG_PTR]], align 8
1658 // OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[B_ADDR]], i32 0, i32 0
1659 // OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[B_ADDR]], i32 0, i32 1
1660 // OGCG: store double %[[BV_REAL]], ptr %[[B_REAL_PTR]], align 8
1661 // OGCG: store double %[[BV_IMAG]], ptr %[[B_IMAG_PTR]], align 8
1662 // OGCG: %[[CV_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[CV_ADDR]], i32 0, i32 0
1663 // OGCG: %[[CV_REAL:.*]] = load volatile i32, ptr %[[CV_REAL_PTR]], align 4
1664 // OGCG: %[[CV_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[CV_ADDR]], i32 0, i32 1
1665 // OGCG: %[[CV_IMAG:.*]] = load volatile i32, ptr %[[CV_IMAG_PTR]], align 4
1666 // OGCG: %[[C_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[C_ADDR]], i32 0, i32 0
1667 // OGCG: %[[C_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[C_ADDR]], i32 0, i32 1
1668 // OGCG: store i32 %[[CV_REAL]], ptr %[[C_REAL_PTR]], align 4
1669 // OGCG: store i32 %[[CV_IMAG]], ptr %[[C_IMAG_PTR]], align 4
1670 // OGCG: %[[D_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[D_ADDR]], i32 0, i32 0
1671 // OGCG: %[[D_REAL:.*]] = load i32, ptr %[[D_REAL_PTR]], align 4
1672 // OGCG: %[[D_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[D_ADDR]], i32 0, i32 1
1673 // OGCG: %[[D_IMAG:.*]] = load i32, ptr %[[D_IMAG_PTR]], align 4
1674 // OGCG: %[[DV_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[DV_ADDR]], i32 0, i32 0
1675 // OGCG: %[[DV_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[DV_ADDR]], i32 0, i32 1
1676 // OGCG: store volatile i32 %[[D_REAL]], ptr %[[DV_REAL_PTR]], align 4
1677 // OGCG: store volatile i32 %[[D_IMAG]], ptr %[[DV_IMAG_PTR]], align 4