subview-to-spirv.mlir
2.87 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
// RUN: mlir-opt -legalize-std-for-spirv -convert-std-to-spirv %s -o - | FileCheck %s
// TODO: For these examples running these passes separately produces
// the desired output. Adding all of patterns within a single pass does
// not seem to work.
//===----------------------------------------------------------------------===//
// std.subview
//===----------------------------------------------------------------------===//
// CHECK-LABEL: @fold_static_stride_subview_with_load
// CHECK-SAME: [[ARG0:%.*]]: !spv.ptr<!spv.struct<!spv.array<384 x f32 [4]> [0]>, StorageBuffer>, [[ARG1:%.*]]: i32, [[ARG2:%.*]]: i32, [[ARG3:%.*]]: i32, [[ARG4:%.*]]: i32
func @fold_static_stride_subview_with_load(%arg0 : memref<12x32xf32>, %arg1 : index, %arg2 : index, %arg3 : index, %arg4 : index) {
// CHECK: [[C2:%.*]] = spv.constant 2
// CHECK: [[C3:%.*]] = spv.constant 3
// CHECK: [[T2:%.*]] = spv.IMul [[ARG3]], [[C2]]
// CHECK: [[T3:%.*]] = spv.IAdd [[ARG1]], [[T2]]
// CHECK: [[T4:%.*]] = spv.IMul [[ARG4]], [[C3]]
// CHECK: [[T5:%.*]] = spv.IAdd [[ARG2]], [[T4]]
// CHECK: [[C32:%.*]] = spv.constant 32
// CHECK: [[T7:%.*]] = spv.IMul [[C32]], [[T3]]
// CHECK: [[C1:%.*]] = spv.constant 1
// CHECK: [[T9:%.*]] = spv.IMul [[C1]], [[T5]]
// CHECK: [[T10:%.*]] = spv.IAdd [[T7]], [[T9]]
// CHECK: [[C0:%.*]] = spv.constant 0
// CHECK: [[T12:%.*]] = spv.AccessChain [[ARG0]]{{\[}}[[C0]], [[T10]]
// CHECK: spv.Load "StorageBuffer" [[T12]] : f32
%0 = subview %arg0[%arg1, %arg2][][] : memref<12x32xf32> to memref<4x4xf32, offset:?, strides: [64, 3]>
%1 = load %0[%arg3, %arg4] : memref<4x4xf32, offset:?, strides: [64, 3]>
return
}
// CHECK-LABEL: @fold_static_stride_subview_with_store
// CHECK-SAME: [[ARG0:%.*]]: !spv.ptr<!spv.struct<!spv.array<384 x f32 [4]> [0]>, StorageBuffer>, [[ARG1:%.*]]: i32, [[ARG2:%.*]]: i32, [[ARG3:%.*]]: i32, [[ARG4:%.*]]: i32, [[ARG5:%.*]]: f32
func @fold_static_stride_subview_with_store(%arg0 : memref<12x32xf32>, %arg1 : index, %arg2 : index, %arg3 : index, %arg4 : index, %arg5 : f32) {
// CHECK: [[C2:%.*]] = spv.constant 2
// CHECK: [[C3:%.*]] = spv.constant 3
// CHECK: [[T2:%.*]] = spv.IMul [[ARG3]], [[C2]]
// CHECK: [[T3:%.*]] = spv.IAdd [[ARG1]], [[T2]]
// CHECK: [[T4:%.*]] = spv.IMul [[ARG4]], [[C3]]
// CHECK: [[T5:%.*]] = spv.IAdd [[ARG2]], [[T4]]
// CHECK: [[C32:%.*]] = spv.constant 32
// CHECK: [[T7:%.*]] = spv.IMul [[C32]], [[T3]]
// CHECK: [[C1:%.*]] = spv.constant 1
// CHECK: [[T9:%.*]] = spv.IMul [[C1]], [[T5]]
// CHECK: [[T10:%.*]] = spv.IAdd [[T7]], [[T9]]
// CHECK: [[C0:%.*]] = spv.constant 0
// CHECK: [[T12:%.*]] = spv.AccessChain [[ARG0]]{{\[}}[[C0]], [[T10]]
// CHECK: spv.Store "StorageBuffer" [[T12]], [[ARG5]] : f32
%0 = subview %arg0[%arg1, %arg2][][] : memref<12x32xf32> to memref<4x4xf32, offset:?, strides: [64, 3]>
store %arg5, %0[%arg3, %arg4] : memref<4x4xf32, offset:?, strides: [64, 3]>
return
}