1 // RUN: mlir-opt -convert-spirv-to-llvm %s | FileCheck %s
3 //===----------------------------------------------------------------------===//
4 // spirv.CompositeExtract
5 //===----------------------------------------------------------------------===//
7 // CHECK-LABEL: @composite_extract_array
8 spirv.func @composite_extract_array(%arg: !spirv.array<4x!spirv.array<4xf32>>) "None" {
9 // CHECK: llvm.extractvalue %{{.*}}[1, 3] : !llvm.array<4 x array<4 x f32>>
10 %0 = spirv.CompositeExtract %arg[1 : i32, 3 : i32] : !spirv.array<4x!spirv.array<4xf32>>
14 // CHECK-LABEL: @composite_extract_vector
15 spirv.func @composite_extract_vector(%arg: vector<3xf32>) "None" {
16 // CHECK: %[[ZERO:.*]] = llvm.mlir.constant(0 : i32) : i32
17 // CHECK: llvm.extractelement %{{.*}}[%[[ZERO]] : i32] : vector<3xf32>
18 %0 = spirv.CompositeExtract %arg[0 : i32] : vector<3xf32>
22 //===----------------------------------------------------------------------===//
23 // spirv.CompositeInsert
24 //===----------------------------------------------------------------------===//
26 // CHECK-LABEL: @composite_insert_struct
27 spirv.func @composite_insert_struct(%arg0: i32, %arg1: !spirv.struct<(f32, !spirv.array<4xi32>)>) "None" {
28 // CHECK: llvm.insertvalue %{{.*}}, %{{.*}}[1, 3] : !llvm.struct<packed (f32, array<4 x i32>)>
29 %0 = spirv.CompositeInsert %arg0, %arg1[1 : i32, 3 : i32] : i32 into !spirv.struct<(f32, !spirv.array<4xi32>)>
33 // CHECK-LABEL: @composite_insert_vector
34 spirv.func @composite_insert_vector(%arg0: vector<3xf32>, %arg1: f32) "None" {
35 // CHECK: %[[ONE:.*]] = llvm.mlir.constant(1 : i32) : i32
36 // CHECK: llvm.insertelement %{{.*}}, %{{.*}}[%[[ONE]] : i32] : vector<3xf32>
37 %0 = spirv.CompositeInsert %arg1, %arg0[1 : i32] : f32 into vector<3xf32>
41 //===----------------------------------------------------------------------===//
43 //===----------------------------------------------------------------------===//
45 // CHECK-LABEL: @select_scalar
46 spirv.func @select_scalar(%arg0: i1, %arg1: vector<3xi32>, %arg2: vector<3xi32>, %arg3: f32, %arg4: f32) "None" {
47 // CHECK: llvm.select %{{.*}}, %{{.*}}, %{{.*}} : i1, vector<3xi32>
48 %0 = spirv.Select %arg0, %arg1, %arg2 : i1, vector<3xi32>
49 // CHECK: llvm.select %{{.*}}, %{{.*}}, %{{.*}} : i1, f32
50 %1 = spirv.Select %arg0, %arg3, %arg4 : i1, f32
54 // CHECK-LABEL: @select_vector
55 spirv.func @select_vector(%arg0: vector<2xi1>, %arg1: vector<2xi32>, %arg2: vector<2xi32>) "None" {
56 // CHECK: llvm.select %{{.*}}, %{{.*}}, %{{.*}} : vector<2xi1>, vector<2xi32>
57 %0 = spirv.Select %arg0, %arg1, %arg2 : vector<2xi1>, vector<2xi32>
61 //===----------------------------------------------------------------------===//
62 // spirv.VectorShuffle
63 //===----------------------------------------------------------------------===//
65 spirv.func @vector_shuffle_same_size(%vector1: vector<2xf32>, %vector2: vector<2xf32>) -> vector<3xf32> "None" {
66 // CHECK: %[[res:.*]] = llvm.shufflevector {{.*}} [0, 2, -1] : vector<2xf32>
67 // CHECK-NEXT: return %[[res]] : vector<3xf32>
68 %0 = spirv.VectorShuffle [0: i32, 2: i32, 0xffffffff: i32] %vector1, %vector2 : vector<2xf32>, vector<2xf32> -> vector<3xf32>
69 spirv.ReturnValue %0: vector<3xf32>
72 spirv.func @vector_shuffle_different_size(%vector1: vector<3xf32>, %vector2: vector<2xf32>) -> vector<3xf32> "None" {
73 // CHECK: %[[UNDEF:.*]] = llvm.mlir.undef : vector<3xf32>
74 // CHECK-NEXT: %[[C0_0:.*]] = llvm.mlir.constant(0 : i32) : i32
75 // CHECK-NEXT: %[[C0_1:.*]] = llvm.mlir.constant(0 : i32) : i32
76 // CHECK-NEXT: %[[EXT0:.*]] = llvm.extractelement %arg0[%[[C0_1]] : i32] : vector<3xf32>
77 // CHECK-NEXT: %[[INSERT0:.*]] = llvm.insertelement %[[EXT0]], %[[UNDEF]][%[[C0_0]] : i32] : vector<3xf32>
78 // CHECK-NEXT: %[[C1_0:.*]] = llvm.mlir.constant(1 : i32) : i32
79 // CHECK-NEXT: %[[C1_1:.*]] = llvm.mlir.constant(1 : i32) : i32
80 // CHECK-NEXT: %[[EXT1:.*]] = llvm.extractelement {{.*}}[%[[C1_1]] : i32] : vector<2xf32>
81 // CHECK-NEXT: %[[RES:.*]] = llvm.insertelement %[[EXT1]], %[[INSERT0]][%[[C1_0]] : i32] : vector<3xf32>
82 // CHECK-NEXT: llvm.return %[[RES]] : vector<3xf32>
83 %0 = spirv.VectorShuffle [0: i32, 4: i32, 0xffffffff: i32] %vector1, %vector2 : vector<3xf32>, vector<2xf32> -> vector<3xf32>
84 spirv.ReturnValue %0: vector<3xf32>
87 //===----------------------------------------------------------------------===//
88 // spirv.EntryPoint and spirv.ExecutionMode
89 //===----------------------------------------------------------------------===//
92 // CHECK-NEXT: llvm.mlir.global external constant @{{.*}}() {addr_space = 0 : i32} : !llvm.struct<(i32)> {
93 // CHECK-NEXT: %[[UNDEF:.*]] = llvm.mlir.undef : !llvm.struct<(i32)>
94 // CHECK-NEXT: %[[VAL:.*]] = llvm.mlir.constant(31 : i32) : i32
95 // CHECK-NEXT: %[[RET:.*]] = llvm.insertvalue %[[VAL]], %[[UNDEF]][0] : !llvm.struct<(i32)>
96 // CHECK-NEXT: llvm.return %[[RET]] : !llvm.struct<(i32)>
98 // CHECK-NEXT: llvm.func @empty
99 // CHECK-NEXT: llvm.return
102 spirv.module Logical OpenCL {
103 spirv.func @empty() "None" {
106 spirv.EntryPoint "Kernel" @empty
107 spirv.ExecutionMode @empty "ContractionOff"
111 // CHECK-NEXT: llvm.mlir.global external constant @{{.*}}() {addr_space = 0 : i32} : !llvm.struct<(i32, array<3 x i32>)> {
112 // CHECK-NEXT: %[[UNDEF:.*]] = llvm.mlir.undef : !llvm.struct<(i32, array<3 x i32>)>
113 // CHECK-NEXT: %[[EM:.*]] = llvm.mlir.constant(18 : i32) : i32
114 // CHECK-NEXT: %[[T0:.*]] = llvm.insertvalue %[[EM]], %[[UNDEF]][0] : !llvm.struct<(i32, array<3 x i32>)>
115 // CHECK-NEXT: %[[C0:.*]] = llvm.mlir.constant(32 : i32) : i32
116 // CHECK-NEXT: %[[T1:.*]] = llvm.insertvalue %[[C0]], %[[T0]][1, 0] : !llvm.struct<(i32, array<3 x i32>)>
117 // CHECK-NEXT: %[[C1:.*]] = llvm.mlir.constant(1 : i32) : i32
118 // CHECK-NEXT: %[[T2:.*]] = llvm.insertvalue %[[C1]], %[[T1]][1, 1] : !llvm.struct<(i32, array<3 x i32>)>
119 // CHECK-NEXT: %[[C2:.*]] = llvm.mlir.constant(1 : i32) : i32
120 // CHECK-NEXT: %[[RET:.*]] = llvm.insertvalue %[[C2]], %[[T2]][1, 2] : !llvm.struct<(i32, array<3 x i32>)>
121 // CHECK-NEXT: llvm.return %[[RET]] : !llvm.struct<(i32, array<3 x i32>)>
123 // CHECK-NEXT: llvm.mlir.global external constant @{{.*}}() {addr_space = 0 : i32} : !llvm.struct<(i32)> {
124 // CHECK: llvm.func @bar
125 // CHECK-NEXT: llvm.return
128 spirv.module Logical OpenCL {
129 spirv.func @bar() "None" {
132 spirv.EntryPoint "Kernel" @bar
133 spirv.ExecutionMode @bar "ContractionOff"
134 spirv.ExecutionMode @bar "LocalSizeHint", 32, 1, 1
137 //===----------------------------------------------------------------------===//
139 //===----------------------------------------------------------------------===//
141 // CHECK-LABEL: @undef_scalar
142 spirv.func @undef_scalar() "None" {
143 // CHECK: llvm.mlir.undef : f32
144 %0 = spirv.Undef : f32
148 // CHECK-LABEL: @undef_vector
149 spirv.func @undef_vector() "None" {
150 // CHECK: llvm.mlir.undef : vector<2xi32>
151 %0 = spirv.Undef : vector<2xi32>