1// RUN: mlir-opt -convert-spirv-to-llvm %s | FileCheck %s 2 3//===----------------------------------------------------------------------===// 4// spv.CompositeExtract 5//===----------------------------------------------------------------------===// 6 7// CHECK-LABEL: @composite_extract_array 8spv.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 float>> 10 %0 = spv.CompositeExtract %arg[1 : i32, 3 : i32] : !spv.array<4x!spv.array<4xf32>> 11 spv.Return 12} 13 14// CHECK-LABEL: @composite_extract_vector 15spv.func @composite_extract_vector(%arg: vector<3xf32>) "None" { 16 // CHECK: %[[ZERO:.*]] = llvm.mlir.constant(0 : i32) : !llvm.i32 17 // CHECK: llvm.extractelement %{{.*}}[%[[ZERO]] : !llvm.i32] : !llvm.vec<3 x float> 18 %0 = spv.CompositeExtract %arg[0 : i32] : vector<3xf32> 19 spv.Return 20} 21 22//===----------------------------------------------------------------------===// 23// spv.CompositeInsert 24//===----------------------------------------------------------------------===// 25 26// CHECK-LABEL: @composite_insert_struct 27spv.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 (float, array<4 x i32>)> 29 %0 = spv.CompositeInsert %arg0, %arg1[1 : i32, 3 : i32] : i32 into !spv.struct<(f32, !spv.array<4xi32>)> 30 spv.Return 31} 32 33// CHECK-LABEL: @composite_insert_vector 34spv.func @composite_insert_vector(%arg0: vector<3xf32>, %arg1: f32) "None" { 35 // CHECK: %[[ONE:.*]] = llvm.mlir.constant(1 : i32) : !llvm.i32 36 // CHECK: llvm.insertelement %{{.*}}, %{{.*}}[%[[ONE]] : !llvm.i32] : !llvm.vec<3 x float> 37 %0 = spv.CompositeInsert %arg1, %arg0[1 : i32] : f32 into vector<3xf32> 38 spv.Return 39} 40 41//===----------------------------------------------------------------------===// 42// spv.Select 43//===----------------------------------------------------------------------===// 44 45// CHECK-LABEL: @select_scalar 46spv.func @select_scalar(%arg0: i1, %arg1: vector<3xi32>, %arg2: f32) "None" { 47 // CHECK: llvm.select %{{.*}}, %{{.*}}, %{{.*}} : !llvm.i1, !llvm.vec<3 x i32> 48 %0 = spv.Select %arg0, %arg1, %arg1 : i1, vector<3xi32> 49 // CHECK: llvm.select %{{.*}}, %{{.*}}, %{{.*}} : !llvm.i1, !llvm.float 50 %1 = spv.Select %arg0, %arg2, %arg2 : i1, f32 51 spv.Return 52} 53 54// CHECK-LABEL: @select_vector 55spv.func @select_vector(%arg0: vector<2xi1>, %arg1: vector<2xi32>) "None" { 56 // CHECK: llvm.select %{{.*}}, %{{.*}}, %{{.*}} : !llvm.vec<2 x i1>, !llvm.vec<2 x i32> 57 %0 = spv.Select %arg0, %arg1, %arg1 : vector<2xi1>, vector<2xi32> 58 spv.Return 59} 60 61//===----------------------------------------------------------------------===// 62// spv.EntryPoint and spv.ExecutionMode 63//===----------------------------------------------------------------------===// 64 65// CHECK: module { 66// CHECK-NEXT: llvm.mlir.global external constant @{{.*}}() : !llvm.struct<(i32)> { 67// CHECK-NEXT: %[[UNDEF:.*]] = llvm.mlir.undef : !llvm.struct<(i32)> 68// CHECK-NEXT: %[[VAL:.*]] = llvm.mlir.constant(31 : i32) : !llvm.i32 69// CHECK-NEXT: %[[RET:.*]] = llvm.insertvalue %[[VAL]], %[[UNDEF]][0 : i32] : !llvm.struct<(i32)> 70// CHECK-NEXT: llvm.return %[[RET]] : !llvm.struct<(i32)> 71// CHECK-NEXT: } 72// CHECK-NEXT: llvm.func @empty 73// CHECK-NEXT: llvm.return 74// CHECK-NEXT: } 75// CHECK-NEXT: } 76spv.module Logical OpenCL { 77 spv.func @empty() "None" { 78 spv.Return 79 } 80 spv.EntryPoint "Kernel" @empty 81 spv.ExecutionMode @empty "ContractionOff" 82} 83 84// CHECK: module { 85// CHECK-NEXT: llvm.mlir.global external constant @{{.*}}() : !llvm.struct<(i32, array<3 x i32>)> { 86// CHECK-NEXT: %[[UNDEF:.*]] = llvm.mlir.undef : !llvm.struct<(i32, array<3 x i32>)> 87// CHECK-NEXT: %[[EM:.*]] = llvm.mlir.constant(18 : i32) : !llvm.i32 88// CHECK-NEXT: %[[T0:.*]] = llvm.insertvalue %[[EM]], %[[UNDEF]][0 : i32] : !llvm.struct<(i32, array<3 x i32>)> 89// CHECK-NEXT: %[[C0:.*]] = llvm.mlir.constant(32 : i32) : !llvm.i32 90// CHECK-NEXT: %[[T1:.*]] = llvm.insertvalue %[[C0]], %[[T0]][1 : i32, 0 : i32] : !llvm.struct<(i32, array<3 x i32>)> 91// CHECK-NEXT: %[[C1:.*]] = llvm.mlir.constant(1 : i32) : !llvm.i32 92// CHECK-NEXT: %[[T2:.*]] = llvm.insertvalue %[[C1]], %[[T1]][1 : i32, 1 : i32] : !llvm.struct<(i32, array<3 x i32>)> 93// CHECK-NEXT: %[[C2:.*]] = llvm.mlir.constant(1 : i32) : !llvm.i32 94// CHECK-NEXT: %[[RET:.*]] = llvm.insertvalue %[[C2]], %[[T2]][1 : i32, 2 : i32] : !llvm.struct<(i32, array<3 x i32>)> 95// CHECK-NEXT: llvm.return %[[RET]] : !llvm.struct<(i32, array<3 x i32>)> 96// CHECK-NEXT: } 97// CHECK-NEXT: llvm.func @bar 98// CHECK-NEXT: llvm.return 99// CHECK-NEXT: } 100// CHECK-NEXT: } 101spv.module Logical OpenCL { 102 spv.func @bar() "None" { 103 spv.Return 104 } 105 spv.EntryPoint "Kernel" @bar 106 spv.ExecutionMode @bar "LocalSizeHint", 32, 1, 1 107} 108 109//===----------------------------------------------------------------------===// 110// spv.Undef 111//===----------------------------------------------------------------------===// 112 113// CHECK-LABEL: @undef_scalar 114spv.func @undef_scalar() "None" { 115 // CHECK: llvm.mlir.undef : !llvm.float 116 %0 = spv.undef : f32 117 spv.Return 118} 119 120// CHECK-LABEL: @undef_vector 121spv.func @undef_vector() "None" { 122 // CHECK: llvm.mlir.undef : !llvm.vec<2 x i32> 123 %0 = spv.undef : vector<2xi32> 124 spv.Return 125} 126