Debian Codegraph @

clang/test/CIR/CodeGen/complex-builtins.cpp

raw
1 // RUN: %clang_cc1 -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 -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 -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 void foo() {
9 int _Complex a;
10 int _Complex b;
11 int _Complex r = __builtin_choose_expr(true, a, b);
12 }
13
14 // CIR: %[[COMPLEX_A:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["a"]
15 // CIR: %[[COMPLEX_R:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["r", init]
16 // CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[COMPLEX_A]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
17 // CIR: cir.store{{.*}} %[[TMP_A]], %[[COMPLEX_R]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
18
19 // LLVM: %[[COMPLEX_A:.*]] = alloca { i32, i32 }, i64 1, align 4
20 // LLVM: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, i64 1, align 4
21 // LLVM: %[[COMPLEX_R:.*]] = alloca { i32, i32 }, i64 1, align 4
22 // LLVM: %[[TMP_A:.*]] = load { i32, i32 }, ptr %[[COMPLEX_A]], align 4
23 // LLVM: store { i32, i32 } %[[TMP_A]], ptr %[[COMPLEX_R]], align 4
24
25 // OGCG: %[[COMPLEX_A:.*]] = alloca { i32, i32 }, align 4
26 // OGCG: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, align 4
27 // OGCG: %[[COMPLEX_R:.*]] = alloca { i32, i32 }, align 4
28 // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_A]], i32 0, i32 0
29 // OGCG: %[[A_REAL:.*]] = load i32, ptr %[[A_REAL_PTR]], align 4
30 // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_A]], i32 0, i32 1
31 // OGCG: %[[A_IMAG:.*]] = load i32, ptr %[[A_IMAG_PTR]], align 4
32 // OGCG: %[[R_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_R]], i32 0, i32 0
33 // OGCG: %[[R_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_R]], i32 0, i32 1
34 // OGCG: store i32 %[[A_REAL]], ptr %[[R_REAL_PTR]], align 4
35 // OGCG: store i32 %[[A_IMAG]], ptr %[[R_IMAG_PTR]], align 4
36
37 void foo2() {
38 double _Complex a;
39 double real = __builtin_creal(a);
40 }
41
42 // CIR: %[[COMPLEX:.*]] = cir.alloca !cir.complex<!cir.double>, !cir.ptr<!cir.complex<!cir.double>>, ["a"]
43 // CIR: %[[INIT:.*]] = cir.alloca !cir.double, !cir.ptr<!cir.double>, ["real", init]
44 // CIR: %[[TMP:.*]] = cir.load{{.*}} %[[COMPLEX]] : !cir.ptr<!cir.complex<!cir.double>>, !cir.complex<!cir.double>
45 // CIR: %[[REAL:.*]] = cir.complex.real %[[TMP]] : !cir.complex<!cir.double> -> !cir.double
46 // CIR: cir.store{{.*}} %[[REAL]], %[[INIT]] : !cir.double, !cir.ptr<!cir.double>
47
48 // LLVM: %[[COMPLEX:.*]] = alloca { double, double }, i64 1, align 8
49 // LLVM: %[[INIT:.*]] = alloca double, i64 1, align 8
50 // LLVM: %[[TMP:.*]] = load { double, double }, ptr %[[COMPLEX]], align 8
51 // LLVM: %[[REAL:.*]] = extractvalue { double, double } %[[TMP]], 0
52 // LLVM: store double %[[REAL]], ptr %[[INIT]], align 8
53
54 // OGCG: %[[COMPLEX:.*]] = alloca { double, double }, align 8
55 // OGCG: %[[INIT:.*]] = alloca double, align 8
56 // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX]], i32 0, i32 0
57 // OGCG: %[[A_REAL:.*]] = load double, ptr %[[A_REAL_PTR]], align 8
58 // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX]], i32 0, i32 1
59 // OGCG: %[[A_IMAG:.*]] = load double, ptr %[[A_IMAG_PTR]], align 8
60 // OGCG: store double %[[A_REAL]], ptr %[[INIT]], align 8
61
62 void foo3() {
63 double _Complex a;
64 double imag = __builtin_cimag(a);
65 }
66
67 // CIR: %[[COMPLEX:.*]] = cir.alloca !cir.complex<!cir.double>, !cir.ptr<!cir.complex<!cir.double>>, ["a"]
68 // CIR: %[[INIT:.*]] = cir.alloca !cir.double, !cir.ptr<!cir.double>, ["imag", init]
69 // CIR: %[[TMP:.*]] = cir.load{{.*}} %[[COMPLEX]] : !cir.ptr<!cir.complex<!cir.double>>, !cir.complex<!cir.double>
70 // CIR: %[[IMAG:.*]] = cir.complex.imag %[[TMP]] : !cir.complex<!cir.double> -> !cir.double
71 // CIR: cir.store{{.*}} %[[IMAG]], %[[INIT]] : !cir.double, !cir.ptr<!cir.double>
72
73 // LLVM: %[[COMPLEX:.*]] = alloca { double, double }, i64 1, align 8
74 // LLVM: %[[INIT:.*]] = alloca double, i64 1, align 8
75 // LLVM: %[[TMP:.*]] = load { double, double }, ptr %[[COMPLEX]], align 8
76 // LLVM: %[[IMAG:.*]] = extractvalue { double, double } %[[TMP]], 1
77 // LLVM: store double %[[IMAG]], ptr %[[INIT]], align 8
78
79 // OGCG: %[[COMPLEX:.*]] = alloca { double, double }, align 8
80 // OGCG: %[[INIT:.*]] = alloca double, align 8
81 // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX]], i32 0, i32 0
82 // OGCG: %[[A_REAL:.*]] = load double, ptr %[[A_REAL_PTR]], align 8
83 // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX]], i32 0, i32 1
84 // OGCG: %[[A_IMAG:.*]] = load double, ptr %[[A_IMAG_PTR]], align 8
85 // OGCG: store double %[[A_IMAG]], ptr %[[INIT]], align 8
86
87 void foo4() {
88 float _Complex a;
89 float _Complex b = __builtin_conjf(a);
90 }
91
92 // CIR: %[[COMPLEX:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["a"]
93 // CIR: %[[RESULT:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["b", init]
94 // CIR: %[[TMP:.*]] = cir.load{{.*}} %[[COMPLEX]] : !cir.ptr<!cir.complex<!cir.float>>, !cir.complex<!cir.float>
95 // CIR: %[[REAL:.*]] = cir.complex.real %[[TMP]] : !cir.complex<!cir.float> -> !cir.float
96 // CIR: %[[IMAG:.*]] = cir.complex.imag %[[TMP]] : !cir.complex<!cir.float> -> !cir.float
97 // CIR: %[[IMAG_MINUS:.*]] = cir.unary(minus, %[[IMAG]]) : !cir.float, !cir.float
98 // CIR: %[[RESULT_VAL:.*]] = cir.complex.create %[[REAL]], %[[IMAG_MINUS]] : !cir.float -> !cir.complex<!cir.float>
99 // CIR: cir.store{{.*}} %[[RESULT_VAL]], %[[RESULT]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
100
101 // LLVM: %[[COMPLEX:.*]] = alloca { float, float }, i64 1, align 4
102 // LLVM: %[[RESULT:.*]] = alloca { float, float }, i64 1, align 4
103 // LLVM: %[[TMP:.*]] = load { float, float }, ptr %[[COMPLEX]], align 4
104 // LLVM: %[[REAL:.*]] = extractvalue { float, float } %[[TMP]], 0
105 // LLVM: %[[IMAG:.*]] = extractvalue { float, float } %[[TMP]], 1
106 // LLVM: %[[IMAG_MINUS:.*]] = fneg float %[[IMAG]]
107 // LLVM: %[[RESULT_TMP:.*]] = insertvalue { float, float } {{.*}}, float %[[REAL]], 0
108 // LLVM: %[[RESULT_VAL:.*]] = insertvalue { float, float } %[[RESULT_TMP]], float %[[IMAG_MINUS]], 1
109 // LLVM: store { float, float } %[[RESULT_VAL]], ptr %[[RESULT]], align 4
110
111 // OGCG: %[[COMPLEX:.*]] = alloca { float, float }, align 4
112 // OGCG: %[[RESULT:.*]] = alloca { float, float }, align 4
113 // OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[COMPLEX]], i32 0, i32 0
114 // OGCG: %[[A_REAL:.*]] = load float, ptr %[[A_REAL_PTR]], align 4
115 // OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[COMPLEX]], i32 0, i32 1
116 // OGCG: %[[A_IMAG:.*]] = load float, ptr %[[A_IMAG_PTR]], align 4
117 // OGCG: %[[A_IMAG_MINUS:.*]] = fneg float %[[A_IMAG]]
118 // OGCG: %[[RESULT_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[RESULT]], i32 0, i32 0
119 // OGCG: %[[RESULT_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[RESULT]], i32 0, i32 1
120 // OGCG: store float %[[A_REAL]], ptr %[[RESULT_REAL_PTR]], align 4
121 // OGCG: store float %[[A_IMAG_MINUS]], ptr %[[RESULT_IMAG_PTR]], align 4