Index: mlir/test/lib/Dialect/Affine/TestLoopPermutation.cpp =================================================================== --- mlir/test/lib/Dialect/Affine/TestLoopPermutation.cpp +++ mlir/test/lib/Dialect/Affine/TestLoopPermutation.cpp @@ -47,21 +47,25 @@ } // end anonymous namespace void TestLoopPermutation::runOnFunction() { - // Get the first maximal perfect nest. - SmallVector nest; - for (auto &op : getFunction().front()) { - if (auto forOp = dyn_cast(op)) { - getPerfectlyNestedLoops(nest, forOp); - break; - } - } - - // Nothing to do. - if (nest.size() < 2) - return; SmallVector permMap(permList.begin(), permList.end()); - permuteLoops(nest, permMap); + + SmallVector forOps; + getFunction().walk([&](AffineForOp forOp) { + forOps.push_back(forOp); + }); + + for (auto forOp: forOps) { + SmallVector nest; + // Get the maximal perfect nest. + getPerfectlyNestedLoops(nest, forOp); + // Permute if the nest's size is consistent with the specified + // permutation. + if (nest.size() >= 2 && nest.size() == permMap.size()) { + permuteLoops(nest, permMap); + } + } + } namespace mlir {