From: Guray Ozen Date: Fri, 2 Dec 2022 15:34:58 +0000 (+0100) Subject: [mlir] Fix infinite loop in collapse X-Git-Tag: upstream/17.0.6~25304 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=12cc8e7310474c2b3231e4ebba8e555e31cd3eaf;p=platform%2Fupstream%2Fllvm.git [mlir] Fix infinite loop in collapse Incrementing `counter` variable is inside the if statement. If the code does not enter there, the while loop will iterate infinitely. This revision moves the codes outside of if statement. Reviewed By: mravishankar Differential Revision: https://reviews.llvm.org/D139005 --- diff --git a/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp b/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp index d7df08f..d4c0887 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp @@ -1318,17 +1318,17 @@ getOperandReassociation(AffineMap indexingMap, while (counter < indexingMap.getNumResults()) { unsigned dim = indexingMap.getResult(counter).cast().getPosition(); + // This is the start of a collapsed dimensions of the iteration that + // is gauranteed to be preserved in the indexing map. The number of folded + // dims is obtained from the collapsed op to original op mapping. + unsigned numFoldedDims = + collapsedOpToOrigOpMapping[origOpToCollapsedOpMapping[dim].first] + .size(); if (origOpToCollapsedOpMapping[dim].second == 0) { - // This is the start of a collapsed dimensions of the iteration that - // is gauranteed to be preserved in the indexing map. The number of folded - // dims is obtained from the collapsed op to original op mapping. - unsigned numFoldedDims = - collapsedOpToOrigOpMapping[origOpToCollapsedOpMapping[dim].first] - .size(); auto range = llvm::seq(counter, counter + numFoldedDims); operandReassociation.emplace_back(range.begin(), range.end()); - counter += numFoldedDims; } + counter += numFoldedDims; } return operandReassociation; }