1 // RUN: mlir-opt -convert-spirv-to-llvm %s | FileCheck %s
3 //===----------------------------------------------------------------------===//
4 // spv.CompositeExtract
5 //===----------------------------------------------------------------------===//
7 // CHECK-LABEL: @composite_extract_array
8 spv.func @composite_extract_array(%arg: !spv.array<4x!spv.array<4xf32>>) "None" {
9 // CHECK: llvm.extractvalue %{{.*}}[1 : i32, 3 : i32] : !llvm.array<4 x array<4 x f32>>
10 %0 = spv.CompositeExtract %arg[1 : i32, 3 : i32] : !spv.array<4x!spv.array<4xf32>>
14 // CHECK-LABEL: @composite_extract_vector
15 spv.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 = spv.CompositeExtract %arg[0 : i32] : vector<3xf32>
22 //===----------------------------------------------------------------------===//
23 // spv.CompositeInsert
24 //===----------------------------------------------------------------------===//
26 // CHECK-LABEL: @composite_insert_struct
27 spv.func @composite_insert_struct(%arg0: i32, %arg1: !spv.struct<(f32, !spv.array<4xi32>)>) "None" {
28 // CHECK: llvm.insertvalue %{{.*}}, %{{.*}}[1 : i32, 3 : i32] : !llvm.struct<packed (f32, array<4 x i32>)>
29 %0 = spv.CompositeInsert %arg0, %arg1[1 : i32, 3 : i32] : i32 into !spv.struct<(f32, !spv.array<4xi32>)>
33 // CHECK-LABEL: @composite_insert_vector
34 spv.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 = spv.CompositeInsert %arg1, %arg0[1 : i32] : f32 into vector<3xf32>
41 //===----------------------------------------------------------------------===//
43 //===----------------------------------------------------------------------===//
45 // CHECK-LABEL: @select_scalar
46 spv.func @select_scalar(%arg0: i1, %arg1: vector<3xi32>, %arg2: f32) "None" {
47 // CHECK: llvm.select %{{.*}}, %{{.*}}, %{{.*}} : i1, vector<3xi32>
48 %0 = spv.Select %arg0, %arg1, %arg1 : i1, vector<3xi32>
49 // CHECK: llvm.select %{{.*}}, %{{.*}}, %{{.*}} : i1, f32
50 %1 = spv.Select %arg0, %arg2, %arg2 : i1, f32
54 // CHECK-LABEL: @select_vector
55 spv.func @select_vector(%arg0: vector<2xi1>, %arg1: vector<2xi32>) "None" {
56 // CHECK: llvm.select %{{.*}}, %{{.*}}, %{{.*}} : vector<2xi1>, vector<2xi32>
57 %0 = spv.Select %arg0, %arg1, %arg1 : vector<2xi1>, vector<2xi32>
61 //===----------------------------------------------------------------------===//
63 //===----------------------------------------------------------------------===//
65 spv.func @vector_shuffle_same_size(%vector1: vector<2xf32>, %vector2: vector<2xf32>) -> vector<3xf32> "None" {
66 // CHECK: %[[res:.*]] = llvm.shufflevector {{.*}} [0 : i32, 2 : i32, -1 : i32] : vector<2xf32>, vector<2xf32>
67 // CHECK-NEXT: return %[[res]] : vector<3xf32>
68 %0 = spv.VectorShuffle [0: i32, 2: i32, 0xffffffff: i32] %vector1: vector<2xf32>, %vector2: vector<2xf32> -> vector<3xf32>
69 spv.ReturnValue %0: vector<3xf32>
72 spv.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 = spv.VectorShuffle [0: i32, 4: i32, 0xffffffff: i32] %vector1: vector<3xf32>, %vector2: vector<2xf32> -> vector<3xf32>
84 spv.ReturnValue %0: vector<3xf32>
87 //===----------------------------------------------------------------------===//
88 // spv.EntryPoint and spv.ExecutionMode
89 //===----------------------------------------------------------------------===//
92 // CHECK-NEXT: llvm.mlir.global external constant @{{.*}}() : !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 : i32] : !llvm.struct<(i32)>
96 // CHECK-NEXT: llvm.return %[[RET]] : !llvm.struct<(i32)>
98 // CHECK-NEXT: llvm.func @empty
99 // CHECK-NEXT: llvm.return
102 spv.module Logical OpenCL {
103 spv.func @empty() "None" {
106 spv.EntryPoint "Kernel" @empty
107 spv.ExecutionMode @empty "ContractionOff"
111 // CHECK-NEXT: llvm.mlir.global external constant @{{.*}}() : !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 : i32] : !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 : i32, 0 : i32] : !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 : i32, 1 : i32] : !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 : i32, 2 : i32] : !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 @{{.*}}() : !llvm.struct<(i32)> {
124 // CHECK: llvm.func @bar
125 // CHECK-NEXT: llvm.return
128 spv.module Logical OpenCL {
129 spv.func @bar() "None" {
132 spv.EntryPoint "Kernel" @bar
133 spv.ExecutionMode @bar "ContractionOff"
134 spv.ExecutionMode @bar "LocalSizeHint", 32, 1, 1
137 //===----------------------------------------------------------------------===//
139 //===----------------------------------------------------------------------===//
141 // CHECK-LABEL: @undef_scalar
142 spv.func @undef_scalar() "None" {
143 // CHECK: llvm.mlir.undef : f32
148 // CHECK-LABEL: @undef_vector
149 spv.func @undef_vector() "None" {
150 // CHECK: llvm.mlir.undef : vector<2xi32>
151 %0 = spv.Undef : vector<2xi32>