22
33// CHECK-LABEL: @conversion_static
44func @conversion_static (%arg0 : memref <2 xf32 >) -> memref <2 xf32 > {
5- %0 = bufferization.clone %arg0 : memref <2 xf32 > to memref <2 xf32 >
6- memref.dealloc %arg0 : memref <2 xf32 >
7- return %0 : memref <2 xf32 >
5+ %0 = bufferization.clone %arg0 : memref <2 xf32 > to memref <2 xf32 >
6+ memref.dealloc %arg0 : memref <2 xf32 >
7+ return %0 : memref <2 xf32 >
88}
99
1010// CHECK: %[[ALLOC:.*]] = memref.alloc
@@ -16,9 +16,9 @@ func @conversion_static(%arg0 : memref<2xf32>) -> memref<2xf32> {
1616
1717// CHECK-LABEL: @conversion_dynamic
1818func @conversion_dynamic (%arg0 : memref <?xf32 >) -> memref <?xf32 > {
19- %1 = bufferization.clone %arg0 : memref <?xf32 > to memref <?xf32 >
20- memref.dealloc %arg0 : memref <?xf32 >
21- return %1 : memref <?xf32 >
19+ %1 = bufferization.clone %arg0 : memref <?xf32 > to memref <?xf32 >
20+ memref.dealloc %arg0 : memref <?xf32 >
21+ return %1 : memref <?xf32 >
2222}
2323
2424// CHECK: %[[CONST:.*]] = arith.constant
@@ -32,7 +32,40 @@ func @conversion_dynamic(%arg0 : memref<?xf32>) -> memref<?xf32> {
3232
3333func @conversion_unknown (%arg0 : memref <*xf32 >) -> memref <*xf32 > {
3434// expected-error@+1 {{failed to legalize operation 'bufferization.clone' that was explicitly marked illegal}}
35- %1 = bufferization.clone %arg0 : memref <*xf32 > to memref <*xf32 >
36- memref.dealloc %arg0 : memref <*xf32 >
37- return %1 : memref <*xf32 >
35+ %1 = bufferization.clone %arg0 : memref <*xf32 > to memref <*xf32 >
36+ memref.dealloc %arg0 : memref <*xf32 >
37+ return %1 : memref <*xf32 >
38+ }
39+
40+ // -----
41+
42+ // CHECK: #[[$MAP:.*]] = affine_map<(d0)[s0, s1] -> (d0 * s1 + s0)>
43+ #map = affine_map <(d0 )[s0 , s1 ] -> (d0 * s1 + s0 )>
44+ // CHECK-LABEL: func @conversion_with_layout_map(
45+ // CHECK-SAME: %[[ARG:.*]]: memref<?xf32, #[[$MAP]]>
46+ // CHECK: %[[C0:.*]] = arith.constant 0 : index
47+ // CHECK: %[[DIM:.*]] = memref.dim %[[ARG]], %[[C0]]
48+ // CHECK: %[[ALLOC:.*]] = memref.alloc(%[[DIM]]) : memref<?xf32>
49+ // CHECK: %[[CASTED:.*]] = memref.cast %[[ALLOC]] : memref<?xf32> to memref<?xf32, #[[$MAP]]>
50+ // CHECK: memref.copy
51+ // CHECK: memref.dealloc
52+ // CHECK: return %[[CASTED]]
53+ func @conversion_with_layout_map (%arg0 : memref <?xf32 , #map >) -> memref <?xf32 , #map > {
54+ %1 = bufferization.clone %arg0 : memref <?xf32 , #map > to memref <?xf32 , #map >
55+ memref.dealloc %arg0 : memref <?xf32 , #map >
56+ return %1 : memref <?xf32 , #map >
57+ }
58+
59+ // -----
60+
61+ // This bufferization.clone cannot be lowered because a buffer with this layout
62+ // map cannot be allocated (or casted to).
63+
64+ #map2 = affine_map <(d0 )[s0 ] -> (d0 * 10 + s0 )>
65+ func @conversion_with_invalid_layout_map (%arg0 : memref <?xf32 , #map2 >)
66+ -> memref <?xf32 , #map2 > {
67+ // expected-error@+1 {{failed to legalize operation 'bufferization.clone' that was explicitly marked illegal}}
68+ %1 = bufferization.clone %arg0 : memref <?xf32 , #map2 > to memref <?xf32 , #map2 >
69+ memref.dealloc %arg0 : memref <?xf32 , #map2 >
70+ return %1 : memref <?xf32 , #map2 >
3871}
0 commit comments