|
| 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 | +void foo() { |
| 9 | + int _Complex a; |
| 10 | + int _Complex b = ~a; |
| 11 | +} |
| 12 | + |
| 13 | +// CIR-BEFORE: %[[COMPLEX:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["a"] |
| 14 | +// CIR-BEFORE: %[[RESULT:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["b", init] |
| 15 | +// CIR-BEFORE: %[[TMP:.*]] = cir.load{{.*}} %[[COMPLEX]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i> |
| 16 | +// CIR-BEFORE: %[[COMPLEX_NOT:.*]] = cir.unary(not, %[[TMP]]) : !cir.complex<!s32i>, !cir.complex<!s32i> |
| 17 | +// CIR-BEFORE: cir.store{{.*}} %[[COMPLEX_NOT]], %[[RESULT]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>> |
| 18 | + |
| 19 | +// CIR-AFTER: %[[COMPLEX:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["a"] |
| 20 | +// CIR-AFTER: %[[RESULT:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["b", init] |
| 21 | +// CIR-AFTER: %[[TMP:.*]] = cir.load{{.*}} %[[COMPLEX]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i> |
| 22 | +// CIR-AFTER: %[[REAL:.*]] = cir.complex.real %[[TMP]] : !cir.complex<!s32i> -> !s32i |
| 23 | +// CIR-AFTER: %[[IMAG:.*]] = cir.complex.imag %[[TMP]] : !cir.complex<!s32i> -> !s32i |
| 24 | +// CIR-AFTER: %[[IMAG_MINUS:.*]] = cir.unary(minus, %[[IMAG]]) : !s32i, !s32i |
| 25 | +// CIR-AFTER: %[[RESULT_VAL:.*]] = cir.complex.create %[[REAL]], %[[IMAG_MINUS]] : !s32i -> !cir.complex<!s32i> |
| 26 | +// CIR-AFTER: cir.store{{.*}} %[[RESULT_VAL]], %[[RESULT]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>> |
| 27 | + |
| 28 | +// LLVM: %[[COMPLEX:.*]] = alloca { i32, i32 }, i64 1, align 4 |
| 29 | +// LLVM: %[[RESULT:.*]] = alloca { i32, i32 }, i64 1, align 4 |
| 30 | +// LLVM: %[[TMP:.*]] = load { i32, i32 }, ptr %[[COMPLEX]], align 4 |
| 31 | +// LLVM: %[[REAL:.*]] = extractvalue { i32, i32 } %[[TMP]], 0 |
| 32 | +// LLVM: %[[IMAG:.*]] = extractvalue { i32, i32 } %[[TMP]], 1 |
| 33 | +// LLVM: %[[IMAG_MINUS:.*]] = sub i32 0, %[[IMAG]] |
| 34 | +// LLVM: %[[RESULT_TMP:.*]] = insertvalue { i32, i32 } {{.*}}, i32 %[[REAL]], 0 |
| 35 | +// LLVM: %[[RESULT_VAL:.*]] = insertvalue { i32, i32 } %[[RESULT_TMP]], i32 %[[IMAG_MINUS]], 1 |
| 36 | +// LLVM: store { i32, i32 } %[[RESULT_VAL]], ptr %[[RESULT]], align 4 |
| 37 | + |
| 38 | +// OGCG: %[[COMPLEX:.*]] = alloca { i32, i32 }, align 4 |
| 39 | +// OGCG: %[[RESULT:.*]] = alloca { i32, i32 }, align 4 |
| 40 | +// OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX]], i32 0, i32 0 |
| 41 | +// OGCG: %[[A_REAL:.*]] = load i32, ptr %[[A_REAL_PTR]], align 4 |
| 42 | +// OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX]], i32 0, i32 1 |
| 43 | +// OGCG: %[[A_IMAG:.*]] = load i32, ptr %[[A_IMAG_PTR]], align 4 |
| 44 | +// OGCG: %[[A_IMAG_MINUS:.*]] = sub i32 0, %[[A_IMAG]] |
| 45 | +// OGCG: %[[RESULT_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[RESULT]], i32 0, i32 0 |
| 46 | +// OGCG: %[[RESULT_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[RESULT]], i32 0, i32 1 |
| 47 | +// OGCG: store i32 %[[A_REAL]], ptr %[[RESULT_REAL_PTR]], align 4 |
| 48 | +// OGCG: store i32 %[[A_IMAG_MINUS]], ptr %[[RESULT_IMAG_PTR]], align 4 |
| 49 | + |
| 50 | +void foo2() { |
| 51 | + float _Complex a; |
| 52 | + float _Complex b = ~a; |
| 53 | +} |
| 54 | + |
| 55 | +// CIR-BEFORE: %[[COMPLEX:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["a"] |
| 56 | +// CIR-BEFORE: %[[RESULT:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["b", init] |
| 57 | +// CIR-BEFORE: %[[TMP:.*]] = cir.load{{.*}} %[[COMPLEX]] : !cir.ptr<!cir.complex<!cir.float>>, !cir.complex<!cir.float> |
| 58 | +// CIR-BEFORE: %[[COMPLEX_NOT:.*]] = cir.unary(not, %[[TMP]]) : !cir.complex<!cir.float>, !cir.complex<!cir.float> |
| 59 | +// CIR-BEFORE: cir.store{{.*}} %[[COMPLEX_NOT]], %[[RESULT]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>> |
| 60 | + |
| 61 | +// CIR-AFTER: %[[COMPLEX:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["a"] |
| 62 | +// CIR-AFTER: %[[RESULT:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["b", init] |
| 63 | +// CIR-AFTER: %[[TMP:.*]] = cir.load{{.*}} %[[COMPLEX]] : !cir.ptr<!cir.complex<!cir.float>>, !cir.complex<!cir.float> |
| 64 | +// CIR-AFTER: %[[REAL:.*]] = cir.complex.real %[[TMP]] : !cir.complex<!cir.float> -> !cir.float |
| 65 | +// CIR-AFTER: %[[IMAG:.*]] = cir.complex.imag %[[TMP]] : !cir.complex<!cir.float> -> !cir.float |
| 66 | +// CIR-AFTER: %[[IMAG_MINUS:.*]] = cir.unary(minus, %[[IMAG]]) : !cir.float, !cir.float |
| 67 | +// CIR-AFTER: %[[RESULT_VAL:.*]] = cir.complex.create %[[REAL]], %[[IMAG_MINUS]] : !cir.float -> !cir.complex<!cir.float> |
| 68 | +// CIR-AFTER: cir.store{{.*}} %[[RESULT_VAL]], %[[RESULT]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>> |
| 69 | + |
| 70 | +// LLVM: %[[COMPLEX:.*]] = alloca { float, float }, i64 1, align 4 |
| 71 | +// LLVM: %[[RESULT:.*]] = alloca { float, float }, i64 1, align 4 |
| 72 | +// LLVM: %[[TMP:.*]] = load { float, float }, ptr %[[COMPLEX]], align 4 |
| 73 | +// LLVM: %[[REAL:.*]] = extractvalue { float, float } %[[TMP]], 0 |
| 74 | +// LLVM: %[[IMAG:.*]] = extractvalue { float, float } %[[TMP]], 1 |
| 75 | +// LLVM: %[[IMAG_MINUS:.*]] = fneg float %[[IMAG]] |
| 76 | +// LLVM: %[[RESULT_TMP:.*]] = insertvalue { float, float } {{.*}}, float %[[REAL]], 0 |
| 77 | +// LLVM: %[[RESULT_VAL:.*]] = insertvalue { float, float } %[[RESULT_TMP]], float %[[IMAG_MINUS]], 1 |
| 78 | +// LLVM: store { float, float } %[[RESULT_VAL]], ptr %[[RESULT]], align 4 |
| 79 | + |
| 80 | +// OGCG: %[[COMPLEX:.*]] = alloca { float, float }, align 4 |
| 81 | +// OGCG: %[[RESULT:.*]] = alloca { float, float }, align 4 |
| 82 | +// OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[COMPLEX]], i32 0, i32 0 |
| 83 | +// OGCG: %[[A_REAL:.*]] = load float, ptr %[[A_REAL_PTR]], align 4 |
| 84 | +// OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[COMPLEX]], i32 0, i32 1 |
| 85 | +// OGCG: %[[A_IMAG:.*]] = load float, ptr %[[A_IMAG_PTR]], align 4 |
| 86 | +// OGCG: %[[A_IMAG_MINUS:.*]] = fneg float %[[A_IMAG]] |
| 87 | +// OGCG: %[[RESULT_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[RESULT]], i32 0, i32 0 |
| 88 | +// OGCG: %[[RESULT_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[RESULT]], i32 0, i32 1 |
| 89 | +// OGCG: store float %[[A_REAL]], ptr %[[RESULT_REAL_PTR]], align 4 |
| 90 | +// OGCG: store float %[[A_IMAG_MINUS]], ptr %[[RESULT_IMAG_PTR]], align 4 |
0 commit comments