summaryrefslogtreecommitdiffstats
path: root/mlir/test/Transforms
diff options
context:
space:
mode:
authorAndy Davis <andydavis@google.com>2019-11-07 08:04:33 -0800
committerA. Unique TensorFlower <gardener@tensorflow.org>2019-11-07 08:05:03 -0800
commit5fbdb67b0aa7f01b17dcca62e08e3db38d021fce (patch)
tree558cbcb37a4b93532aea6098de4616607602751a /mlir/test/Transforms
parenta10d836c6de913445105274a0d92b0265da3bd2f (diff)
downloadbcm5719-llvm-5fbdb67b0aa7f01b17dcca62e08e3db38d021fce.tar.gz
bcm5719-llvm-5fbdb67b0aa7f01b17dcca62e08e3db38d021fce.zip
Add canonicalizer for ViewOp which folds constants into the ViewOp memref shape and layout map strides and offset.
PiperOrigin-RevId: 279088023
Diffstat (limited to 'mlir/test/Transforms')
-rw-r--r--mlir/test/Transforms/canonicalize.mlir46
1 files changed, 46 insertions, 0 deletions
diff --git a/mlir/test/Transforms/canonicalize.mlir b/mlir/test/Transforms/canonicalize.mlir
index b100f7213f1..8ccf24061b9 100644
--- a/mlir/test/Transforms/canonicalize.mlir
+++ b/mlir/test/Transforms/canonicalize.mlir
@@ -1,5 +1,15 @@
// RUN: mlir-opt %s -pass-pipeline='func(canonicalize)' | FileCheck %s
+#TEST_VIEW_MAP0 = (d0, d1)[s0, s1] -> (d0 * s0 + d1 + s1)
+#TEST_VIEW_MAP1 = (d0, d1, d2)[s0, s1] -> (d0 * s0 + d1 * s1 + d2)
+#TEST_VIEW_MAP2 = (d0, d1)[s0, s1] -> (d0 * 4 + d1 + s1)
+
+// CHECK-DAG: #[[VIEW_MAP0:map[0-9]+]] = (d0, d1) -> (d0 * 11 + d1 + 15)
+// CHECK-DAG: #[[VIEW_MAP1:map[0-9]+]] = (d0, d1)[s0] -> (d0 * 11 + s0 + d1)
+// CHECK-DAG: #[[VIEW_MAP2:map[0-9]+]] = (d0, d1)[s0] -> (d0 * s0 + d1 + 15)
+// CHECK-DAG: #[[VIEW_MAP3:map[0-9]+]] = (d0, d1, d2)[s0] -> (d0 * s0 + d1 * 7 + d2)
+// CHECK-DAG: #[[VIEW_MAP4:map[0-9]+]] = (d0, d1) -> (d0 * 4 + d1 + 15)
+
// CHECK-LABEL: func @test_subi_zero
func @test_subi_zero(%arg0: i32) -> i32 {
// CHECK-NEXT: %c0_i32 = constant 0 : i32
@@ -579,3 +589,39 @@ func @cast_values(%arg0: tensor<*xi32>, %arg1: memref<?xi32>) -> (tensor<2xi32>,
// CHECK-NEXT: return %0, %1 : tensor<2xi32>, memref<2xi32>
return %4, %5 : tensor<2xi32>, memref<2xi32>
}
+
+// CHECK-LABEL: func @view
+func @view(%arg0 : index) {
+ %0 = alloc() : memref<2048xi8>
+ %c7 = constant 7 : index
+ %c11 = constant 11 : index
+ %c15 = constant 15 : index
+
+ // Test: fold constant sizes and offset, update map with static stride/offset.
+ // CHECK: std.view %0[][] : memref<2048xi8> to memref<7x11xf32, #[[VIEW_MAP0]]>
+ %1 = view %0[%c7, %c11][%c15]
+ : memref<2048xi8> to memref<?x?xf32, #TEST_VIEW_MAP0>
+ // Test: fold constant sizes but not offset, update map with static stride.
+ // Test that we do not a fold dynamic dim which is not produced by a constant.
+ // CHECK: std.view %0[][%arg0] : memref<2048xi8> to memref<7x11xf32, #[[VIEW_MAP1]]>
+ %2 = view %0[%c7, %c11][%arg0]
+ : memref<2048xi8> to memref<?x?xf32, #TEST_VIEW_MAP0>
+ // Test: fold constant offset but not sizes, update map with constant offset.
+ // Test that we fold constant offset but not dynamic dims.
+ // CHECK: std.view %0[%arg0, %arg0][] : memref<2048xi8> to memref<?x?xf32, #[[VIEW_MAP2]]>
+ %3 = view %0[%arg0, %arg0][%c15]
+ : memref<2048xi8> to memref<?x?xf32, #TEST_VIEW_MAP0>
+ // Test: fold one constant dim, no offset, should update with constant
+ // stride on dim 1, but leave dynamic stride on dim 0.
+ // CHECK: std.view %0[%arg0, %arg0][] : memref<2048xi8> to memref<?x?x7xf32, #[[VIEW_MAP3]]>
+ %4 = view %0[%arg0, %arg0, %c7][]
+ : memref<2048xi8> to memref<?x?x?xf32, #TEST_VIEW_MAP1>
+
+ // Test: preserve an existing static dim size while folding a dynamic
+ // dimension and offset.
+ // CHECK: std.view %0[][] : memref<2048xi8> to memref<7x4xf32, #[[VIEW_MAP4]]>
+ %5 = view %0[%c7][%c15]
+ : memref<2048xi8> to memref<?x4xf32, #TEST_VIEW_MAP2>
+
+ return
+}
OpenPOWER on IntegriCloud