comparison mlir/test/Conversion/StandardToSPIRV/subview-to-spirv.mlir @ 150:1d019706d866

LLVM10
author anatofuz
date Thu, 13 Feb 2020 15:10:13 +0900
parents
children 0572611fdcc8
comparison
equal deleted inserted replaced
147:c2174574ed3a 150:1d019706d866
1 // RUN: mlir-opt -legalize-std-for-spirv -convert-std-to-spirv %s -o - | FileCheck %s
2
3 // TODO: For these examples running these passes separately produces
4 // the desired output. Adding all of patterns within a single pass does
5 // not seem to work.
6
7 //===----------------------------------------------------------------------===//
8 // std.subview
9 //===----------------------------------------------------------------------===//
10
11 // CHECK-LABEL: @fold_static_stride_subview_with_load
12 // CHECK-SAME: [[ARG0:%.*]]: !spv.ptr<!spv.struct<!spv.array<384 x f32 [4]> [0]>, StorageBuffer>, [[ARG1:%.*]]: i32, [[ARG2:%.*]]: i32, [[ARG3:%.*]]: i32, [[ARG4:%.*]]: i32
13 func @fold_static_stride_subview_with_load(%arg0 : memref<12x32xf32>, %arg1 : index, %arg2 : index, %arg3 : index, %arg4 : index) {
14 // CHECK: [[C2:%.*]] = spv.constant 2
15 // CHECK: [[C3:%.*]] = spv.constant 3
16 // CHECK: [[T2:%.*]] = spv.IMul [[ARG3]], [[C2]]
17 // CHECK: [[T3:%.*]] = spv.IAdd [[ARG1]], [[T2]]
18 // CHECK: [[T4:%.*]] = spv.IMul [[ARG4]], [[C3]]
19 // CHECK: [[T5:%.*]] = spv.IAdd [[ARG2]], [[T4]]
20 // CHECK: [[C32:%.*]] = spv.constant 32
21 // CHECK: [[T7:%.*]] = spv.IMul [[C32]], [[T3]]
22 // CHECK: [[C1:%.*]] = spv.constant 1
23 // CHECK: [[T9:%.*]] = spv.IMul [[C1]], [[T5]]
24 // CHECK: [[T10:%.*]] = spv.IAdd [[T7]], [[T9]]
25 // CHECK: [[C0:%.*]] = spv.constant 0
26 // CHECK: [[T12:%.*]] = spv.AccessChain [[ARG0]]{{\[}}[[C0]], [[T10]]
27 // CHECK: spv.Load "StorageBuffer" [[T12]] : f32
28 %0 = subview %arg0[%arg1, %arg2][][] : memref<12x32xf32> to memref<4x4xf32, offset:?, strides: [64, 3]>
29 %1 = load %0[%arg3, %arg4] : memref<4x4xf32, offset:?, strides: [64, 3]>
30 return
31 }
32
33 // CHECK-LABEL: @fold_static_stride_subview_with_store
34 // 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
35 func @fold_static_stride_subview_with_store(%arg0 : memref<12x32xf32>, %arg1 : index, %arg2 : index, %arg3 : index, %arg4 : index, %arg5 : f32) {
36 // CHECK: [[C2:%.*]] = spv.constant 2
37 // CHECK: [[C3:%.*]] = spv.constant 3
38 // CHECK: [[T2:%.*]] = spv.IMul [[ARG3]], [[C2]]
39 // CHECK: [[T3:%.*]] = spv.IAdd [[ARG1]], [[T2]]
40 // CHECK: [[T4:%.*]] = spv.IMul [[ARG4]], [[C3]]
41 // CHECK: [[T5:%.*]] = spv.IAdd [[ARG2]], [[T4]]
42 // CHECK: [[C32:%.*]] = spv.constant 32
43 // CHECK: [[T7:%.*]] = spv.IMul [[C32]], [[T3]]
44 // CHECK: [[C1:%.*]] = spv.constant 1
45 // CHECK: [[T9:%.*]] = spv.IMul [[C1]], [[T5]]
46 // CHECK: [[T10:%.*]] = spv.IAdd [[T7]], [[T9]]
47 // CHECK: [[C0:%.*]] = spv.constant 0
48 // CHECK: [[T12:%.*]] = spv.AccessChain [[ARG0]]{{\[}}[[C0]], [[T10]]
49 // CHECK: spv.Store "StorageBuffer" [[T12]], [[ARG5]] : f32
50 %0 = subview %arg0[%arg1, %arg2][][] : memref<12x32xf32> to memref<4x4xf32, offset:?, strides: [64, 3]>
51 store %arg5, %0[%arg3, %arg4] : memref<4x4xf32, offset:?, strides: [64, 3]>
52 return
53 }