130 lines · plain
1// RUN: mlir-opt %s -pass-pipeline='builtin.module(func.func(test-affine-reify-value-bounds))' -verify-diagnostics \2// RUN: -split-input-file | FileCheck %s3 4// CHECK-LABEL: func @memref_alloc(5// CHECK-SAME: %[[sz:.*]]: index6// CHECK: %[[c6:.*]] = arith.constant 6 : index7// CHECK: return %[[c6]], %[[sz]]8func.func @memref_alloc(%sz: index) -> (index, index) {9 %0 = memref.alloc(%sz) : memref<6x?xf32>10 %1 = "test.reify_bound"(%0) {dim = 0} : (memref<6x?xf32>) -> (index)11 %2 = "test.reify_bound"(%0) {dim = 1} : (memref<6x?xf32>) -> (index)12 return %1, %2 : index, index13}14 15// -----16 17// CHECK-LABEL: func @memref_alloca(18// CHECK-SAME: %[[sz:.*]]: index19// CHECK: %[[c6:.*]] = arith.constant 6 : index20// CHECK: return %[[c6]], %[[sz]]21func.func @memref_alloca(%sz: index) -> (index, index) {22 %0 = memref.alloca(%sz) : memref<6x?xf32>23 %1 = "test.reify_bound"(%0) {dim = 0} : (memref<6x?xf32>) -> (index)24 %2 = "test.reify_bound"(%0) {dim = 1} : (memref<6x?xf32>) -> (index)25 return %1, %2 : index, index26}27 28// -----29 30// CHECK-LABEL: func @memref_cast(31// CHECK: %[[c10:.*]] = arith.constant 10 : index32// CHECK: return %[[c10]]33func.func @memref_cast(%m: memref<10xf32>) -> index {34 %0 = memref.cast %m : memref<10xf32> to memref<?xf32>35 %1 = "test.reify_bound"(%0) {dim = 0} : (memref<?xf32>) -> (index)36 return %1 : index37}38 39// -----40 41// CHECK-LABEL: func @memref_dim(42// CHECK-SAME: %[[m:.*]]: memref<?xf32>43// CHECK: %[[dim:.*]] = memref.dim %[[m]]44// CHECK: %[[dim:.*]] = memref.dim %[[m]]45// CHECK: return %[[dim]]46func.func @memref_dim(%m: memref<?xf32>) -> index {47 %c0 = arith.constant 0 : index48 %0 = memref.dim %m, %c0 : memref<?xf32>49 %1 = "test.reify_bound"(%0) : (index) -> (index)50 return %1 : index51}52 53// -----54 55// CHECK-LABEL: func @memref_dim_all_positive(56func.func @memref_dim_all_positive(%m: memref<?xf32>, %x: index) {57 %c0 = arith.constant 0 : index58 %0 = memref.dim %m, %x : memref<?xf32>59 // expected-remark @below{{true}}60 "test.compare"(%0, %c0) {cmp = "GE"} : (index, index) -> ()61 return62}63 64// -----65 66// CHECK-LABEL: func @memref_expand(67// CHECK-SAME: %[[m:[a-zA-Z0-9]+]]: memref<?xf32>68// CHECK-SAME: %[[sz:[a-zA-Z0-9]+]]: index69// CHECK: %[[c4:.*]] = arith.constant 4 : index70// CHECK: return %[[c4]], %[[sz]]71func.func @memref_expand(%m: memref<?xf32>, %sz: index) -> (index, index) {72 %0 = memref.expand_shape %m [[0, 1]] output_shape [4, %sz]: memref<?xf32> into memref<4x?xf32>73 %1 = "test.reify_bound"(%0) {dim = 0} : (memref<4x?xf32>) -> (index)74 %2 = "test.reify_bound"(%0) {dim = 1} : (memref<4x?xf32>) -> (index)75 return %1, %2 : index, index76}77 78// -----79 80// CHECK: #[[$MAP:.+]] = affine_map<()[s0] -> (s0 * 2)>81// CHECK-LABEL: func @memref_collapse(82// CHECK-SAME: %[[sz0:.*]]: index83// CHECK-DAG: %[[c2:.*]] = arith.constant 2 : index84// CHECK-DAG: %[[c12:.*]] = arith.constant 12 : index85// CHECK: %[[dim:.*]] = memref.dim %{{.*}}, %[[c2]] : memref<3x4x?x2xf32>86// CHECK: %[[mul:.*]] = affine.apply #[[$MAP]]()[%[[dim]]]87// CHECK: return %[[c12]], %[[mul]]88func.func @memref_collapse(%sz0: index) -> (index, index) {89 %0 = memref.alloc(%sz0) : memref<3x4x?x2xf32>90 %1 = memref.collapse_shape %0 [[0, 1], [2, 3]] : memref<3x4x?x2xf32> into memref<12x?xf32>91 %2 = "test.reify_bound"(%1) {dim = 0} : (memref<12x?xf32>) -> (index)92 %3 = "test.reify_bound"(%1) {dim = 1} : (memref<12x?xf32>) -> (index)93 return %2, %3 : index, index94}95 96// -----97 98// CHECK-LABEL: func @memref_get_global(99// CHECK: %[[c4:.*]] = arith.constant 4 : index100// CHECK: return %[[c4]]101memref.global "private" @gv0 : memref<4xf32> = dense<[0.0, 1.0, 2.0, 3.0]>102func.func @memref_get_global() -> index {103 %0 = memref.get_global @gv0 : memref<4xf32>104 %1 = "test.reify_bound"(%0) {dim = 0} : (memref<4xf32>) -> (index)105 return %1 : index106}107 108// -----109 110// CHECK-LABEL: func @memref_rank(111// CHECK-SAME: %[[t:.*]]: memref<5xf32>112// CHECK: %[[c1:.*]] = arith.constant 1 : index113// CHECK: return %[[c1]]114func.func @memref_rank(%m: memref<5xf32>) -> index {115 %0 = memref.rank %m : memref<5xf32>116 %1 = "test.reify_bound"(%0) : (index) -> (index)117 return %1 : index118}119 120// -----121 122// CHECK-LABEL: func @memref_subview(123// CHECK-SAME: %[[m:.*]]: memref<?xf32>, %[[sz:.*]]: index124// CHECK: return %[[sz]]125func.func @memref_subview(%m: memref<?xf32>, %sz: index) -> index {126 %0 = memref.subview %m[2][%sz][1] : memref<?xf32> to memref<?xf32, strided<[1], offset: 2>>127 %1 = "test.reify_bound"(%0) {dim = 0} : (memref<?xf32, strided<[1], offset: 2>>) -> (index)128 return %1 : index129}130