@@ -155,3 +155,84 @@ func.func @compare_maps(%a: index, %b: index) {
155155 : (index , index , index , index ) -> ()
156156 return
157157}
158+
159+ // -----
160+
161+ // CHECK-DAG: #[[$map1:.+]] = affine_map<()[s0] -> (s0 floordiv 15)>
162+ // CHECK-DAG: #[[$map2:.+]] = affine_map<()[s0] -> ((s0 mod 15) floordiv 5)>
163+ // CHECK-DAG: #[[$map3:.+]] = affine_map<()[s0] -> (s0 mod 5)>
164+ // CHECK-LABEL: func.func @delinearize_static
165+ // CHECK-SAME: (%[[arg0:.+]]: index)
166+ // CHECK-DAG: %[[v1:.+]] = affine.apply #[[$map1]]()[%[[arg0]]]
167+ // CHECK-DAG: %[[v2:.+]] = affine.apply #[[$map2]]()[%[[arg0]]]
168+ // CHECK-DAG: %[[v3:.+]] = affine.apply #[[$map3]]()[%[[arg0]]]
169+ // CHECK: return %[[v1]], %[[v2]], %[[v3]]
170+ func.func @delinearize_static (%arg0: index ) -> (index , index , index ) {
171+ %c2 = arith.constant 2 : index
172+ %c3 = arith.constant 3 : index
173+ %0:3 = affine.delinearize_index %arg0 into (2 , 3 , 5 ) : index , index , index
174+ %1 = " test.reify_bound" (%0#0 ) {type = " EQ" } : (index ) -> (index )
175+ %2 = " test.reify_bound" (%0#1 ) {type = " EQ" } : (index ) -> (index )
176+ %3 = " test.reify_bound" (%0#2 ) {type = " EQ" } : (index ) -> (index )
177+ // expected-remark @below{{true}}
178+ " test.compare" (%0#0 , %c2 ) {cmp = " LT" } : (index , index ) -> ()
179+ // expected-remark @below{{true}}
180+ " test.compare" (%0#1 , %c3 ) {cmp = " LT" } : (index , index ) -> ()
181+ return %1 , %2 , %3 : index , index , index
182+ }
183+
184+ // -----
185+
186+ // CHECK-DAG: #[[$map1:.+]] = affine_map<()[s0] -> (s0 floordiv 15)>
187+ // CHECK-DAG: #[[$map2:.+]] = affine_map<()[s0] -> ((s0 mod 15) floordiv 5)>
188+ // CHECK-DAG: #[[$map3:.+]] = affine_map<()[s0] -> (s0 mod 5)>
189+ // CHECK-LABEL: func.func @delinearize_static_no_outer_bound
190+ // CHECK-SAME: (%[[arg0:.+]]: index)
191+ // CHECK-DAG: %[[v1:.+]] = affine.apply #[[$map1]]()[%[[arg0]]]
192+ // CHECK-DAG: %[[v2:.+]] = affine.apply #[[$map2]]()[%[[arg0]]]
193+ // CHECK-DAG: %[[v3:.+]] = affine.apply #[[$map3]]()[%[[arg0]]]
194+ // CHECK: return %[[v1]], %[[v2]], %[[v3]]
195+ func.func @delinearize_static_no_outer_bound (%arg0: index ) -> (index , index , index ) {
196+ %c2 = arith.constant 2 : index
197+ %c3 = arith.constant 3 : index
198+ %0:3 = affine.delinearize_index %arg0 into (3 , 5 ) : index , index , index
199+ %1 = " test.reify_bound" (%0#0 ) {type = " EQ" } : (index ) -> (index )
200+ %2 = " test.reify_bound" (%0#1 ) {type = " EQ" } : (index ) -> (index )
201+ %3 = " test.reify_bound" (%0#2 ) {type = " EQ" } : (index ) -> (index )
202+ " test.compaare" (%0#0 , %c2 ) {cmp = " LT" } : (index , index ) -> ()
203+ // expected-remark @below{{true}}
204+ " test.compare" (%0#1 , %c3 ) {cmp = " LT" } : (index , index ) -> ()
205+ return %1 , %2 , %3 : index , index , index
206+ }
207+
208+ // -----
209+
210+ // CHECK: #[[$map:.+]] = affine_map<()[s0, s1] -> (s0 + s1 * 3)>
211+ // CHECK-LABEL: func.func @linearize_static
212+ // CHECK-SAME: (%[[arg0:.+]]: index, %[[arg1:.+]]: index)
213+ // CHECK: %[[v1:.+]] = affine.apply #[[$map]]()[%[[arg1]], %[[arg0]]]
214+ // CHECK: return %[[v1]]
215+ func.func @linearize_static (%arg0: index , %arg1: index ) -> index {
216+ %c6 = arith.constant 6 : index
217+ %0 = affine.linearize_index disjoint [%arg0 , %arg1 ] by (2 , 3 ) : index
218+ %1 = " test.reify_bound" (%0 ) {type = " EQ" } : (index ) -> (index )
219+ // expected-remark @below{{true}}
220+ " test.compare" (%0 , %c6 ) {cmp = " LT" } : (index , index ) -> ()
221+ return %1 : index
222+ }
223+
224+ // -----
225+
226+ // CHECK: #[[$map:.+]] = affine_map<()[s0, s1] -> (s0 + s1 * 3)>
227+ // CHECK-LABEL: func.func @linearize_static_no_outer_bound
228+ // CHECK-SAME: (%[[arg0:.+]]: index, %[[arg1:.+]]: index)
229+ // CHECK: %[[v1:.+]] = affine.apply #[[$map]]()[%[[arg1]], %[[arg0]]]
230+ // CHECK: return %[[v1]]
231+ func.func @linearize_static_no_outer_bound (%arg0: index , %arg1: index ) -> index {
232+ %c6 = arith.constant 6 : index
233+ %0 = affine.linearize_index disjoint [%arg0 , %arg1 ] by (3 ) : index
234+ %1 = " test.reify_bound" (%0 ) {type = " EQ" } : (index ) -> (index )
235+ // expected-error @below{{unknown}}
236+ " test.compare" (%0 , %c6 ) {cmp = " LT" } : (index , index ) -> ()
237+ return %1 : index
238+ }
0 commit comments