| 1 |
// RUN: %clang_cc1 -x c -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 -x c -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 -x c -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 foo2() { |
| 9 |
float _Complex a; |
| 10 |
float _Complex b; |
| 11 |
float _Complex c = a ?: b; |
| 12 |
} |
| 13 |
|
| 14 |
// CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["a"] |
| 15 |
// CIR: %[[B_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["b"] |
| 16 |
// CIR: %[[C_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["c", init] |
| 17 |
// CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[A_ADDR]] : !cir.ptr<!cir.complex<!cir.float>>, !cir.complex<!cir.float> |
| 18 |
// CIR: %[[A_REAL:.*]] = cir.complex.real %[[TMP_A]] : !cir.complex<!cir.float> -> !cir.float |
| 19 |
// CIR: %[[A_IMAG:.*]] = cir.complex.imag %[[TMP_A]] : !cir.complex<!cir.float> -> !cir.float |
| 20 |
// CIR: %[[A_REAL_BOOL:.*]] = cir.cast float_to_bool %[[A_REAL]] : !cir.float -> !cir.bool |
| 21 |
// CIR: %[[A_IMAG_BOOL:.*]] = cir.cast float_to_bool %[[A_IMAG]] : !cir.float -> !cir.bool |
| 22 |
// CIR: %[[CONST_TRUE:.*]] = cir.const #true |
| 23 |
// CIR: %[[COND:.*]] = cir.select if %[[A_REAL_BOOL]] then %[[CONST_TRUE]] else %[[A_IMAG_BOOL]] : (!cir.bool, !cir.bool, !cir.bool) -> !cir.bool |
| 24 |
// CIR: %[[RESULT:.*]] = cir.ternary(%[[COND]], true { |
| 25 |
// CIR: cir.yield %[[TMP_A]] : !cir.complex<!cir.float> |
| 26 |
// CIR: }, false { |
| 27 |
// CIR: %[[TMP_B:.*]] = cir.load{{.*}} %[[B_ADDR]] : !cir.ptr<!cir.complex<!cir.float>>, !cir.complex<!cir.float> |
| 28 |
// CIR: cir.yield %[[TMP_B]] : !cir.complex<!cir.float> |
| 29 |
// CIR: }) : (!cir.bool) -> !cir.complex<!cir.float> |
| 30 |
// CIR: cir.store{{.*}} %[[RESULT]], %[[C_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>> |
| 31 |
|
| 32 |
// LLVM: %[[A_ADDR:.*]] = alloca { float, float }, i64 1, align 4 |
| 33 |
// LLVM: %[[B_ADDR:.*]] = alloca { float, float }, i64 1, align 4 |
| 34 |
// LLVM: %[[C_ADDR:.*]] = alloca { float, float }, i64 1, align 4 |
| 35 |
// LLVM: %[[TMP_A:.*]] = load { float, float }, ptr %[[A_ADDR]], align 4 |
| 36 |
// LLVM: %[[A_REAL:.*]] = extractvalue { float, float } %[[TMP_A]], 0 |
| 37 |
// LLVM: %[[A_IMAG:.*]] = extractvalue { float, float } %[[TMP_A]], 1 |
| 38 |
// LLVM: %[[A_REAL_BOOL:.*]] = fcmp une float %[[A_REAL]], 0.000000e+00 |
| 39 |
// LLVM: %[[A_IMAG_BOOL:.*]] = fcmp une float %[[A_IMAG]], 0.000000e+00 |
| 40 |
// LLVM: %[[COND:.*]] = or i1 %[[A_REAL_BOOL]], %[[A_IMAG_BOOL]] |
| 41 |
// LLVM: br i1 %[[COND]], label %[[COND_TRUE:.*]], label %[[COND_FALSE:.*]] |
| 42 |
// LLVM: [[COND_TRUE]]: |
| 43 |
// LLVM: br label %[[COND_RESULT:.*]] |
| 44 |
// LLVM: [[COND_FALSE]]: |
| 45 |
// LLVM: %[[TMP_B:.*]] = load { float, float }, ptr %[[B_ADDR]], align 4 |
| 46 |
// LLVM: br label %[[COND_RESULT]] |
| 47 |
// LLVM: [[COND_RESULT]]: |
| 48 |
// LLVM: %[[RESULT:.*]] = phi { float, float } [ %[[TMP_B]], %[[COND_FALSE]] ], [ %[[TMP_A]], %[[COND_TRUE]] ] |
| 49 |
// LLVM: br label %[[COND_END:.*]] |
| 50 |
// LLVM: [[COND_END]]: |
| 51 |
// LLVM: store { float, float } %[[RESULT]], ptr %[[C_ADDR]], align 4 |
| 52 |
|
| 53 |
// OGCG: %[[A_ADDR:.*]] = alloca { float, float }, align 4 |
| 54 |
// OGCG: %[[B_ADDR:.*]] = alloca { float, float }, align 4 |
| 55 |
// OGCG: %[[C_ADDR:.*]] = alloca { float, float }, align 4 |
| 56 |
// OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 0 |
| 57 |
// OGCG: %[[A_REAL:.*]] = load float, ptr %[[A_REAL_PTR]], align 4 |
| 58 |
// OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 1 |
| 59 |
// OGCG: %[[A_IMAG:.*]] = load float, ptr %[[A_IMAG_PTR]], align 4 |
| 60 |
// OGCG: %[[A_REAL_BOOL:.*]] = fcmp une float %[[A_REAL]], 0.000000e+00 |
| 61 |
// OGCG: %[[A_IMAG_BOOL:.*]] = fcmp une float %[[A_IMAG]], 0.000000e+00 |
| 62 |
// OGCG: %[[COND:.*]] = or i1 %[[A_REAL_BOOL]], %[[A_IMAG_BOOL]] |
| 63 |
// OGCG: br i1 %tobool2, label %[[COND_TRUE:.*]], label %[[COND_FALSE:.*]] |
| 64 |
// OGCG: [[COND_TRUE]]: |
| 65 |
// OGCG: br label %[[COND_END:.*]] |
| 66 |
// OGCG: [[COND_FALSE]]: |
| 67 |
// OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[B_ADDR]], i32 0, i32 0 |
| 68 |
// OGCG: %[[B_REAL:.*]] = load float, ptr %[[B_REAL_PTR]], align 4 |
| 69 |
// OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[B_ADDR]], i32 0, i32 1 |
| 70 |
// OGCG: %[[B_IMAG:.*]] = load float, ptr %[[B_IMAG_PTR]], align 4 |
| 71 |
// OGCG: br label %[[COND_END]] |
| 72 |
// OGCG: [[COND_END]]: |
| 73 |
// OGCG: %[[RESULT_REAL:.*]] = phi float [ %[[A_REAL]], %[[COND_TRUE]] ], [ %[[B_REAL]], %[[COND_FALSE]] ] |
| 74 |
// OGCG: %[[RESULT_IMAG:.*]] = phi float [ %[[A_IMAG]], %[[COND_TRUE]] ], [ %[[B_IMAG]], %[[COND_FALSE]] ] |
| 75 |
// OGCG: %[[C_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[C_ADDR]], i32 0, i32 0 |
| 76 |
// OGCG: %[[C_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[C_ADDR]], i32 0, i32 1 |
| 77 |
// OGCG: store float %[[RESULT_REAL]], ptr %[[C_REAL_PTR]], align 4 |
| 78 |
// OGCG: store float %[[RESULT_IMAG]], ptr %[[C_IMAG_PTR]], align 4 |