|
| 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 dso_local @_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>, [""] |
| 22 | +// CIR: %[[MEMBER_A:.+]] = cir.get_member %[[STRUCT]][0] {name = "a"} : !cir.ptr<!rec_some_struct> -> !cir.ptr<!s32i> |
| 23 | +// CIR: %[[LOAD_A:.+]] = cir.load align(4) %[[MEMBER_A]] : !cir.ptr<!s32i>, !s32i |
| 24 | +// CIR: %[[CAST_A:.+]] = cir.cast(int_to_float, %[[LOAD_A]] : !s32i), !cir.float |
| 25 | +// CIR: %[[MEMBER_B:.+]] = cir.get_member %[[STRUCT]][1] {name = "b"} : !cir.ptr<!rec_some_struct> -> !cir.ptr<!cir.float> |
| 26 | +// CIR: %[[LOAD_B:.+]] = cir.load align(4) %[[MEMBER_B]] : !cir.ptr<!cir.float>, !cir.float |
| 27 | +// CIR: %[[ADD:.+]] = cir.binop(add, %[[CAST_A]], %[[LOAD_B]]) : !cir.float |
| 28 | +// CIR: cir.store %[[ADD]], %[[RETVAL]] : !cir.float, !cir.ptr<!cir.float> |
| 29 | +// CIR: %[[RET:.+]] = cir.load %[[RETVAL]] : !cir.ptr<!cir.float>, !cir.float |
| 30 | +// CIR: cir.return %[[RET]] : !cir.float |
| 31 | + |
| 32 | +// LLVM-LABEL: define dso_local float @_Z8functionv() |
| 33 | +// LLVM: %[[RETVAL:.+]] = alloca float, i64 1 |
| 34 | +// LLVM: %[[STRUCT:.+]] = alloca %struct.some_struct, i64 1 |
| 35 | +// LLVM: %[[GEP_A:.+]] = getelementptr %struct.some_struct, ptr %[[STRUCT]], i32 0, i32 0 |
| 36 | +// LLVM: %[[LOAD_A:.+]] = load i32, ptr %[[GEP_A]] |
| 37 | +// LLVM: %[[CAST_A:.+]] = sitofp i32 %[[LOAD_A]] to float |
| 38 | +// LLVM: %[[GEP_B:.+]] = getelementptr %struct.some_struct, ptr %[[STRUCT]], i32 0, i32 1 |
| 39 | +// LLVM: %[[LOAD_B:.+]] = load float, ptr %[[GEP_B]] |
| 40 | +// LLVM: %[[ADD:.+]] = fadd float %[[CAST_A]], %[[LOAD_B]] |
| 41 | +// LLVM: store float %[[ADD]], ptr %[[RETVAL]] |
| 42 | +// LLVM: %[[RET:.+]] = load float, ptr %[[RETVAL]] |
| 43 | +// LLVM: ret float %[[RET]] |
| 44 | + |
| 45 | +// OGCG: @__const._Z8functionv.{{.*}} = private unnamed_addr constant %struct.some_struct { i32 1, float 2.000000e+00 } |
| 46 | +// OGCG-LABEL: define dso_local noundef float @_Z8functionv() |
| 47 | +// OGCG: %[[STRUCT:.+]] = alloca %struct.some_struct |
| 48 | +// OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[STRUCT]], ptr align 4 @__const._Z8functionv.{{.*}}, i64 8, i1 false) |
| 49 | +// OGCG: %[[GEP_A:.+]] = getelementptr inbounds nuw %struct.some_struct, ptr %[[STRUCT]], i32 0, i32 0 |
| 50 | +// OGCG: %[[LOAD_A:.+]] = load i32, ptr %[[GEP_A]] |
| 51 | +// OGCG: %[[CAST_A:.+]] = sitofp i32 %[[LOAD_A]] to float |
| 52 | +// OGCG: %[[GEP_B:.+]] = getelementptr inbounds nuw %struct.some_struct, ptr %[[STRUCT]], i32 0, i32 1 |
| 53 | +// OGCG: %[[LOAD_B:.+]] = load float, ptr %[[GEP_B]] |
| 54 | +// OGCG: %[[ADD:.+]] = fadd float %[[CAST_A]], %[[LOAD_B]] |
| 55 | +// OGCG: ret float %[[ADD]] |
0 commit comments