| 1 |
// RUN: %clang_cc1 -std=c++17 -triple x86_64-pc-linux-gnu -fclangir -emit-cir %s -o %t.cir |
| 2 |
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s |
| 3 |
// RUN: %clang_cc1 -std=c++17 -triple x86_64-pc-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll |
| 4 |
// RUN: FileCheck --check-prefix=LLVM --input-file=%t-cir.ll %s |
| 5 |
// RUN: %clang_cc1 -std=c++17 -triple x86_64-pc-linux-gnu -emit-llvm %s -o %t.ll |
| 6 |
// RUN: FileCheck --check-prefix=OGCG --input-file=%t.ll %s |
| 7 |
|
| 8 |
struct some_struct { |
| 9 |
int a; |
| 10 |
float b; |
| 11 |
}; |
| 12 |
|
| 13 |
float function() { |
| 14 |
auto[a, b] = some_struct{1, 2.f}; |
| 15 |
|
| 16 |
return a + b; |
| 17 |
} |
| 18 |
|
| 19 |
// CIR-LABEL: cir.func {{.*}} @_Z8functionv() -> !cir.float |
| 20 |
// CIR: %[[RETVAL:.+]] = cir.alloca !cir.float, !cir.ptr<!cir.float>, ["__retval"] |
| 21 |
// CIR: %[[STRUCT:.+]] = cir.alloca !rec_some_struct, !cir.ptr<!rec_some_struct>, ["", init] |
| 22 |
// CIR: %[[CONST:.+]] = cir.const #cir.const_record<{#cir.int<1> : !s32i, #cir.fp<2.000000e+00> : !cir.float}> : !rec_some_struct |
| 23 |
// CIR: cir.store{{.*}} %[[CONST]], %[[STRUCT]] |
| 24 |
// CIR: %[[MEMBER_A:.+]] = cir.get_member %[[STRUCT]][0] {name = "a"} : !cir.ptr<!rec_some_struct> -> !cir.ptr<!s32i> |
| 25 |
// CIR: %[[LOAD_A:.+]] = cir.load align(4) %[[MEMBER_A]] : !cir.ptr<!s32i>, !s32i |
| 26 |
// CIR: %[[CAST_A:.+]] = cir.cast int_to_float %[[LOAD_A]] : !s32i -> !cir.float |
| 27 |
// CIR: %[[MEMBER_B:.+]] = cir.get_member %[[STRUCT]][1] {name = "b"} : !cir.ptr<!rec_some_struct> -> !cir.ptr<!cir.float> |
| 28 |
// CIR: %[[LOAD_B:.+]] = cir.load align(4) %[[MEMBER_B]] : !cir.ptr<!cir.float>, !cir.float |
| 29 |
// CIR: %[[ADD:.+]] = cir.binop(add, %[[CAST_A]], %[[LOAD_B]]) : !cir.float |
| 30 |
// CIR: cir.store %[[ADD]], %[[RETVAL]] : !cir.float, !cir.ptr<!cir.float> |
| 31 |
// CIR: %[[RET:.+]] = cir.load %[[RETVAL]] : !cir.ptr<!cir.float>, !cir.float |
| 32 |
// CIR: cir.return %[[RET]] : !cir.float |
| 33 |
|
| 34 |
// LLVM-LABEL: define dso_local float @_Z8functionv() |
| 35 |
// LLVM: %[[RETVAL:.+]] = alloca float, i64 1 |
| 36 |
// LLVM: %[[STRUCT:.+]] = alloca %struct.some_struct, i64 1 |
| 37 |
// LLVM: store %struct.some_struct { i32 1, float 2.000000e+00 }, ptr %[[STRUCT]] |
| 38 |
// LLVM: %[[GEP_A:.+]] = getelementptr %struct.some_struct, ptr %[[STRUCT]], i32 0, i32 0 |
| 39 |
// LLVM: %[[LOAD_A:.+]] = load i32, ptr %[[GEP_A]] |
| 40 |
// LLVM: %[[CAST_A:.+]] = sitofp i32 %[[LOAD_A]] to float |
| 41 |
// LLVM: %[[GEP_B:.+]] = getelementptr %struct.some_struct, ptr %[[STRUCT]], i32 0, i32 1 |
| 42 |
// LLVM: %[[LOAD_B:.+]] = load float, ptr %[[GEP_B]] |
| 43 |
// LLVM: %[[ADD:.+]] = fadd float %[[CAST_A]], %[[LOAD_B]] |
| 44 |
// LLVM: store float %[[ADD]], ptr %[[RETVAL]] |
| 45 |
// LLVM: %[[RET:.+]] = load float, ptr %[[RETVAL]] |
| 46 |
// LLVM: ret float %[[RET]] |
| 47 |
|
| 48 |
// OGCG: @__const._Z8functionv.{{.*}} = private unnamed_addr constant %struct.some_struct { i32 1, float 2.000000e+00 } |
| 49 |
// OGCG-LABEL: define dso_local noundef float @_Z8functionv() |
| 50 |
// OGCG: %[[STRUCT:.+]] = alloca %struct.some_struct |
| 51 |
// OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[STRUCT]], ptr align 4 @__const._Z8functionv.{{.*}}, i64 8, i1 false) |
| 52 |
// OGCG: %[[GEP_A:.+]] = getelementptr inbounds nuw %struct.some_struct, ptr %[[STRUCT]], i32 0, i32 0 |
| 53 |
// OGCG: %[[LOAD_A:.+]] = load i32, ptr %[[GEP_A]] |
| 54 |
// OGCG: %[[CAST_A:.+]] = sitofp i32 %[[LOAD_A]] to float |
| 55 |
// OGCG: %[[GEP_B:.+]] = getelementptr inbounds nuw %struct.some_struct, ptr %[[STRUCT]], i32 0, i32 1 |
| 56 |
// OGCG: %[[LOAD_B:.+]] = load float, ptr %[[GEP_B]] |
| 57 |
// OGCG: %[[ADD:.+]] = fadd float %[[CAST_A]], %[[LOAD_B]] |
| 58 |
// OGCG: ret float %[[ADD]] |