xref: /llvm-project/mlir/test/Dialect/SCF/forall-to-for.mlir (revision 286bd42a7a799e3d9035c09bf0d64cb1a1eef682)
1// RUN: mlir-opt %s -pass-pipeline='builtin.module(func.func(scf-forall-to-for))' -split-input-file | FileCheck %s
2
3func.func private @callee(%i: index, %j: index)
4
5// CHECK-LABEL: @two_iters
6// CHECK-SAME: %[[UB1:.+]]: index, %[[UB2:.+]]: index
7func.func @two_iters(%ub1: index, %ub2: index) {
8  scf.forall (%i, %j) in (%ub1, %ub2) {
9    func.call @callee(%i, %j) : (index, index) -> ()
10  }
11  // CHECK: scf.for %[[IV1:.+]] = %{{.*}} to %[[UB1]]
12  // CHECK:   scf.for %[[IV2:.+]] = %{{.*}} to %[[UB2]]
13  // CHECK:     func.call @callee(%[[IV1]], %[[IV2]])
14  return
15}
16
17// -----
18
19func.func private @callee(%i: index, %j: index)
20
21// CHECK-LABEL: @repeated
22// CHECK-SAME: %[[UB1:.+]]: index, %[[UB2:.+]]: index
23func.func @repeated(%ub1: index, %ub2: index) {
24  scf.forall (%i, %j) in (%ub1, %ub2) {
25    func.call @callee(%i, %j) : (index, index) -> ()
26  }
27  // CHECK: scf.for %[[IV1:.+]] = %{{.*}} to %[[UB1]]
28  // CHECK:   scf.for %[[IV2:.+]] = %{{.*}} to %[[UB2]]
29  // CHECK:     func.call @callee(%[[IV1]], %[[IV2]])
30  scf.forall (%i, %j) in (%ub1, %ub2) {
31    func.call @callee(%i, %j) : (index, index) -> ()
32  }
33  // CHECK: scf.for %[[IV1:.+]] = %{{.*}} to %[[UB1]]
34  // CHECK:   scf.for %[[IV2:.+]] = %{{.*}} to %[[UB2]]
35  // CHECK:     func.call @callee(%[[IV1]], %[[IV2]])
36  return
37}
38
39// -----
40
41func.func private @callee(%i: index, %j: index, %k: index, %l: index)
42
43// CHECK-LABEL: @nested
44// CHECK-SAME: %[[UB1:.+]]: index, %[[UB2:.+]]: index, %[[UB3:.+]]: index, %[[UB4:.+]]: index
45func.func @nested(%ub1: index, %ub2: index, %ub3: index, %ub4: index) {
46  // CHECK: scf.for %[[IV1:.+]] = %{{.*}} to %[[UB1]]
47  // CHECK:   scf.for %[[IV2:.+]] = %{{.*}} to %[[UB2]]
48  // CHECK:     scf.for %[[IV3:.+]] = %{{.*}} to %[[UB3]]
49  // CHECK:       scf.for %[[IV4:.+]] = %{{.*}} to %[[UB4]]
50  // CHECK:         func.call @callee(%[[IV1]], %[[IV2]], %[[IV3]], %[[IV4]])
51  scf.forall (%i, %j) in (%ub1, %ub2) {
52    scf.forall (%k, %l) in (%ub3, %ub4) {
53      func.call @callee(%i, %j, %k, %l) : (index, index, index, index) -> ()
54    }
55  }
56  return
57}
58