diff --git a/mlir/lib/Dialect/Tosa/Transforms/TosaFoldConstantTranspose.cpp b/mlir/lib/Dialect/Tosa/Transforms/TosaFoldConstantTranspose.cpp --- a/mlir/lib/Dialect/Tosa/Transforms/TosaFoldConstantTranspose.cpp +++ b/mlir/lib/Dialect/Tosa/Transforms/TosaFoldConstantTranspose.cpp @@ -30,7 +30,7 @@ if (!outputType.getElementType().isIntOrIndexOrFloat()) return failure(); - DenseElementsAttr inputValues; + ElementsAttr inputValues; if (!matchPattern(op.getInput1(), m_Constant(&inputValues))) return failure(); // Make sure the input is a constant that has a single user. @@ -57,10 +57,9 @@ // index. auto attrValues = inputValues.getValues(); ArrayRef outputShape = outputType.getShape(); - for (int srcLinearIndex = 0; srcLinearIndex < numElements; - ++srcLinearIndex) { + for (const auto &it : llvm::enumerate(attrValues)) { SmallVector srcIndices(inputType.getRank(), 0); - int totalCount = srcLinearIndex; + int totalCount = it.index(); for (int dim = inputType.getRank() - 1; dim >= 0; --dim) { srcIndices[dim] = totalCount % inputShape[dim]; totalCount /= inputShape[dim]; @@ -74,7 +73,7 @@ for (int dim = 1; dim < outputType.getRank(); ++dim) dstLinearIndex = dstLinearIndex * outputShape[dim] + dstIndices[dim]; - outputValues[dstLinearIndex] = attrValues[srcIndices]; + outputValues[dstLinearIndex] = it.value(); } rewriter.replaceOpWithNewOp(