Skip to content

Commit ebca222

Browse files
committed
[mlir] Check 'iter_args' in 'isLoopParallel' utility
Fix 'isLoopParallel' utility so that 'iter_args' is taken into account and loops with loop-carried dependences are not classified as parallel. Reviewed By: tungld, vinayaka-polymage Differential Revision: https://reviews.llvm.org/D97347
1 parent 203d5ee commit ebca222

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

mlir/lib/Analysis/Utils.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,12 @@ void mlir::getSequentialLoops(AffineForOp forOp,
11731173

11741174
/// Returns true if 'forOp' is parallel.
11751175
bool mlir::isLoopParallel(AffineForOp forOp) {
1176+
// Loop is not parallel if it has SSA loop-carried dependences.
1177+
// TODO: Conditionally support reductions and other loop-carried dependences
1178+
// that could be handled in the context of a parallel loop.
1179+
if (forOp.getNumIterOperands() > 0)
1180+
return false;
1181+
11761182
// Collect all load and store ops in loop nest rooted at 'forOp'.
11771183
SmallVector<Operation *, 8> loadAndStoreOpInsts;
11781184
auto walkResult = forOp.walk([&](Operation *opInst) -> WalkResult {

mlir/test/Dialect/Affine/parallelize.mlir

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,29 @@ func @max_nested(%m: memref<?x?xf32>, %lb0: index, %lb1: index,
159159
return
160160
}
161161

162+
// CHECK-LABEL: @unsupported_iter_args
163+
func @unsupported_iter_args(%in: memref<10xf32>) {
164+
%cst = constant 0.000000e+00 : f32
165+
// CHECK-NOT: affine.parallel
166+
%final_red = affine.for %i = 0 to 10 iter_args(%red_iter = %cst) -> (f32) {
167+
%ld = affine.load %in[%i] : memref<10xf32>
168+
%add = addf %red_iter, %ld : f32
169+
affine.yield %add : f32
170+
}
171+
return
172+
}
162173

174+
// CHECK-LABEL: @unsupported_nested_iter_args
175+
func @unsupported_nested_iter_args(%in: memref<20x10xf32>) {
176+
%cst = constant 0.000000e+00 : f32
177+
// CHECK: affine.parallel
178+
affine.for %i = 0 to 20 {
179+
// CHECK: affine.for
180+
%final_red = affine.for %j = 0 to 10 iter_args(%red_iter = %cst) -> (f32) {
181+
%ld = affine.load %in[%i, %j] : memref<20x10xf32>
182+
%add = addf %red_iter, %ld : f32
183+
affine.yield %add : f32
184+
}
185+
}
186+
return
187+
}

0 commit comments

Comments
 (0)