diff --git a/mlir/include/mlir/Dialect/Affine/Utils.h b/mlir/include/mlir/Dialect/Affine/Utils.h --- a/mlir/include/mlir/Dialect/Affine/Utils.h +++ b/mlir/include/mlir/Dialect/Affine/Utils.h @@ -158,10 +158,11 @@ /// Normalize an affine.for op. If the affine.for op has only a single iteration /// only then it is simply promoted, else it is normalized in the traditional /// way, by converting the lower bound to zero and loop step to one. The upper -/// bound is set to the trip count of the loop. For now, original loops must -/// have lower bound with a single result only. There is no such restriction on -/// upper bounds. -void normalizeAffineFor(AffineForOp op); +/// bound is set to the trip count of the loop. Original loops must have a +/// lower bound with only a single result. There is no such restriction on upper +/// bounds. Returns success if the loop has been normalized (or is already in +/// the normal form). +LogicalResult normalizeAffineFor(AffineForOp op); /// Traverse `e` and return an AffineExpr where all occurrences of `dim` have /// been replaced by either: diff --git a/mlir/lib/Dialect/Affine/Transforms/AffineLoopNormalize.cpp b/mlir/lib/Dialect/Affine/Transforms/AffineLoopNormalize.cpp --- a/mlir/lib/Dialect/Affine/Transforms/AffineLoopNormalize.cpp +++ b/mlir/lib/Dialect/Affine/Transforms/AffineLoopNormalize.cpp @@ -30,7 +30,7 @@ if (auto affineParallel = dyn_cast(op)) normalizeAffineParallel(affineParallel); else if (auto affineFor = dyn_cast(op)) - normalizeAffineFor(affineFor); + (void)normalizeAffineFor(affineFor); }); } }; diff --git a/mlir/lib/Dialect/Affine/Utils/Utils.cpp b/mlir/lib/Dialect/Affine/Utils/Utils.cpp --- a/mlir/lib/Dialect/Affine/Utils/Utils.cpp +++ b/mlir/lib/Dialect/Affine/Utils/Utils.cpp @@ -551,21 +551,21 @@ /// bound is set to the trip count of the loop. For now, original loops must /// have lower bound with a single result only. There is no such restriction on /// upper bounds. -void mlir::normalizeAffineFor(AffineForOp op) { +LogicalResult mlir::normalizeAffineFor(AffineForOp op) { if (succeeded(promoteIfSingleIteration(op))) - return; + return success(); // Check if the forop is already normalized. if (op.hasConstantLowerBound() && (op.getConstantLowerBound() == 0) && (op.getStep() == 1)) - return; + return success(); // Check if the lower bound has a single result only. Loops with a max lower // bound can't be normalized without additional support like // affine.execute_region's. If the lower bound does not have a single result // then skip this op. if (op.getLowerBoundMap().getNumResults() != 1) - return; + return failure(); Location loc = op.getLoc(); OpBuilder opBuilder(op); @@ -642,6 +642,7 @@ origLbMap.getNumSymbols(), newIVExpr); Operation *newIV = opBuilder.create(loc, ivMap, lbOperands); op.getInductionVar().replaceAllUsesExcept(newIV->getResult(0), newIV); + return success(); } /// Ensure that all operations that could be executed after `start`