llvm-project
149 строк · 6.3 Кб
1// RUN: fir-opt --split-input-file --fir-to-llvm-ir="target=x86_64-unknown-linux-gnu" %s | FileCheck %s --check-prefix INT64
2// RUN: fir-opt --split-input-file --fir-to-llvm-ir="target=aarch64-unknown-linux-gnu" %s | FileCheck %s --check-prefixes INT64
3// RUN: fir-opt --split-input-file --fir-to-llvm-ir="target=i386-unknown-linux-gnu" %s | FileCheck %s --check-prefixes INT32
4// RUN: fir-opt --split-input-file --fir-to-llvm-ir="target=powerpc64le-unknown-linux-gn" %s | FileCheck %s --check-prefixes INT64
5
6//=============================================================================
7// SUMMARY: Tests for FIR --> LLVM MLIR conversion that *depend* on the target
8//=============================================================================
9
10// Test fir.emboxchar
11
12func.func @test_embox(%char_array : !fir.ref<!fir.char<1,?>>) -> () {
13%c10 = arith.constant 10 : i64
14%box_char = fir.emboxchar %char_array, %c10 : (!fir.ref<!fir.char<1,?>>, i64) -> !fir.boxchar<1>
15return
16}
17
18// INT64-LABEL: test_embox
19// INT64-SAME: (%[[char_array:.*]]: !llvm.ptr)
20// INT64: %[[c10:.*]] = llvm.mlir.constant(10 : i64) : i64
21// INT64: %[[empty_struct:.*]] = llvm.mlir.undef : !llvm.struct<(ptr, i{{.*}})>
22// INT64: %[[struct_with_buffer:.*]] = llvm.insertvalue %[[char_array]], %[[empty_struct]][0] : !llvm.struct<(ptr, i{{.*}})>
23// INT64: %{{.*}} = llvm.insertvalue %[[c10]], %[[struct_with_buffer]][1] : !llvm.struct<(ptr, i{{.*}})>
24// INT64-NEXT: llvm.return
25
26// INT32-LABEL: llvm.func @test_embox
27// INT32-SAME: %[[char_array:.*]]: !llvm.ptr)
28// INT32: %[[c10:.*]] = llvm.mlir.constant(10 : i64) : i64
29// INT32: %[[empty_struct:.*]] = llvm.mlir.undef : !llvm.struct<(ptr, i32)>
30// INT32: %[[c10_truncated:.*]] = llvm.trunc %[[c10]] : i64 to i32
31// INT32: %[[struct_with_buffer:.*]] = llvm.insertvalue %[[char_array]], %[[empty_struct]][0] : !llvm.struct<(ptr, i32)>
32// INT32: %{{.*}} = llvm.insertvalue %[[c10_truncated:.*]], %[[struct_with_buffer]][1] : !llvm.struct<(ptr, i32)>
33// INT32-NEXT: llvm.return
34
35// -----
36
37// Test fir.unboxchar
38
39func.func @unboxchar_i8(%arg0 : !fir.boxchar<1>) -> () {
40%0:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1>>, i64)
41return
42}
43
44// INT64-LABEL: llvm.func @unboxchar_i8
45// INT64-SAME: %[[box_char:.*]]: !llvm.struct<(ptr, i64)>
46// INT64: %{{.*}} = llvm.extractvalue %[[box_char]][0] : !llvm.struct<(ptr, i64)>
47// INT64: %{{.*}} = llvm.extractvalue %[[box_char]][1] : !llvm.struct<(ptr, i64)>
48// INT64-NEXT: llvm.return
49
50// INT32-LABEL: llvm.func @unboxchar_i8
51// INT32-SAME: %[[box_char:.*]]: !llvm.struct<(ptr, i32)>
52// INT32: %{{.*}} = llvm.extractvalue %[[box_char]][0] : !llvm.struct<(ptr, i32)>
53// INT32: %[[len_unextended:.*]] = llvm.extractvalue %[[box_char]][1] : !llvm.struct<(ptr, i32)>
54// INT32: %{{.*}} = llvm.sext %[[len_unextended]] : i32 to i64
55// INT32-NEXT: llvm.return
56
57func.func @unboxchar_i32(%arg0 : !fir.boxchar<4>) -> () {
58fir.unboxchar %arg0 : (!fir.boxchar<4>) -> (!fir.ref<!fir.char<4>>, i64)
59return
60}
61
62// INT64-LABEL: llvm.func @unboxchar_i32
63// INT64-SAME: %[[box_char:.*]]: !llvm.struct<(ptr, i64)>
64// INT64: %{{.*}} = llvm.extractvalue %[[box_char]][0] : !llvm.struct<(ptr, i64)>
65// INT64: %{{.*}} = llvm.extractvalue %[[box_char]][1] : !llvm.struct<(ptr, i64)>
66// INT64-NEXT: llvm.return
67
68// INT32-LABEL: llvm.func @unboxchar_i32
69// INT32-SAME: %[[box_char:.*]]: !llvm.struct<(ptr, i32)>
70// INT32: %{{.*}} = llvm.extractvalue %[[box_char]][0] : !llvm.struct<(ptr, i32)>
71// INT32: %[[len_unextended:.*]] = llvm.extractvalue %[[box_char]][1] : !llvm.struct<(ptr, i32)>
72// INT32: %{{.*}} = llvm.sext %[[len_unextended]] : i32 to i64
73// INT32-NEXT: llvm.return
74
75// -----
76
77// Test fir.boxchar_len
78
79func.func @boxchar_len_i8_i32(%arg0 : !fir.boxchar<1>) -> () {
80fir.boxchar_len %arg0 : (!fir.boxchar<1>) -> i32
81return
82}
83
84// INT64-LABEL: llvm.func @boxchar_len_i8_i32
85// INT64-SAME: %[[box_char:.*]]: !llvm.struct<(ptr, i64)>
86// INT64: %[[len:.*]] = llvm.extractvalue %[[box_char]][1] : !llvm.struct<(ptr, i64)>
87// INT64: %{{.*}} = llvm.trunc %[[len]] : i64 to i32
88// INT64-NEXT: llvm.return
89
90// INT32-LABEL: llvm.func @boxchar_len_i8_i32
91// INT32-SAME: %[[box_char:.*]]: !llvm.struct<(ptr, i32)>
92// INT32: %{{.*}} = llvm.extractvalue %[[box_char]][1] : !llvm.struct<(ptr, i32)>
93// INT32-NOT: llvm.trunc
94// INT32-NOT: llvm.sext
95// INT32-NEXT: llvm.return
96
97func.func @boxchar_len_i8_i64(%arg0 : !fir.boxchar<1>) -> () {
98fir.boxchar_len %arg0 : (!fir.boxchar<1>) -> i64
99return
100}
101
102// INT64-LABEL: llvm.func @boxchar_len_i8_i64
103// INT64-SAME: %[[box_char:.*]]: !llvm.struct<(ptr, i64)>
104// INT64: %{{.*}} = llvm.extractvalue %[[box_char]][1] : !llvm.struct<(ptr, i64)>
105// INT64-NOT: llvm.trunc
106// INT64-NOT: llvm.sext
107// INT64-NEXT: llvm.return
108
109// INT32-LABEL: llvm.func @boxchar_len_i8_i64
110// INT32-SAME: %[[box_char:.*]]: !llvm.struct<(ptr, i32)>
111// INT32: %[[len:.*]] = llvm.extractvalue %[[box_char]][1] : !llvm.struct<(ptr, i32)>
112// INT32: %{{.*}} = llvm.sext %0 : i32 to i64
113// INT32-NEXT: llvm.return
114
115func.func @boxchar_len_i32_i32(%arg0 : !fir.boxchar<4>) -> () {
116fir.boxchar_len %arg0 : (!fir.boxchar<4>) -> i32
117return
118}
119
120// INT64-LABEL: llvm.func @boxchar_len_i32_i32
121// INT64-SAME: %[[box_char:.*]]: !llvm.struct<(ptr, i64)>
122// INT64: %[[len:.*]] = llvm.extractvalue %[[box_char]][1] : !llvm.struct<(ptr, i64)>
123// INT64: %{{.*}} = llvm.trunc %[[len]] : i64 to i32
124// INT64-NEXT: llvm.return
125
126// INT32-LABEL: llvm.func @boxchar_len_i32_i32
127// INT32-SAME: %[[box_char:.*]]: !llvm.struct<(ptr, i32)>
128// INT32: %{{.*}} = llvm.extractvalue %[[box_char]][1] : !llvm.struct<(ptr, i32)>
129// INT32-NOT: llvm.trunc
130// INT32-NOT: llvm.sext
131// INT32-NEXT: llvm.return
132
133func.func @boxchar_len_i32_i64(%arg0 : !fir.boxchar<4>) -> (i64) {
134%0 = fir.boxchar_len %arg0 : (!fir.boxchar<4>) -> i64
135return %0 : i64
136}
137
138// INT64-LABEL: llvm.func @boxchar_len_i32_i64
139// INT64-SAME: %[[box_char:.*]]: !llvm.struct<(ptr, i64)>
140// INT64: %{{.*}} = llvm.extractvalue %[[box_char]][1] : !llvm.struct<(ptr, i64)>
141// INT64-NOT: llvm.trunc
142// INT64-NOT: llvm.sext
143// INT64-NEXT: llvm.return
144
145// INT32-LABEL: llvm.func @boxchar_len_i32_i64
146// INT32-SAME: %[[box_char:.*]]: !llvm.struct<(ptr, i32)>
147// INT32: %[[len:.*]] = llvm.extractvalue %[[box_char]][1] : !llvm.struct<(ptr, i32)>
148// INT32: %{{.*}} = llvm.sext %0 : i32 to i64
149// INT32-NEXT: llvm.return
150