1 // Test X86-64 passing ABI of struct in registers for the cases where the
2 // struct has more than one field.
3 // REQUIRES: x86-registered-target
4 // RUN: fir-opt -target-rewrite="target=x86_64-unknown-linux-gnu" %s -o - | FileCheck %s
7 module attributes {fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", llvm.target_triple = "x86_64-unknown-linux-gnu"} {
9 func.func @test_call_i8_a16(%0 : !fir.ref<!fir.type<ti8_a16{a:!fir.array<16xi8>}>>) {
10 %1 = fir.load %0 : !fir.ref<!fir.type<ti8_a16{a:!fir.array<16xi8>}>>
11 fir.call @test_func_i8_a16(%1) : (!fir.type<ti8_a16{a:!fir.array<16xi8>}>) -> ()
14 // CHECK-LABEL: func.func @test_call_i8_a16(
15 // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.type<ti8_a16{a:!fir.array<16xi8>}>>) {
16 // CHECK: %[[VAL_1:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.type<ti8_a16{a:!fir.array<16xi8>}>>
17 // CHECK: %[[VAL_2:.*]] = llvm.intr.stacksave : !llvm.ptr
18 // CHECK: %[[VAL_3:.*]] = fir.alloca tuple<i64, i64>
19 // CHECK: %[[VAL_4:.*]] = fir.convert %[[VAL_3]] : (!fir.ref<tuple<i64, i64>>) -> !fir.ref<!fir.type<ti8_a16{a:!fir.array<16xi8>}>>
20 // CHECK: fir.store %[[VAL_1]] to %[[VAL_4]] : !fir.ref<!fir.type<ti8_a16{a:!fir.array<16xi8>}>>
21 // CHECK: %[[VAL_5:.*]] = fir.load %[[VAL_3]] : !fir.ref<tuple<i64, i64>>
22 // CHECK: %[[VAL_6:.*]] = fir.extract_value %[[VAL_5]], [0 : i32] : (tuple<i64, i64>) -> i64
23 // CHECK: %[[VAL_7:.*]] = fir.extract_value %[[VAL_5]], [1 : i32] : (tuple<i64, i64>) -> i64
24 // CHECK: fir.call @test_func_i8_a16(%[[VAL_6]], %[[VAL_7]]) : (i64, i64) -> ()
25 // CHECK: llvm.intr.stackrestore %[[VAL_2]] : !llvm.ptr
28 func.func private @test_func_i8_a16(%0 : !fir.type<ti8_a16{a:!fir.array<16xi8>}>) -> () {
31 // CHECK-LABEL: func.func private @test_func_i8_a16(
32 // CHECK-SAME: %[[VAL_0:.*]]: i64,
33 // CHECK-SAME: %[[VAL_1:.*]]: i64) {
34 // CHECK: %[[VAL_2:.*]] = fir.undefined tuple<i64, i64>
35 // CHECK: %[[VAL_3:.*]] = fir.insert_value %[[VAL_2]], %[[VAL_0]], [0 : i32] : (tuple<i64, i64>, i64) -> tuple<i64, i64>
36 // CHECK: %[[VAL_4:.*]] = fir.insert_value %[[VAL_3]], %[[VAL_1]], [1 : i32] : (tuple<i64, i64>, i64) -> tuple<i64, i64>
37 // CHECK: %[[VAL_5:.*]] = fir.alloca tuple<i64, i64>
38 // CHECK: fir.store %[[VAL_4]] to %[[VAL_5]] : !fir.ref<tuple<i64, i64>>
39 // CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_5]] : (!fir.ref<tuple<i64, i64>>) -> !fir.ref<!fir.type<ti8_a16{a:!fir.array<16xi8>}>>
40 // CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_6]] : !fir.ref<!fir.type<ti8_a16{a:!fir.array<16xi8>}>>
44 // For the cases below, the argument marshalling logic is the same as above,
45 // so only the chosen signature is tested at the end.
47 func.func @test_call_i32_f32(%0 : !fir.ref<!fir.type<ti32_f32{i:i32,x:f32}>>) {
48 %1 = fir.load %0 : !fir.ref<!fir.type<ti32_f32{i:i32,x:f32}>>
49 fir.call @test_func_i32_f32(%1) : (!fir.type<ti32_f32{i:i32,x:f32}>) -> ()
52 func.func private @test_func_i32_f32(%0 : !fir.type<ti32_f32{i:i32,x:f32}>) -> () {
56 func.func @test_call_i32_i16(%0 : !fir.ref<!fir.type<ti32_i16{i:i32,x:i16}>>) {
57 %1 = fir.load %0 : !fir.ref<!fir.type<ti32_i16{i:i32,x:i16}>>
58 fir.call @test_func_i32_i16(%1) : (!fir.type<ti32_i16{i:i32,x:i16}>) -> ()
61 func.func private @test_func_i32_i16(%0 : !fir.type<ti32_i16{i:i32,x:i16}>) -> () {
65 func.func @test_call_f16_i16(%0 : !fir.ref<!fir.type<tf16_i16{i:f16,x:i16}>>) {
66 %1 = fir.load %0 : !fir.ref<!fir.type<tf16_i16{i:f16,x:i16}>>
67 fir.call @test_func_f16_i16(%1) : (!fir.type<tf16_i16{i:f16,x:i16}>) -> ()
70 func.func private @test_func_f16_i16(%0 : !fir.type<tf16_i16{i:f16,x:i16}>) -> () {
74 func.func @test_call_f16_f16(%0 : !fir.ref<!fir.type<tf16_f16{i:f16,x:f16}>>) {
75 %1 = fir.load %0 : !fir.ref<!fir.type<tf16_f16{i:f16,x:f16}>>
76 fir.call @test_func_f16_f16(%1) : (!fir.type<tf16_f16{i:f16,x:f16}>) -> ()
79 func.func private @test_func_f16_f16(%0 : !fir.type<tf16_f16{i:f16,x:f16}>) -> () {
83 func.func @test_call_i32_f64(%0 : !fir.ref<!fir.type<ti32_f64{i:i32,x:f64}>>) {
84 %1 = fir.load %0 : !fir.ref<!fir.type<ti32_f64{i:i32,x:f64}>>
85 fir.call @test_func_i32_f64(%1) : (!fir.type<ti32_f64{i:i32,x:f64}>) -> ()
88 func.func private @test_func_i32_f64(%0 : !fir.type<ti32_f64{i:i32,x:f64}>) -> () {
92 func.func @test_call_f64_f32(%0 : !fir.ref<!fir.type<tf64_f32{i:f64,x:f32}>>) {
93 %1 = fir.load %0 : !fir.ref<!fir.type<tf64_f32{i:f64,x:f32}>>
94 fir.call @test_func_f64_f32(%1) : (!fir.type<tf64_f32{i:f64,x:f32}>) -> ()
97 func.func private @test_func_f64_f32(%0 : !fir.type<tf64_f32{i:f64,x:f32}>) -> () {
101 func.func @test_call_f32_i32_f32_f32(%0 : !fir.ref<!fir.type<tf32_i32_f32_f32{i:i32,x:f32,y:f32,z:f32}>>) {
102 %1 = fir.load %0 : !fir.ref<!fir.type<tf32_i32_f32_f32{i:i32,x:f32,y:f32,z:f32}>>
103 fir.call @test_func_f32_i32_f32_f32(%1) : (!fir.type<tf32_i32_f32_f32{i:i32,x:f32,y:f32,z:f32}>) -> ()
106 func.func private @test_func_f32_i32_f32_f32(%0 : !fir.type<tf32_i32_f32_f32{i:i32,x:f32,y:f32,z:f32}>) -> () {
110 func.func @test_call_f64_i32(%before : i16, %0 : !fir.ref<!fir.type<tf64_i32{i:f64,x:i32}>>, %after : f128) {
111 %1 = fir.load %0 : !fir.ref<!fir.type<tf64_i32{i:f64,x:i32}>>
112 fir.call @test_func_f64_i32(%before, %1, %after) : (i16, !fir.type<tf64_i32{i:f64,x:i32}>, f128) -> ()
115 func.func private @test_func_f64_i32(%before : i16, %0 : !fir.type<tf64_i32{i:f64,x:i32}>, %after : f128) -> () {
120 // CHECK-LABEL: func.func @test_call_i32_f32(
121 // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.type<ti32_f32{i:i32,x:f32}>>) {
122 // CHECK-LABEL: func.func private @test_func_i32_f32(
123 // CHECK-SAME: %[[VAL_0:.*]]: i64) {
124 // CHECK-LABEL: func.func @test_call_i32_i16(
125 // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.type<ti32_i16{i:i32,x:i16}>>) {
126 // CHECK-LABEL: func.func private @test_func_i32_i16(
127 // CHECK-SAME: %[[VAL_0:.*]]: i64) {
128 // CHECK-LABEL: func.func @test_call_f16_i16(
129 // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.type<tf16_i16{i:f16,x:i16}>>) {
130 // CHECK-LABEL: func.func private @test_func_f16_i16(
131 // CHECK-SAME: %[[VAL_0:.*]]: i32) {
132 // CHECK-LABEL: func.func @test_call_f16_f16(
133 // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.type<tf16_f16{i:f16,x:f16}>>) {
134 // CHECK-LABEL: func.func private @test_func_f16_f16(
135 // CHECK-SAME: %[[VAL_0:.*]]: f32) {
136 // CHECK-LABEL: func.func @test_call_i32_f64(
137 // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.type<ti32_f64{i:i32,x:f64}>>) {
138 // CHECK-LABEL: func.func private @test_func_i32_f64(
139 // CHECK-SAME: %[[VAL_0:.*]]: i64,
140 // CHECK-SAME: %[[VAL_1:.*]]: f64) {
141 // CHECK-LABEL: func.func @test_call_f64_f32(
142 // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.type<tf64_f32{i:f64,x:f32}>>) {
143 // CHECK-LABEL: func.func private @test_func_f64_f32(
144 // CHECK-SAME: %[[VAL_0:.*]]: f64,
145 // CHECK-SAME: %[[VAL_1:.*]]: f32) {
146 // CHECK-LABEL: func.func @test_call_f32_i32_f32_f32(
147 // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.type<tf32_i32_f32_f32{i:i32,x:f32,y:f32,z:f32}>>) {
148 // CHECK-LABEL: func.func private @test_func_f32_i32_f32_f32(
149 // CHECK-SAME: %[[VAL_0:.*]]: i64,
150 // CHECK-SAME: %[[VAL_1:.*]]: f64) {
151 // CHECK-LABEL: func.func @test_call_f64_i32(
152 // CHECK-SAME: %[[VAL_0:.*]]: i16,
153 // CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.type<tf64_i32{i:f64,x:i32}>>,
154 // CHECK-SAME: %[[VAL_2:.*]]: f128) {
155 // CHECK-LABEL: func.func private @test_func_f64_i32(
156 // CHECK-SAME: %[[VAL_0:.*]]: i16,
157 // CHECK-SAME: %[[VAL_1:.*]]: f64,
158 // CHECK-SAME: %[[VAL_2:.*]]: i32,
159 // CHECK-SAME: %[[VAL_3:.*]]: f128) {