[Mlir-commits] [mlir] [mlir][vector] Add unroll patterns for vector.load and vector.store (PR #143420)
James Newling
llvmlistbot at llvm.org
Fri Jun 20 13:12:04 PDT 2025
================
@@ -631,6 +653,100 @@ struct UnrollGatherPattern : public OpRewritePattern<vector::GatherOp> {
vector::UnrollVectorOptions options;
};
+struct UnrollLoadPattern : public OpRewritePattern<vector::LoadOp> {
+ UnrollLoadPattern(MLIRContext *context,
+ const vector::UnrollVectorOptions &options,
+ PatternBenefit benefit = 1)
+ : OpRewritePattern<vector::LoadOp>(context, benefit), options(options) {}
+
+ LogicalResult matchAndRewrite(vector::LoadOp loadOp,
+ PatternRewriter &rewriter) const override {
+ VectorType vecType = loadOp.getVectorType();
+ if (vecType.getRank() <= 1)
+ return failure();
+
+ auto targetShape = getTargetShape(options, loadOp);
+ if (!targetShape)
+ return failure();
+
+ Location loc = loadOp.getLoc();
+ ArrayRef<int64_t> originalShape = vecType.getShape();
+ SmallVector<int64_t> strides(targetShape->size(), 1);
+
+ Value result = rewriter.create<arith::ConstantOp>(
+ loc, vecType, rewriter.getZeroAttr(vecType));
+
+ SmallVector<Value> originalIndices(loadOp.getIndices().begin(),
----------------
newling wrote:
You could use
```
SmallVector<Value> originalIndices = llvm::to_vector(loadOp.getIndices());
```
but even better to just pass loadOp.getIndices() directly to the function (as suggested in another comment).
(same comment for load logic)
https://github.com/llvm/llvm-project/pull/143420
More information about the Mlir-commits
mailing list