| 1 |
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir -mmlir --mlir-print-ir-before=cir-canonicalize -o %t.cir %s 2>&1 | FileCheck --check-prefix=CIR-BEFORE %s |
| 2 |
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir -mmlir --mlir-print-ir-after=cir-lowering-prepare -o %t.cir %s 2>&1 | FileCheck --check-prefixes=CIR-AFTER %s |
| 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 |
double _Complex cd; |
| 9 |
float _Complex cf; |
| 10 |
int _Complex ci; |
| 11 |
short _Complex cs; |
| 12 |
double sd; |
| 13 |
int si; |
| 14 |
bool b; |
| 15 |
|
| 16 |
void scalar_to_complex() { |
| 17 |
cd = sd; |
| 18 |
ci = si; |
| 19 |
cd = si; |
| 20 |
ci = sd; |
| 21 |
} |
| 22 |
|
| 23 |
// CIR-BEFORE: %[[FP_TO_COMPLEX:.*]] = cir.cast float_to_complex %{{.*}} : !cir.double -> !cir.complex<!cir.double> |
| 24 |
|
| 25 |
// CIR-AFTER: %[[REAL:.*]] = cir.load{{.*}} %{{.*}} : !cir.ptr<!cir.double>, !cir.double |
| 26 |
// CIR-AFTER-NEXT: %[[IMAG:.*]] = cir.const #cir.fp<0.000000e+00> : !cir.double |
| 27 |
// CIR-AFTER-NEXT: %{{.*}} = cir.complex.create %[[REAL]], %[[IMAG]] : !cir.double -> !cir.complex<!cir.double> |
| 28 |
|
| 29 |
// LLVM: %[[REAL:.*]] = load double, ptr {{.*}}, align 8 |
| 30 |
// LLVM-NEXT: %[[TMP:.*]] = insertvalue { double, double } undef, double %[[REAL]], 0 |
| 31 |
// LLVM-NEXT: %[[COMPLEX:.*]] = insertvalue { double, double } %[[TMP]], double 0.000000e+00, 1 |
| 32 |
// LLVM-NEXT: store { double, double } %[[COMPLEX]], ptr {{.*}}, align 8 |
| 33 |
|
| 34 |
// OGCG: %[[REAL:.*]] = load double, ptr {{.*}}, align 8 |
| 35 |
// OGCG: store double %[[REAL]], ptr {{.*}}, align 8 |
| 36 |
// OGCG: store double 0.000000e+00, ptr getelementptr inbounds nuw ({ double, double }, ptr @cd, i32 0, i32 1), align 8 |
| 37 |
|
| 38 |
// CIR-BEFORE: %[[INT_TO_COMPLEX:.*]] = cir.cast int_to_complex %{{.*}} : !s32i -> !cir.complex<!s32i> |
| 39 |
|
| 40 |
// CIR-AFTER: %[[REAL:.*]] = cir.load{{.*}} %{{.*}} : !cir.ptr<!s32i>, !s32i |
| 41 |
// CIR-AFTER-NEXT: %[[IMAG:.*]] = cir.const #cir.int<0> : !s32i |
| 42 |
// CIR-AFTER-NEXT: %{{.*}} = cir.complex.create %[[REAL]], %[[IMAG]] : !s32i -> !cir.complex<!s32i> |
| 43 |
|
| 44 |
// LLVM: %[[REAL:.*]] = load i32, ptr {{.*}}, align 4 |
| 45 |
// LLVM-NEXT: %[[TMP:.*]] = insertvalue { i32, i32 } undef, i32 %[[REAL]], 0 |
| 46 |
// LLVM-NEXT: %[[COMPLEX:.*]] = insertvalue { i32, i32 } %[[TMP]], i32 0, 1 |
| 47 |
// LLVM-NEXT: store { i32, i32 } %[[COMPLEX]], ptr {{.*}}, align 4 |
| 48 |
|
| 49 |
// OGCG: %[[REAL:.*]] = load i32, ptr {{.*}}, align 4 |
| 50 |
// OGCG: store i32 %[[REAL]], ptr {{.*}}, align 4 |
| 51 |
// OGCG: store i32 0, ptr getelementptr inbounds nuw ({ i32, i32 }, ptr @ci, i32 0, i32 1), align 4 |
| 52 |
|
| 53 |
// CIR-BEFORE: %[[INT_TO_FP:.*]] = cir.cast int_to_float %{{.*}} : !s32i -> !cir.double |
| 54 |
// CIR-BEFORE: %[[FP_TO_COMPLEX:.*]] = cir.cast float_to_complex %[[INT_TO_FP]] : !cir.double -> !cir.complex<!cir.double> |
| 55 |
|
| 56 |
// CIR-AFTER: %[[TMP:.*]] = cir.load{{.*}} %{{.*}} : !cir.ptr<!s32i>, !s32i |
| 57 |
// CIR-AFTER-NEXT: %[[REAL:.*]] = cir.cast int_to_float %[[TMP]] : !s32i -> !cir.double |
| 58 |
// CIR-AFTER-NEXT: %[[IMAG:.*]] = cir.const #cir.fp<0.000000e+00> : !cir.double |
| 59 |
// CIR-AFTER-NEXT: %{{.*}} = cir.complex.create %[[REAL]], %[[IMAG]] : !cir.double -> !cir.complex<!cir.double> |
| 60 |
|
| 61 |
// LLVM: %[[TMP:.*]] = load i32, ptr {{.*}}, align 4 |
| 62 |
// LLVM-NEXT: %[[REAL:.*]] = sitofp i32 %[[TMP]] to double |
| 63 |
// LLVM-NEXT: %[[TMP_2:.*]] = insertvalue { double, double } undef, double %[[REAL]], 0 |
| 64 |
// LLVM-NEXT: %[[COMPLEX:.*]] = insertvalue { double, double } %[[TMP_2]], double 0.000000e+00, 1 |
| 65 |
// LLVM-NEXT: store { double, double } %[[COMPLEX]], ptr {{.*}}, align 8 |
| 66 |
|
| 67 |
// OGCG: %[[TMP:.*]] = load i32, ptr {{.*}}, align 4 |
| 68 |
// OGCG: %[[REAL:.*]] = sitofp i32 %[[TMP]] to double |
| 69 |
// OGCG: store double %[[REAL]], ptr {{.*}}, align 8 |
| 70 |
// OGCG: store double 0.000000e+00, ptr getelementptr inbounds nuw ({ double, double }, ptr {{.*}}, i32 0, i32 1), align 8 |
| 71 |
|
| 72 |
// CIR-BEFORE: %[[FP_TO_INT:.*]] = cir.cast float_to_int %{{.*}} : !cir.double -> !s32i |
| 73 |
// CIR-BEFORE: %[[INT_TO_COMPLEX:.*]] = cir.cast int_to_complex %[[FP_TO_INT]] : !s32i -> !cir.complex<!s32i> |
| 74 |
|
| 75 |
// CIR-AFTER: %[[TMP:.*]] = cir.load{{.*}} %{{.*}} : !cir.ptr<!cir.double>, !cir.double |
| 76 |
// CIR-AFTER-NEXT: %[[REAL:.*]] = cir.cast float_to_int %[[TMP]] : !cir.double -> !s32i |
| 77 |
// CIR-AFTER-NEXT: %[[IMAG:.*]] = cir.const #cir.int<0> : !s32i |
| 78 |
// CIR-AFTER-NEXT: %{{.*}} = cir.complex.create %[[REAL]], %[[IMAG]] : !s32i -> !cir.complex<!s32i> |
| 79 |
|
| 80 |
// LLVM: %[[TMP:.*]] = load double, ptr {{.*}}, align 8 |
| 81 |
// LLVM-NEXT: %[[REAL:.*]] = fptosi double %[[TMP]] to i32 |
| 82 |
// LLVM-NEXT: %[[TMP_2:.*]] = insertvalue { i32, i32 } undef, i32 %[[REAL]], 0 |
| 83 |
// LLVM-NEXT: %[[COMPLEX:.*]] = insertvalue { i32, i32 } %[[TMP_2]], i32 0, 1 |
| 84 |
// LLVM-NEXT: store { i32, i32 } %[[COMPLEX]], ptr {{.*}}, align 4 |
| 85 |
|
| 86 |
// OGCG: %[[TMP:.*]] = load double, ptr {{.*}}, align 8 |
| 87 |
// OGCG: %[[REAL:.*]] = fptosi double %[[TMP]] to i32 |
| 88 |
// OGCG: store i32 %[[REAL]], ptr {{.*}}, align 4 |
| 89 |
// OGCG: store i32 0, ptr getelementptr inbounds nuw ({ i32, i32 }, ptr {{.*}}, i32 0, i32 1), align 4 |
| 90 |
|
| 91 |
void scalar_to_complex_explicit() { |
| 92 |
cd = (double _Complex)sd; |
| 93 |
ci = (int _Complex)si; |
| 94 |
cd = (double _Complex)si; |
| 95 |
ci = (int _Complex)sd; |
| 96 |
} |
| 97 |
|
| 98 |
// CIR-BEFORE: %[[FP_TO_COMPLEX:.*]] = cir.cast float_to_complex %{{.*}} : !cir.double -> !cir.complex<!cir.double> |
| 99 |
|
| 100 |
// CIR-AFTER: %[[REAL:.*]] = cir.load{{.*}} %{{.*}} : !cir.ptr<!cir.double>, !cir.double |
| 101 |
// CIR-AFTER-NEXT: %[[IMAG:.*]] = cir.const #cir.fp<0.000000e+00> : !cir.double |
| 102 |
// CIR-AFTER-NEXT: %{{.*}} = cir.complex.create %[[REAL]], %[[IMAG]] : !cir.double -> !cir.complex<!cir.double> |
| 103 |
|
| 104 |
// LLVM: %[[REAL:.*]] = load double, ptr {{.*}}, align 8 |
| 105 |
// LLVM-NEXT: %[[TMP:.*]] = insertvalue { double, double } undef, double %[[REAL]], 0 |
| 106 |
// LLVM-NEXT: %[[COMPLEX:.*]] = insertvalue { double, double } %[[TMP]], double 0.000000e+00, 1 |
| 107 |
// LLVM-NEXT: store { double, double } %[[COMPLEX]], ptr {{.*}}, align 8 |
| 108 |
|
| 109 |
// OGCG: %[[REAL:.*]] = load double, ptr {{.*}}, align 8 |
| 110 |
// OGCG: store double %[[REAL]], ptr {{.*}}, align 8 |
| 111 |
// OGCG: store double 0.000000e+00, ptr getelementptr inbounds nuw ({ double, double }, ptr @cd, i32 0, i32 1), align 8 |
| 112 |
|
| 113 |
// CIR-BEFORE: %[[INT_TO_COMPLEX:.*]] = cir.cast int_to_complex %{{.*}} : !s32i -> !cir.complex<!s32i> |
| 114 |
|
| 115 |
// CIR-AFTER: %[[REAL:.*]] = cir.load{{.*}} %{{.*}} : !cir.ptr<!s32i>, !s32i |
| 116 |
// CIR-AFTER-NEXT: %[[IMAG:.*]] = cir.const #cir.int<0> : !s32i |
| 117 |
// CIR-AFTER-NEXT: %{{.*}} = cir.complex.create %[[REAL]], %[[IMAG]] : !s32i -> !cir.complex<!s32i> |
| 118 |
|
| 119 |
// LLVM: %[[REAL:.*]] = load i32, ptr {{.*}}, align 4 |
| 120 |
// LLVM-NEXT: %[[TMP:.*]] = insertvalue { i32, i32 } undef, i32 %[[REAL]], 0 |
| 121 |
// LLVM-NEXT: %[[COMPLEX:.*]] = insertvalue { i32, i32 } %[[TMP]], i32 0, 1 |
| 122 |
// LLVM-NEXT: store { i32, i32 } %[[COMPLEX]], ptr {{.*}}, align 4 |
| 123 |
|
| 124 |
// OGCG: %[[REAL:.*]] = load i32, ptr {{.*}}, align 4 |
| 125 |
// OGCG: store i32 %[[REAL]], ptr {{.*}}, align 4 |
| 126 |
// OGCG: store i32 0, ptr getelementptr inbounds nuw ({ i32, i32 }, ptr @ci, i32 0, i32 1), align 4 |
| 127 |
|
| 128 |
// CIR-BEFORE: %[[INT_TO_FP:.*]] = cir.cast int_to_float %{{.*}} : !s32i -> !cir.double |
| 129 |
// CIR-BEFORE: %[[FP_TO_COMPLEX:.*]] = cir.cast float_to_complex %[[INT_TO_FP]] : !cir.double -> !cir.complex<!cir.double> |
| 130 |
|
| 131 |
// CIR-AFTER: %[[TMP:.*]] = cir.load{{.*}} %{{.*}} : !cir.ptr<!s32i>, !s32i |
| 132 |
// CIR-AFTER-NEXT: %[[REAL:.*]] = cir.cast int_to_float %[[TMP]] : !s32i -> !cir.double |
| 133 |
// CIR-AFTER-NEXT: %[[IMAG:.*]] = cir.const #cir.fp<0.000000e+00> : !cir.double |
| 134 |
// CIR-AFTER-NEXT: %{{.*}} = cir.complex.create %[[REAL]], %[[IMAG]] : !cir.double -> !cir.complex<!cir.double> |
| 135 |
|
| 136 |
// LLVM: %[[TMP:.*]] = load i32, ptr {{.*}}, align 4 |
| 137 |
// LLVM-NEXT: %[[REAL:.*]] = sitofp i32 %[[TMP]] to double |
| 138 |
// LLVM-NEXT: %[[TMP_2:.*]] = insertvalue { double, double } undef, double %[[REAL]], 0 |
| 139 |
// LLVM-NEXT: %[[COMPLEX:.*]] = insertvalue { double, double } %[[TMP_2]], double 0.000000e+00, 1 |
| 140 |
// LLVM-NEXT: store { double, double } %[[COMPLEX]], ptr {{.*}}, align 8 |
| 141 |
|
| 142 |
// OGCG: %[[TMP:.*]] = load i32, ptr {{.*}}, align 4 |
| 143 |
// OGCG: %[[REAL:.*]] = sitofp i32 %[[TMP]] to double |
| 144 |
// OGCG: store double %[[REAL]], ptr {{.*}}, align 8 |
| 145 |
// OGCG: store double 0.000000e+00, ptr getelementptr inbounds nuw ({ double, double }, ptr {{.*}}, i32 0, i32 1), align 8 |
| 146 |
|
| 147 |
// CIR-BEFORE: %[[FP_TO_INT:.*]] = cir.cast float_to_int %{{.*}} : !cir.double -> !s32i |
| 148 |
// CIR-BEFORE: %[[INT_TO_COMPLEX:.*]] = cir.cast int_to_complex %[[FP_TO_INT]] : !s32i -> !cir.complex<!s32i> |
| 149 |
|
| 150 |
// CIR-AFTER: %[[TMP:.*]] = cir.load{{.*}} %{{.*}} : !cir.ptr<!cir.double>, !cir.double |
| 151 |
// CIR-AFTER-NEXT: %[[REAL:.*]] = cir.cast float_to_int %[[TMP]] : !cir.double -> !s32i |
| 152 |
// CIR-AFTER-NEXT: %[[IMAG:.*]] = cir.const #cir.int<0> : !s32i |
| 153 |
// CIR-AFTER-NEXT: %{{.*}} = cir.complex.create %[[REAL]], %[[IMAG]] : !s32i -> !cir.complex<!s32i> |
| 154 |
|
| 155 |
// LLVM: %[[TMP:.*]] = load double, ptr {{.*}}, align 8 |
| 156 |
// LLVM-NEXT: %[[REAL:.*]] = fptosi double %[[TMP]] to i32 |
| 157 |
// LLVM-NEXT: %[[TMP_2:.*]] = insertvalue { i32, i32 } undef, i32 %[[REAL]], 0 |
| 158 |
// LLVM-NEXT: %[[COMPLEX:.*]] = insertvalue { i32, i32 } %[[TMP_2]], i32 0, 1 |
| 159 |
// LLVM-NEXT: store { i32, i32 } %[[COMPLEX]], ptr {{.*}}, align 4 |
| 160 |
|
| 161 |
// OGCG: %[[TMP:.*]] = load double, ptr {{.*}}, align 8 |
| 162 |
// OGCG: %[[REAL:.*]] = fptosi double %[[TMP]] to i32 |
| 163 |
// OGCG: store i32 %[[REAL]], ptr {{.*}}, align 4 |
| 164 |
// OGCG: store i32 0, ptr getelementptr inbounds nuw ({ i32, i32 }, ptr {{.*}}, i32 0, i32 1), align 4 |
| 165 |
|
| 166 |
void complex_to_scalar() { |
| 167 |
sd = (double)cd; |
| 168 |
si = (int)ci; |
| 169 |
sd = (double)ci; |
| 170 |
si = (int)cd; |
| 171 |
} |
| 172 |
|
| 173 |
// CIR-BEFORE: %[[FP_TO_COMPLEX_REAL:.*]] = cir.cast float_complex_to_real %{{.*}} : !cir.complex<!cir.double> -> !cir.double |
| 174 |
|
| 175 |
// CIR-AFTER: %{{.*}} = cir.complex.real %{{.*}} : !cir.complex<!cir.double> -> !cir.double |
| 176 |
|
| 177 |
// LLVM: %[[REAL:.*]] = extractvalue { double, double } %{{.*}}, 0 |
| 178 |
// LLVM: store double %[[REAL]], ptr {{.*}}, align 8 |
| 179 |
|
| 180 |
// OGCG: %[[REAL:.*]] = load double, ptr {{.*}}, align 8 |
| 181 |
// OGCG: store double %[[REAL]], ptr {{.*}}, align 8 |
| 182 |
|
| 183 |
// CIR-BEFORE: %[[INT_COMPLEX_TO_REAL:.*]] = cir.cast int_complex_to_real %{{.*}} : !cir.complex<!s32i> -> !s32i |
| 184 |
|
| 185 |
// CIR-AFTER: %{{.*}} = cir.complex.real %{{.*}} : !cir.complex<!s32i> -> !s32i |
| 186 |
|
| 187 |
// LLVM: %[[REAL:.*]] = extractvalue { i32, i32 } %{{.*}}, 0 |
| 188 |
// LLVM: store i32 %[[REAL]], ptr {{.*}}, align 4 |
| 189 |
|
| 190 |
// OGCG: %[[REAL:.*]] = load i32, ptr {{.*}}, align 4 |
| 191 |
// OGCG: store i32 %[[REAL]], ptr {{.*}}, align 4 |
| 192 |
|
| 193 |
// CIR-BEFORE: %[[INT_COMPLEX_TO_REAL:.*]] = cir.cast int_complex_to_real %{{.*}} : !cir.complex<!s32i> -> !s32i |
| 194 |
// CIR-BEFORE: %[[INT_TO_FP:.*]] = cir.cast int_to_float %[[INT_COMPLEX_TO_REAL]] : !s32i -> !cir.double |
| 195 |
|
| 196 |
// CIR-AFTER: %[[REAL:.*]] = cir.complex.real %{{.*}} : !cir.complex<!s32i> -> !s32i |
| 197 |
// CIR-AFTER-NEXT: %{{.*}} = cir.cast int_to_float %[[REAL]] : !s32i -> !cir.double |
| 198 |
|
| 199 |
// LLVM: %[[REAL:.*]] = extractvalue { i32, i32 } %{{.+}}, 0 |
| 200 |
// LLVM-NEXT: %[[REAL_TO_DOUBLE:.*]] = sitofp i32 %[[REAL]] to double |
| 201 |
// LLVM-NEXT: store double %[[REAL_TO_DOUBLE]], ptr {{.*}}, align 8 |
| 202 |
|
| 203 |
// OGCG: %[[REAL:.*]] = load i32, ptr {{.*}}, align 4 |
| 204 |
// OGCG: %[[INT_TO_FP:.*]] = sitofp i32 %[[REAL]] to double |
| 205 |
// OGCG: store double %[[INT_TO_FP]], ptr {{.*}}, align 8 |
| 206 |
|
| 207 |
// CIR-BEFORE: %[[FP_TO_COMPLEX_REAL:.*]] = cir.cast float_complex_to_real %{{.*}} : !cir.complex<!cir.double> -> !cir.double |
| 208 |
// CIR-BEFORE: %[[FP_TO_INT:.*]] = cir.cast float_to_int %[[FP_TO_COMPLEX_REAL]] : !cir.double -> !s32i |
| 209 |
|
| 210 |
// CIR-AFTER: %[[REAL:.*]] = cir.complex.real %{{.*}} : !cir.complex<!cir.double> -> !cir.double |
| 211 |
// CIR-AFTER-NEXT: %{{.*}} = cir.cast float_to_int %[[REAL]] : !cir.double -> !s32i |
| 212 |
|
| 213 |
// LLVM: %[[REAL:.*]] = extractvalue { double, double } %{{.+}}, 0 |
| 214 |
// LLVM-NEXT: %[[REAL_TO_INT:.*]] = fptosi double %[[REAL]] to i32 |
| 215 |
// LLVM-NEXT: store i32 %[[REAL_TO_INT]], ptr {{.*}}, align 4 |
| 216 |
|
| 217 |
// OGCG: %[[REAL:.*]] = load double, ptr {{.*}}, align 8 |
| 218 |
// OGCG: %[[FP_TO_INT:.*]] = fptosi double %[[REAL]] to i32 |
| 219 |
// OGCG: store i32 %[[FP_TO_INT]], ptr {{.*}}, align 4 |
| 220 |
|
| 221 |
void complex_to_bool() { |
| 222 |
b = (bool)cd; |
| 223 |
b = (bool)ci; |
| 224 |
} |
| 225 |
|
| 226 |
// CIR-BEFORE: %[[FP_COMPLEX_TO_BOOL:.*]] = cir.cast float_complex_to_bool %{{.*}} : !cir.complex<!cir.double> -> !cir.bool |
| 227 |
|
| 228 |
// CIR-AFTER: %[[REAL:.*]] = cir.complex.real %{{.*}} : !cir.complex<!cir.double> -> !cir.double |
| 229 |
// CIR-AFTER-NEXT: %[[IMAG:.*]] = cir.complex.imag %{{.*}} : !cir.complex<!cir.double> -> !cir.double |
| 230 |
// CIR-AFTER-NEXT: %[[REAL_TO_BOOL:.*]] = cir.cast float_to_bool %[[REAL]] : !cir.double -> !cir.bool |
| 231 |
// CIR-AFTER-NEXT: %[[IMAG_TO_BOOL:.*]] = cir.cast float_to_bool %[[IMAG]] : !cir.double -> !cir.bool |
| 232 |
// CIR-AFTER-NEXT: %[[CONST_TRUE:.*]] = cir.const #true |
| 233 |
// CIR-AFTER-NEXT: %{{.*}} = cir.select if %[[REAL_TO_BOOL]] then %[[CONST_TRUE]] else %[[IMAG_TO_BOOL]] : (!cir.bool, !cir.bool, !cir.bool) -> !cir.bool |
| 234 |
|
| 235 |
// LLVM: %[[REAL:.*]] = extractvalue { double, double } %{{.*}}, 0 |
| 236 |
// LLVM-NEXT: %[[IMAG:.*]] = extractvalue { double, double } %{{.*}}, 1 |
| 237 |
// LLVM-NEXT: %[[REAL_TO_BOOL:.*]] = fcmp une double %[[REAL]], 0.000000e+00 |
| 238 |
// LLVM-NEXT: %[[IMAG_TO_BOOL:.*]] = fcmp une double %[[IMAG]], 0.000000e+00 |
| 239 |
// LLVM-NEXT: %[[OR:.*]] = or i1 %[[REAL_TO_BOOL]], %[[IMAG_TO_BOOL]] |
| 240 |
// LLVM-NEXT: %[[RESULT:.*]] = zext i1 %[[OR]] to i8 |
| 241 |
// LLVM-NEXT: store i8 %[[RESULT]], ptr {{.*}}, align 1 |
| 242 |
|
| 243 |
// OGCG: %[[REAL:.*]] = load double, ptr {{.*}}, align 8 |
| 244 |
// OGCG: %[[IMAG:.*]] = load double, ptr getelementptr inbounds nuw ({ double, double }, ptr {{.*}}, i32 0, i32 1), align 8 |
| 245 |
// OGCG: %[[REAL_TO_BOOL:.*]] = fcmp une double %[[REAL]], 0.000000e+00 |
| 246 |
// OGCG: %[[IMAG_TO_BOOL:.*]] = fcmp une double %[[IMAG]], 0.000000e+00 |
| 247 |
// OGCG: %[[COMPLEX_TO_BOOL:.*]] = or i1 %[[REAL_TO_BOOL]], %[[IMAG_TO_BOOL]] |
| 248 |
// OGCG: %[[BOOL_TO_INT:.*]] = zext i1 %[[COMPLEX_TO_BOOL]] to i8 |
| 249 |
// OGCG: store i8 %[[BOOL_TO_INT]], ptr {{.*}}, align 1 |
| 250 |
|
| 251 |
// CIR-BEFORE: %[[INT_COMPLEX_TO_BOOL:.*]] = cir.cast int_complex_to_bool %{{.*}} : !cir.complex<!s32i> -> !cir.bool |
| 252 |
|
| 253 |
// CIR-AFTER: %[[REAL:.*]] = cir.complex.real %{{.*}} : !cir.complex<!s32i> -> !s32i |
| 254 |
// CIR-AFTER-NEXT: %[[IMAG:.*]] = cir.complex.imag %{{.*}} : !cir.complex<!s32i> -> !s32i |
| 255 |
// CIR-AFTER-NEXT: %[[REAL_TO_BOOL:.*]] = cir.cast int_to_bool %[[REAL]] : !s32i -> !cir.bool |
| 256 |
// CIR-AFTER-NEXT: %[[IMAG_TO_BOOL:.*]] = cir.cast int_to_bool %[[IMAG]] : !s32i -> !cir.bool |
| 257 |
// CIR-AFTER-NEXT: %[[CONST_TRUE:.*]] = cir.const #true |
| 258 |
// CIR-AFTER-NEXT: %{{.+}} = cir.select if %[[REAL_TO_BOOL]] then %[[CONST_TRUE]] else %[[IMAG_TO_BOOL]] : (!cir.bool, !cir.bool, !cir.bool) -> !cir.bool |
| 259 |
|
| 260 |
// LLVM: %[[REAL:.*]] = extractvalue { i32, i32 } %{{.*}}, 0 |
| 261 |
// LLVM-NEXT: %[[IMAG:.*]] = extractvalue { i32, i32 } %{{.*}}, 1 |
| 262 |
// LLVM-NEXT: %[[REAL_TO_BOOL:.*]] = icmp ne i32 %[[REAL]], 0 |
| 263 |
// LLVM-NEXT: %[[IMAG_TO_BOOL:.*]] = icmp ne i32 %[[IMAG]], 0 |
| 264 |
// LLVM-NEXT: %[[OR:.*]] = or i1 %[[REAL_TO_BOOL]], %[[IMAG_TO_BOOL]] |
| 265 |
// LLVM-NEXT: %[[RESULT:.*]] = zext i1 %[[OR]] to i8 |
| 266 |
// LLVM-NEXT: store i8 %[[RESULT]], ptr {{.*}}, align 1 |
| 267 |
|
| 268 |
// OGCG: %[[REAL:.*]] = load i32, ptr {{.*}}, align 4 |
| 269 |
// OGCG: %[[IMAG:.*]] = load i32, ptr getelementptr inbounds nuw ({ i32, i32 }, ptr {{.*}}, i32 0, i32 1), align 4 |
| 270 |
// OGCG: %[[REAL_TO_BOOL:.*]] = icmp ne i32 %[[REAL]], 0 |
| 271 |
// OGCG: %[[IMAG_TO_BOOL:.*]] = icmp ne i32 %[[IMAG]], 0 |
| 272 |
// OGCG: %[[COMPLEX_TO_BOOL:.*]] = or i1 %[[REAL_TO_BOOL]], %[[IMAG_TO_BOOL]] |
| 273 |
// OGCG: %[[BOOL_TO_INT:.*]] = zext i1 %[[COMPLEX_TO_BOOL]] to i8 |
| 274 |
// OGCG: store i8 %[[BOOL_TO_INT]], ptr {{.*}}, align 1 |
| 275 |
|
| 276 |
void complex_to_complex_cast() { |
| 277 |
cd = cf; |
| 278 |
ci = cs; |
| 279 |
} |
| 280 |
|
| 281 |
// CIR-BEFORE: %[[TMP:.*]] = cir.load{{.*}} %{{.*}} : !cir.ptr<!cir.complex<!cir.float>>, !cir.complex<!cir.float> |
| 282 |
// CIR-BEFORE: %[[FP_COMPLEX:.*]] = cir.cast float_complex %[[TMP]] : !cir.complex<!cir.float> -> !cir.complex<!cir.double> |
| 283 |
|
| 284 |
// CIR-AFTER: %[[REAL:.*]] = cir.complex.real %{{.*}} : !cir.complex<!cir.float> -> !cir.float |
| 285 |
// CIR-AFTER: %[[IMAG:.*]] = cir.complex.imag %{{.*}} : !cir.complex<!cir.float> -> !cir.float |
| 286 |
// CIR-AFTER: %[[REAL_FP_CAST:.*]] = cir.cast floating %[[REAL]] : !cir.float -> !cir.double |
| 287 |
// CIR-AFTER: %[[IMAG_FP_CAST:.*]] = cir.cast floating %[[IMAG]] : !cir.float -> !cir.double |
| 288 |
// CIR-AFTER: %{{.*}} = cir.complex.create %[[REAL_FP_CAST]], %[[IMAG_FP_CAST]] : !cir.double -> !cir.complex<!cir.double> |
| 289 |
|
| 290 |
// LLVM: %[[REAL:.*]] = extractvalue { float, float } %{{.*}}, 0 |
| 291 |
// LLVM: %[[IMAG:.*]] = extractvalue { float, float } %{{.*}}, 1 |
| 292 |
// LLVM: %[[REAL_FP_CAST:.*]] = fpext float %[[REAL]] to double |
| 293 |
// LLVM: %[[IMAG_FP_CAST:.*]] = fpext float %[[IMAG]] to double |
| 294 |
// LLVM: %[[TMP:.*]] = insertvalue { double, double } undef, double %[[REAL_FP_CAST]], 0 |
| 295 |
// LLVM: %[[COMPLEX:.*]] = insertvalue { double, double } %[[TMP]], double %[[IMAG_FP_CAST]], 1 |
| 296 |
// LLVM: store { double, double } %[[COMPLEX]], ptr {{.*}}, align 8 |
| 297 |
|
| 298 |
// OGCG: %[[REAL:.*]] = load float, ptr {{.*}}, align 4 |
| 299 |
// OGCG: %[[IMAG:.*]] = load float, ptr getelementptr inbounds nuw ({ float, float }, ptr {{.*}}, i32 0, i32 1), align 4 |
| 300 |
// OGCG: %[[REAL_FP_CAST:.*]] = fpext float %[[REAL]] to double |
| 301 |
// OGCG: %[[IMAG_FP_CAST:.*]] = fpext float %[[IMAG]] to double |
| 302 |
// OGCG: store double %[[REAL_FP_CAST]], ptr {{.*}}, align 8 |
| 303 |
// OGCG: store double %[[IMAG_FP_CAST]], ptr getelementptr inbounds nuw ({ double, double }, ptr {{.*}}, i32 0, i32 1), align 8 |
| 304 |
|
| 305 |
// CIR-BEFORE: %[[TMP:.*]] = cir.load{{.*}} %{{.*}} : !cir.ptr<!cir.complex<!s16i>>, !cir.complex<!s16i> |
| 306 |
// CIR-BEFORE: %[[INT_COMPLEX:.*]] = cir.cast int_complex %[[TMP]] : !cir.complex<!s16i> -> !cir.complex<!s32i> |
| 307 |
|
| 308 |
// CIR-AFTER: %[[REAL:.*]] = cir.complex.real %{{.*}} : !cir.complex<!s16i> -> !s16i |
| 309 |
// CIR-AFTER: %[[IMAG:.*]] = cir.complex.imag %{{.*}} : !cir.complex<!s16i> -> !s16i |
| 310 |
// CIR-AFTER: %[[REAL_INT_CAST:.*]] = cir.cast integral %[[REAL]] : !s16i -> !s32i |
| 311 |
// CIR-AFTER: %[[IMAG_INT_CAST:.*]] = cir.cast integral %[[IMAG]] : !s16i -> !s32i |
| 312 |
// CIR-AFTER: %{{.*}} = cir.complex.create %[[REAL_INT_CAST]], %[[IMAG_INT_CAST]] : !s32i -> !cir.complex<!s32i> |
| 313 |
|
| 314 |
// LLVM: %[[REAL:.*]] = extractvalue { i16, i16 } %{{.*}}, 0 |
| 315 |
// LLVM: %[[IMAG:.*]] = extractvalue { i16, i16 } %{{.*}}, 1 |
| 316 |
// LLVM: %[[REAL_INT_CAST:.*]] = sext i16 %[[REAL]] to i32 |
| 317 |
// LLVM: %[[IMAG_INT_CAST:.*]] = sext i16 %[[IMAG]] to i32 |
| 318 |
// LLVM: %[[TMP:.*]] = insertvalue { i32, i32 } undef, i32 %[[REAL_INT_CAST]], 0 |
| 319 |
// LLVM: %[[COMPLEX:.*]] = insertvalue { i32, i32 } %[[TMP]], i32 %[[IMAG_INT_CAST]], 1 |
| 320 |
// LLVM: store { i32, i32 } %[[COMPLEX]], ptr {{.*}}, align 4 |
| 321 |
|
| 322 |
// OGCG: %[[REAL:.*]] = load i16, ptr {{.*}}, align 2 |
| 323 |
// OGCG: %[[IMAG:.*]] = load i16, ptr getelementptr inbounds nuw ({ i16, i16 }, ptr {{.*}}, i32 0, i32 1), align 2 |
| 324 |
// OGCG: %[[REAL_INT_CAST:.*]] = sext i16 %[[REAL]] to i32 |
| 325 |
// OGCG: %[[IMAG_INT_CAST:.*]] = sext i16 %[[IMAG]] to i32 |
| 326 |
// OGCG: store i32 %[[REAL_INT_CAST]], ptr {{.*}}, align 4 |
| 327 |
// OGCG: store i32 %[[IMAG_INT_CAST]], ptr getelementptr inbounds nuw ({ i32, i32 }, ptr {{.*}}, i32 0, i32 1), align 4 |
| 328 |
|
| 329 |
struct CX { |
| 330 |
double real; |
| 331 |
double imag; |
| 332 |
}; |
| 333 |
|
| 334 |
void lvalue_to_rvalue_bitcast() { |
| 335 |
CX a; |
| 336 |
double _Complex b = __builtin_bit_cast(double _Complex, a); |
| 337 |
} |
| 338 |
|
| 339 |
// CIR-BEFORE: %{{.*}} = cir.cast bitcast %{{.*}} : !cir.ptr<!rec_CX> -> !cir.ptr<!cir.complex<!cir.double>> |
| 340 |
|
| 341 |
// CIR-AFTER: %{{.*}} = cir.cast bitcast %{{.*}} : !cir.ptr<!rec_CX> -> !cir.ptr<!cir.complex<!cir.double>> |
| 342 |
|
| 343 |
// LLVM: %[[PTR_ADDR:.*]] = alloca %struct.CX, i64 1, align 8 |
| 344 |
// LLVM: %[[COMPLEX_ADDR:.*]] = alloca { double, double }, i64 1, align 8 |
| 345 |
// LLVM: %[[PTR_TO_COMPLEX:.*]] = load { double, double }, ptr %[[PTR_ADDR]], align 8 |
| 346 |
// LLVM: store { double, double } %[[PTR_TO_COMPLEX]], ptr %[[COMPLEX_ADDR]], align 8 |
| 347 |
|
| 348 |
// OGCG: %[[A_ADDR:.*]] = alloca %struct.CX, align 8 |
| 349 |
// OGCG: %[[B_ADDR:.*]] = alloca { double, double }, align 8 |
| 350 |
// OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[A_ADDR]], i32 0, i32 0 |
| 351 |
// OGCG: %[[A_REAL:.*]] = load double, ptr %[[A_REAL_PTR]], align 8 |
| 352 |
// OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[A_ADDR]], i32 0, i32 1 |
| 353 |
// OGCG: %[[A_IMAG:.*]] = load double, ptr %[[A_IMAG_PTR]], align 8 |
| 354 |
// OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[B_ADDR]], i32 0, i32 0 |
| 355 |
// OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[B_ADDR]], i32 0, i32 1 |
| 356 |
// OGCG: store double %[[A_REAL]], ptr %[[B_REAL_PTR]], align 8 |
| 357 |
// OGCG: store double %[[A_IMAG]], ptr %[[B_IMAG_PTR]], align 8 |
| 358 |
|
| 359 |
void lvalue_bitcast() { |
| 360 |
CX a; |
| 361 |
(double _Complex &)a = {}; |
| 362 |
} |
| 363 |
|
| 364 |
// CIR-BEFORE: %{{.*}} = cir.cast bitcast %{{.*}} : !cir.ptr<!rec_CX> -> !cir.ptr<!cir.complex<!cir.double>> |
| 365 |
|
| 366 |
// CIR-AFTER: %{{.*}} = cir.cast bitcast %{{.*}} : !cir.ptr<!rec_CX> -> !cir.ptr<!cir.complex<!cir.double>> |
| 367 |
|
| 368 |
// LLVM: %[[A_ADDR:.*]] = alloca %struct.CX, i64 1, align 8 |
| 369 |
// LLVM: store { double, double } zeroinitializer, ptr %[[A_ADDR]], align 8 |
| 370 |
|
| 371 |
// OGCG: %[[A_ADDR]] = alloca %struct.CX, align 8 |
| 372 |
// OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[A_ADDR]], i32 0, i32 0 |
| 373 |
// OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[A_ADDR]], i32 0, i32 1 |
| 374 |
// OGCG: store double 0.000000e+00, ptr %[[A_REAL_PTR]], align 8 |
| 375 |
// OGCG: store double 0.000000e+00, ptr %[[A_IMAG_PTR]], align 8 |