xref: /llvm-project/mlir/test/Conversion/SPIRVToLLVM/constant-op-to-llvm.mlir (revision 41f3b83fb066b4c3273e9abe02a8630864f22f30)
1// RUN: mlir-opt -convert-spirv-to-llvm %s | FileCheck %s
2
3//===----------------------------------------------------------------------===//
4// spirv.Constant
5//===----------------------------------------------------------------------===//
6
7// CHECK-LABEL: @bool_constant_scalar
8spirv.func @bool_constant_scalar() "None" {
9  // CHECK: llvm.mlir.constant(true) : i1
10  %0 = spirv.Constant true
11  // CHECK: llvm.mlir.constant(false) : i1
12  %1 = spirv.Constant false
13  spirv.Return
14}
15
16// CHECK-LABEL: @bool_constant_vector
17spirv.func @bool_constant_vector() "None" {
18  // CHECK: llvm.mlir.constant(dense<[true, false]> : vector<2xi1>) : vector<2xi1>
19  %0 = spirv.Constant dense<[true, false]> : vector<2xi1>
20  // CHECK: llvm.mlir.constant(dense<false> : vector<3xi1>) : vector<3xi1>
21  %1 = spirv.Constant dense<false> : vector<3xi1>
22  spirv.Return
23}
24
25// CHECK-LABEL: @integer_constant_scalar
26spirv.func @integer_constant_scalar() "None" {
27  // CHECK: llvm.mlir.constant(0 : i8) : i8
28  %0 = spirv.Constant  0 : i8
29  // CHECK: llvm.mlir.constant(-5 : i64) : i64
30  %1 = spirv.Constant -5 : si64
31  // CHECK: llvm.mlir.constant(10 : i16) : i16
32  %2 = spirv.Constant  10 : ui16
33  spirv.Return
34}
35
36// CHECK-LABEL: @integer_constant_vector
37spirv.func @integer_constant_vector() "None" {
38  // CHECK: llvm.mlir.constant(dense<[2, 3]> : vector<2xi32>) : vector<2xi32>
39  %0 = spirv.Constant dense<[2, 3]> : vector<2xi32>
40  // CHECK: llvm.mlir.constant(dense<-4> : vector<2xi32>) : vector<2xi32>
41  %1 = spirv.Constant dense<-4> : vector<2xsi32>
42  // CHECK: llvm.mlir.constant(dense<[2, 3, 4]> : vector<3xi32>) : vector<3xi32>
43  %2 = spirv.Constant dense<[2, 3, 4]> : vector<3xui32>
44  spirv.Return
45}
46
47// CHECK-LABEL: @float_constant_scalar
48spirv.func @float_constant_scalar() "None" {
49  // CHECK: llvm.mlir.constant(5.000000e+00 : f16) : f16
50  %0 = spirv.Constant 5.000000e+00 : f16
51  // CHECK: llvm.mlir.constant(5.000000e+00 : f64) : f64
52  %1 = spirv.Constant 5.000000e+00 : f64
53  spirv.Return
54}
55
56// CHECK-LABEL: @float_constant_vector
57spirv.func @float_constant_vector() "None" {
58  // CHECK: llvm.mlir.constant(dense<[2.000000e+00, 3.000000e+00]> : vector<2xf32>) : vector<2xf32>
59  %0 = spirv.Constant dense<[2.000000e+00, 3.000000e+00]> : vector<2xf32>
60  spirv.Return
61}
62