@@ -20,3 +20,82 @@ func.func @reify_through_chain(%sz0: index, %sz2: index) -> (index, index, index
20
20
21
21
return %4 , %5 , %6 : index , index , index
22
22
}
23
+
24
+ // -----
25
+
26
+ // CHECK-LABEL: func @reify_slice_bound(
27
+ // CHECK: %[[c5:.*]] = arith.constant 5 : index
28
+ // CHECK: "test.some_use"(%[[c5]])
29
+ func.func @reify_slice_bound (%t: tensor <?x?xi32 >, %idx: index , %ub: index , %f: f32 ) {
30
+ %c0 = arith.constant 0 : index
31
+ %c4 = arith.constant 4 : index
32
+ scf.for %iv = %c0 to %ub step %c4 {
33
+ %sz = affine.min affine_map <(d0 )[s0 ] -> (-d0 + s0 , 4 )>(%iv )[%ub ]
34
+ %slice = tensor.extract_slice %t [%idx , %iv ] [1 , %sz ] [1 , 1 ] : tensor <?x?xi32 > to tensor <1 x?xi32 >
35
+ %filled = linalg.fill ins (%f : f32 ) outs (%slice : tensor <1 x?xi32 >) -> tensor <1 x?xi32 >
36
+ %bound = " test.reify_bound" (%filled ) {dim = 1 , type = " UB" } : (tensor <1 x?xi32 >) -> (index )
37
+ " test.some_use" (%bound ) : (index ) -> ()
38
+ }
39
+ return
40
+ }
41
+
42
+ // -----
43
+
44
+ // CHECK: #[[$map:.*]] = affine_map<()[s0, s1] -> (s0 - s1 + 1)>
45
+ // CHECK-LABEL: func @scf_for(
46
+ // CHECK-SAME: %[[lb:.*]]: index, %[[ub:.*]]: index, %[[step:.*]]: index
47
+ // CHECK: %[[bound:.*]] = affine.apply #[[$map]]()[%[[ub]], %[[lb]]]
48
+ // CHECK: "test.some_use"(%[[bound]])
49
+ func.func @scf_for (%lb: index , %ub: index , %step: index ) {
50
+ scf.for %iv = %lb to %ub step %step {
51
+ %0 = affine.apply affine_map <(d0 )[s0 ] -> (-d0 + s0 )>(%iv )[%ub ]
52
+ %bound = " test.reify_bound" (%0 ) {type = " UB" } : (index ) -> (index )
53
+ " test.some_use" (%bound ) : (index ) -> ()
54
+ }
55
+ return
56
+ }
57
+
58
+ // -----
59
+
60
+ // CHECK-LABEL: func @reify_slice_bound2(
61
+ func.func @reify_slice_bound2 (%lb0: index , %ub0: index , %step0: index ,
62
+ %ub2: index , %t1: tensor <1 x?xi8 >,
63
+ %t2: tensor <?x?xi8 >, %t3: tensor <1 x?xi32 >) {
64
+ %c0 = arith.constant 0 : index
65
+ %c1 = arith.constant 1 : index
66
+ %c32 = arith.constant 32 : index
67
+ scf.for %iv0 = %lb0 to %ub0 step %step0 {
68
+ // CHECK: %[[c129:.*]] = arith.constant 129 : index
69
+ // CHECK: "test.some_use"(%[[c129]])
70
+ %ub1 = affine.min affine_map <(d0 )[s0 ] -> (-d0 + s0 , 128 )>(%iv0 )[%ub0 ]
71
+ %ub1_ub = " test.reify_bound" (%ub1 ) {type = " UB" } : (index ) -> (index )
72
+ " test.some_use" (%ub1_ub ) : (index ) -> ()
73
+
74
+ // CHECK: %[[c129:.*]] = arith.constant 129 : index
75
+ // CHECK: "test.some_use"(%[[c129]])
76
+ %lb1 = affine.apply affine_map <()[s0 ] -> ((s0 floordiv 32 ) * 32 )>()[%ub1 ]
77
+ %lb1_ub = " test.reify_bound" (%lb1 ) {type = " UB" } : (index ) -> (index )
78
+ " test.some_use" (%lb1_ub ) : (index ) -> ()
79
+
80
+ scf.for %iv1 = %lb1 to %ub1 step %c32 {
81
+ // CHECK: %[[c32:.*]] = arith.constant 32 : index
82
+ // CHECK: "test.some_use"(%[[c32]])
83
+ %sz = affine.apply affine_map <(d0 )[s0 ] -> (-d0 + s0 )>(%iv1 )[%ub1 ]
84
+ %sz_ub = " test.reify_bound" (%sz ) {type = " UB" } : (index ) -> (index )
85
+ " test.some_use" (%sz_ub ) : (index ) -> ()
86
+
87
+ scf.for %iv2 = %c0 to %ub2 step %c1 {
88
+ %slice1 = tensor.extract_slice %t1 [0 , %iv2 ] [1 , 1 ] [1 , 1 ] : tensor <1 x?xi8 > to tensor <1 x1 xi8 >
89
+ %slice2 = tensor.extract_slice %t2 [%iv2 , 0 ] [1 , %sz ] [1 , 1 ] : tensor <?x?xi8 > to tensor <1 x?xi8 >
90
+ %slice3 = tensor.extract_slice %t3 [0 , 0 ] [1 , %sz ] [1 , 1 ] : tensor <1 x?xi32 > to tensor <1 x?xi32 >
91
+ %matmul = linalg.matmul ins (%slice1 , %slice2 : tensor <1 x1 xi8 >, tensor <1 x?xi8 >) outs (%slice3 : tensor <1 x?xi32 >) -> tensor <1 x?xi32 >
92
+
93
+ // CHECK: %[[c32:.*]] = arith.constant 32 : index
94
+ // CHECK: "test.some_use"(%[[c32]])
95
+ %matmul_ub = " test.reify_bound" (%matmul ) {dim = 1 , type = " UB" } : (tensor <1 x?xi32 >) -> (index )
96
+ " test.some_use" (%matmul_ub ) : (index ) -> ()
97
+ }
98
+ }
99
+ }
100
+ return
101
+ }
0 commit comments