1 // RUN: fir-opt --target-rewrite="target=x86_64-unknown-linux-gnu" %s | FileCheck %s
2 // RUN: fir-opt --target-rewrite="target=loongarch64-unknown-linux-gnu" %s | FileCheck %s
4 // Test that we rewrite the signature and body of a func.function that returns a
6 func.func @returncomplex16() -> complex<f128> {
7 %1 = fir.undefined complex<f128>
8 %2 = arith.constant 2.0 : f128
9 %3 = fir.convert %2 : (f128) -> f128
10 %c0 = arith.constant 0 : i32
11 %4 = fir.insert_value %1, %3, [0 : i32] : (complex<f128>, f128) -> complex<f128>
12 %c1 = arith.constant 1 : i32
13 %5 = arith.constant -42.0 : f128
14 %6 = fir.insert_value %4, %5, [1 : i32] : (complex<f128>, f128) -> complex<f128>
15 return %6 : complex<f128>
18 // Test that we rewrite the signature of a func.function that accepts a complex<16>.
19 func.func private @paramcomplex16(complex<f128>) -> ()
21 // Test that we rewrite calls to func.functions that return or accept complex<16>.
22 func.func @callcomplex16() {
23 %1 = fir.call @returncomplex16() : () -> complex<f128>
24 fir.call @paramcomplex16(%1) : (complex<f128>) -> ()
28 // Test multiple complex<16> parameters and arguments
29 func.func private @calleemultipleparamscomplex16(complex<f128>, complex<f128>, complex<f128>) -> ()
31 func.func @multipleparamscomplex16(%z1 : complex<f128>, %z2 : complex<f128>, %z3 : complex<f128>) {
32 fir.call @calleemultipleparamscomplex16(%z1, %z2, %z3) : (complex<f128>, complex<f128>, complex<f128>) -> ()
36 // Test that we rewrite the signature of and calls to a func.function that accepts
37 // and returns MLIR complex<f128>.
38 func.func private @mlircomplexf128(%z1: complex<f128>, %z2: complex<f128>) -> complex<f128> {
39 %0 = fir.call @mlircomplexf128(%z1, %z2) : (complex<f128>, complex<f128>) -> complex<f128>
40 return %0 : complex<f128>
43 // Test that we rewrite the fir.address_of operator.
45 %r = fir.address_of(@returncomplex16) : () -> complex<f128>
46 %p = fir.address_of(@paramcomplex16) : (complex<f128>) -> ()
50 // CHECK-LABEL: func.func @returncomplex16(
51 // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<tuple<f128, f128>> {llvm.align = 16 : i32, llvm.sret = tuple<f128, f128>}) {
52 // CHECK: %[[VAL_1:.*]] = fir.undefined complex<f128>
53 // CHECK: %[[VAL_2:.*]] = arith.constant 2.000000e+00 : f128
54 // CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : (f128) -> f128
55 // CHECK: %[[VAL_4:.*]] = arith.constant 0 : i32
56 // CHECK: %[[VAL_5:.*]] = fir.insert_value %[[VAL_1]], %[[VAL_3]], [0 : i32] : (complex<f128>, f128) -> complex<f128>
57 // CHECK: %[[VAL_6:.*]] = arith.constant 1 : i32
58 // CHECK: %[[VAL_7:.*]] = arith.constant -4.200000e+01 : f128
59 // CHECK: %[[VAL_8:.*]] = fir.insert_value %[[VAL_5]], %[[VAL_7]], [1 : i32] : (complex<f128>, f128) -> complex<f128>
60 // CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<tuple<f128, f128>>) -> !fir.ref<complex<f128>>
61 // CHECK: fir.store %[[VAL_8]] to %[[VAL_9]] : !fir.ref<complex<f128>>
64 // CHECK: func.func private @paramcomplex16(!fir.ref<tuple<f128, f128>> {llvm.align = 16 : i32, llvm.byval = tuple<f128, f128>})
66 // CHECK-LABEL: func.func @callcomplex16() {
67 // CHECK: %[[VAL_0:.*]] = llvm.intr.stacksave : !llvm.ptr
68 // CHECK: %[[VAL_1:.*]] = fir.alloca tuple<f128, f128>
69 // CHECK: fir.call @returncomplex16(%[[VAL_1]]) : (!fir.ref<tuple<f128, f128>>) -> ()
70 // CHECK: %[[VAL_2:.*]] = fir.convert %[[VAL_1]] : (!fir.ref<tuple<f128, f128>>) -> !fir.ref<complex<f128>>
71 // CHECK: %[[VAL_3:.*]] = fir.load %[[VAL_2]] : !fir.ref<complex<f128>>
72 // CHECK: llvm.intr.stackrestore %[[VAL_0]] : !llvm.ptr
73 // CHECK: %[[VAL_4:.*]] = llvm.intr.stacksave : !llvm.ptr
74 // CHECK: %[[VAL_5:.*]] = fir.alloca complex<f128>
75 // CHECK: fir.store %[[VAL_3]] to %[[VAL_5]] : !fir.ref<complex<f128>>
76 // CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_5]] : (!fir.ref<complex<f128>>) -> !fir.ref<tuple<f128, f128>>
77 // CHECK: fir.call @paramcomplex16(%[[VAL_6]]) : (!fir.ref<tuple<f128, f128>>) -> ()
78 // CHECK: llvm.intr.stackrestore %[[VAL_4]] : !llvm.ptr
81 // CHECK: func.func private @calleemultipleparamscomplex16(!fir.ref<tuple<f128, f128>> {llvm.align = 16 : i32, llvm.byval = tuple<f128, f128>}, !fir.ref<tuple<f128, f128>> {llvm.align = 16 : i32, llvm.byval = tuple<f128, f128>}, !fir.ref<tuple<f128, f128>> {llvm.align = 16 : i32, llvm.byval = tuple<f128, f128>})
83 // CHECK-LABEL: func.func @multipleparamscomplex16(
84 // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<tuple<f128, f128>> {llvm.align = 16 : i32, llvm.byval = tuple<f128, f128>}, %[[VAL_1:.*]]: !fir.ref<tuple<f128, f128>> {llvm.align = 16 : i32, llvm.byval = tuple<f128, f128>}, %[[VAL_2:.*]]: !fir.ref<tuple<f128, f128>> {llvm.align = 16 : i32, llvm.byval = tuple<f128, f128>}) {
85 // CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : (!fir.ref<tuple<f128, f128>>) -> !fir.ref<complex<f128>>
86 // CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_3]] : !fir.ref<complex<f128>>
87 // CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_1]] : (!fir.ref<tuple<f128, f128>>) -> !fir.ref<complex<f128>>
88 // CHECK: %[[VAL_6:.*]] = fir.load %[[VAL_5]] : !fir.ref<complex<f128>>
89 // CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<tuple<f128, f128>>) -> !fir.ref<complex<f128>>
90 // CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_7]] : !fir.ref<complex<f128>>
91 // CHECK: %[[VAL_9:.*]] = llvm.intr.stacksave : !llvm.ptr
92 // CHECK: %[[VAL_10:.*]] = fir.alloca complex<f128>
93 // CHECK: fir.store %[[VAL_8]] to %[[VAL_10]] : !fir.ref<complex<f128>>
94 // CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_10]] : (!fir.ref<complex<f128>>) -> !fir.ref<tuple<f128, f128>>
95 // CHECK: %[[VAL_12:.*]] = fir.alloca complex<f128>
96 // CHECK: fir.store %[[VAL_6]] to %[[VAL_12]] : !fir.ref<complex<f128>>
97 // CHECK: %[[VAL_13:.*]] = fir.convert %[[VAL_12]] : (!fir.ref<complex<f128>>) -> !fir.ref<tuple<f128, f128>>
98 // CHECK: %[[VAL_14:.*]] = fir.alloca complex<f128>
99 // CHECK: fir.store %[[VAL_4]] to %[[VAL_14]] : !fir.ref<complex<f128>>
100 // CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_14]] : (!fir.ref<complex<f128>>) -> !fir.ref<tuple<f128, f128>>
101 // CHECK: fir.call @calleemultipleparamscomplex16(%[[VAL_11]], %[[VAL_13]], %[[VAL_15]]) : (!fir.ref<tuple<f128, f128>>, !fir.ref<tuple<f128, f128>>, !fir.ref<tuple<f128, f128>>) -> ()
102 // CHECK: llvm.intr.stackrestore %[[VAL_9]] : !llvm.ptr
106 // CHECK-LABEL: func.func private @mlircomplexf128(
107 // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<tuple<f128, f128>> {llvm.align = 16 : i32, llvm.sret = tuple<f128, f128>}, %[[VAL_1:.*]]: !fir.ref<tuple<f128, f128>> {llvm.align = 16 : i32, llvm.byval = tuple<f128, f128>}, %[[VAL_2:.*]]: !fir.ref<tuple<f128, f128>> {llvm.align = 16 : i32, llvm.byval = tuple<f128, f128>}) {
108 // CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : (!fir.ref<tuple<f128, f128>>) -> !fir.ref<complex<f128>>
109 // CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_3]] : !fir.ref<complex<f128>>
110 // CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_1]] : (!fir.ref<tuple<f128, f128>>) -> !fir.ref<complex<f128>>
111 // CHECK: %[[VAL_6:.*]] = fir.load %[[VAL_5]] : !fir.ref<complex<f128>>
112 // CHECK: %[[VAL_7:.*]] = llvm.intr.stacksave : !llvm.ptr
113 // CHECK: %[[VAL_8:.*]] = fir.alloca tuple<f128, f128>
114 // CHECK: %[[VAL_9:.*]] = fir.alloca complex<f128>
115 // CHECK: fir.store %[[VAL_6]] to %[[VAL_9]] : !fir.ref<complex<f128>>
116 // CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_9]] : (!fir.ref<complex<f128>>) -> !fir.ref<tuple<f128, f128>>
117 // CHECK: %[[VAL_11:.*]] = fir.alloca complex<f128>
118 // CHECK: fir.store %[[VAL_4]] to %[[VAL_11]] : !fir.ref<complex<f128>>
119 // CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_11]] : (!fir.ref<complex<f128>>) -> !fir.ref<tuple<f128, f128>>
120 // CHECK: fir.call @mlircomplexf128(%[[VAL_8]], %[[VAL_10]], %[[VAL_12]]) : (!fir.ref<tuple<f128, f128>>, !fir.ref<tuple<f128, f128>>, !fir.ref<tuple<f128, f128>>) -> ()
121 // CHECK: %[[VAL_13:.*]] = fir.convert %[[VAL_8]] : (!fir.ref<tuple<f128, f128>>) -> !fir.ref<complex<f128>>
122 // CHECK: %[[VAL_14:.*]] = fir.load %[[VAL_13]] : !fir.ref<complex<f128>>
123 // CHECK: llvm.intr.stackrestore %[[VAL_7]] : !llvm.ptr
124 // CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<tuple<f128, f128>>) -> !fir.ref<complex<f128>>
125 // CHECK: fir.store %[[VAL_14]] to %[[VAL_15]] : !fir.ref<complex<f128>>
129 // CHECK-LABEL: func.func @addrof() {
130 // CHECK: %[[VAL_0:.*]] = fir.address_of(@returncomplex16) : (!fir.ref<tuple<f128, f128>>) -> ()
131 // CHECK: %[[VAL_1:.*]] = fir.address_of(@paramcomplex16) : (!fir.ref<tuple<f128, f128>>) -> ()