cast-ops-to-llvm.mlir
6.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// RUN: mlir-opt -convert-spirv-to-llvm %s | FileCheck %s
//===----------------------------------------------------------------------===//
// spv.Bitcast
//===----------------------------------------------------------------------===//
// CHECK-LABEL: @bitcast_float_to_integer_scalar
spv.func @bitcast_float_to_integer_scalar(%arg0 : f32) "None" {
// CHECK: llvm.bitcast {{.*}} : !llvm.float to !llvm.i32
%0 = spv.Bitcast %arg0: f32 to i32
spv.Return
}
// CHECK-LABEL: @bitcast_float_to_integer_vector
spv.func @bitcast_float_to_integer_vector(%arg0 : vector<3xf32>) "None" {
// CHECK: {{.*}} = llvm.bitcast {{.*}} : !llvm.vec<3 x float> to !llvm.vec<3 x i32>
%0 = spv.Bitcast %arg0: vector<3xf32> to vector<3xi32>
spv.Return
}
// CHECK-LABEL: @bitcast_vector_to_scalar
spv.func @bitcast_vector_to_scalar(%arg0 : vector<2xf32>) "None" {
// CHECK: {{.*}} = llvm.bitcast {{.*}} : !llvm.vec<2 x float> to !llvm.i64
%0 = spv.Bitcast %arg0: vector<2xf32> to i64
spv.Return
}
// CHECK-LABEL: @bitcast_scalar_to_vector
spv.func @bitcast_scalar_to_vector(%arg0 : f64) "None" {
// CHECK: {{.*}} = llvm.bitcast {{.*}} : !llvm.double to !llvm.vec<2 x i32>
%0 = spv.Bitcast %arg0: f64 to vector<2xi32>
spv.Return
}
// CHECK-LABEL: @bitcast_vector_to_vector
spv.func @bitcast_vector_to_vector(%arg0 : vector<4xf32>) "None" {
// CHECK: {{.*}} = llvm.bitcast {{.*}} : !llvm.vec<4 x float> to !llvm.vec<2 x i64>
%0 = spv.Bitcast %arg0: vector<4xf32> to vector<2xi64>
spv.Return
}
// CHECK-LABEL: @bitcast_pointer
spv.func @bitcast_pointer(%arg0: !spv.ptr<f32, Function>) "None" {
// CHECK: llvm.bitcast %{{.*}} : !llvm.ptr<float> to !llvm.ptr<i32>
%0 = spv.Bitcast %arg0 : !spv.ptr<f32, Function> to !spv.ptr<i32, Function>
spv.Return
}
//===----------------------------------------------------------------------===//
// spv.ConvertFToS
//===----------------------------------------------------------------------===//
// CHECK-LABEL: @convert_float_to_signed_scalar
spv.func @convert_float_to_signed_scalar(%arg0: f32) "None" {
// CHECK: llvm.fptosi %{{.*}} : !llvm.float to !llvm.i32
%0 = spv.ConvertFToS %arg0: f32 to i32
spv.Return
}
// CHECK-LABEL: @convert_float_to_signed_vector
spv.func @convert_float_to_signed_vector(%arg0: vector<2xf32>) "None" {
// CHECK: llvm.fptosi %{{.*}} : !llvm.vec<2 x float> to !llvm.vec<2 x i32>
%0 = spv.ConvertFToS %arg0: vector<2xf32> to vector<2xi32>
spv.Return
}
//===----------------------------------------------------------------------===//
// spv.ConvertFToU
//===----------------------------------------------------------------------===//
// CHECK-LABEL: @convert_float_to_unsigned_scalar
spv.func @convert_float_to_unsigned_scalar(%arg0: f32) "None" {
// CHECK: llvm.fptoui %{{.*}} : !llvm.float to !llvm.i32
%0 = spv.ConvertFToU %arg0: f32 to i32
spv.Return
}
// CHECK-LABEL: @convert_float_to_unsigned_vector
spv.func @convert_float_to_unsigned_vector(%arg0: vector<2xf32>) "None" {
// CHECK: llvm.fptoui %{{.*}} : !llvm.vec<2 x float> to !llvm.vec<2 x i32>
%0 = spv.ConvertFToU %arg0: vector<2xf32> to vector<2xi32>
spv.Return
}
//===----------------------------------------------------------------------===//
// spv.ConvertSToF
//===----------------------------------------------------------------------===//
// CHECK-LABEL: @convert_signed_to_float_scalar
spv.func @convert_signed_to_float_scalar(%arg0: i32) "None" {
// CHECK: llvm.sitofp %{{.*}} : !llvm.i32 to !llvm.float
%0 = spv.ConvertSToF %arg0: i32 to f32
spv.Return
}
// CHECK-LABEL: @convert_signed_to_float_vector
spv.func @convert_signed_to_float_vector(%arg0: vector<3xi32>) "None" {
// CHECK: llvm.sitofp %{{.*}} : !llvm.vec<3 x i32> to !llvm.vec<3 x float>
%0 = spv.ConvertSToF %arg0: vector<3xi32> to vector<3xf32>
spv.Return
}
//===----------------------------------------------------------------------===//
// spv.ConvertUToF
//===----------------------------------------------------------------------===//
// CHECK-LABEL: @convert_unsigned_to_float_scalar
spv.func @convert_unsigned_to_float_scalar(%arg0: i32) "None" {
// CHECK: llvm.uitofp %{{.*}} : !llvm.i32 to !llvm.float
%0 = spv.ConvertUToF %arg0: i32 to f32
spv.Return
}
// CHECK-LABEL: @convert_unsigned_to_float_vector
spv.func @convert_unsigned_to_float_vector(%arg0: vector<3xi32>) "None" {
// CHECK: llvm.uitofp %{{.*}} : !llvm.vec<3 x i32> to !llvm.vec<3 x float>
%0 = spv.ConvertUToF %arg0: vector<3xi32> to vector<3xf32>
spv.Return
}
//===----------------------------------------------------------------------===//
// spv.FConvert
//===----------------------------------------------------------------------===//
// CHECK-LABEL: @fconvert_scalar
spv.func @fconvert_scalar(%arg0: f32, %arg1: f64) "None" {
// CHECK: llvm.fpext %{{.*}} : !llvm.float to !llvm.double
%0 = spv.FConvert %arg0: f32 to f64
// CHECK: llvm.fptrunc %{{.*}} : !llvm.double to !llvm.float
%1 = spv.FConvert %arg1: f64 to f32
spv.Return
}
// CHECK-LABEL: @fconvert_vector
spv.func @fconvert_vector(%arg0: vector<2xf32>, %arg1: vector<2xf64>) "None" {
// CHECK: llvm.fpext %{{.*}} : !llvm.vec<2 x float> to !llvm.vec<2 x double>
%0 = spv.FConvert %arg0: vector<2xf32> to vector<2xf64>
// CHECK: llvm.fptrunc %{{.*}} : !llvm.vec<2 x double> to !llvm.vec<2 x float>
%1 = spv.FConvert %arg1: vector<2xf64> to vector<2xf32>
spv.Return
}
//===----------------------------------------------------------------------===//
// spv.SConvert
//===----------------------------------------------------------------------===//
// CHECK-LABEL: @sconvert_scalar
spv.func @sconvert_scalar(%arg0: i32, %arg1: i64) "None" {
// CHECK: llvm.sext %{{.*}} : !llvm.i32 to !llvm.i64
%0 = spv.SConvert %arg0: i32 to i64
// CHECK: llvm.trunc %{{.*}} : !llvm.i64 to !llvm.i32
%1 = spv.SConvert %arg1: i64 to i32
spv.Return
}
// CHECK-LABEL: @sconvert_vector
spv.func @sconvert_vector(%arg0: vector<3xi32>, %arg1: vector<3xi64>) "None" {
// CHECK: llvm.sext %{{.*}} : !llvm.vec<3 x i32> to !llvm.vec<3 x i64>
%0 = spv.SConvert %arg0: vector<3xi32> to vector<3xi64>
// CHECK: llvm.trunc %{{.*}} : !llvm.vec<3 x i64> to !llvm.vec<3 x i32>
%1 = spv.SConvert %arg1: vector<3xi64> to vector<3xi32>
spv.Return
}
//===----------------------------------------------------------------------===//
// spv.UConvert
//===----------------------------------------------------------------------===//
// CHECK-LABEL: @uconvert_scalar
spv.func @uconvert_scalar(%arg0: i32, %arg1: i64) "None" {
// CHECK: llvm.zext %{{.*}} : !llvm.i32 to !llvm.i64
%0 = spv.UConvert %arg0: i32 to i64
// CHECK: llvm.trunc %{{.*}} : !llvm.i64 to !llvm.i32
%1 = spv.UConvert %arg1: i64 to i32
spv.Return
}
// CHECK-LABEL: @uconvert_vector
spv.func @uconvert_vector(%arg0: vector<3xi32>, %arg1: vector<3xi64>) "None" {
// CHECK: llvm.zext %{{.*}} : !llvm.vec<3 x i32> to !llvm.vec<3 x i64>
%0 = spv.UConvert %arg0: vector<3xi32> to vector<3xi64>
// CHECK: llvm.trunc %{{.*}} : !llvm.vec<3 x i64> to !llvm.vec<3 x i32>
%1 = spv.UConvert %arg1: vector<3xi64> to vector<3xi32>
spv.Return
}