Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions mlir/lib/Dialect/Vector/IR/VectorOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5348,6 +5348,9 @@ class FoldContiguousGather final : public OpRewritePattern<GatherOp> {
using OpRewritePattern::OpRewritePattern;
LogicalResult matchAndRewrite(GatherOp op,
PatternRewriter &rewriter) const override {
if (!op.getBase().getType().isa<MemRefType>())
return rewriter.notifyMatchFailure(op, "base must be of memref type");

if (failed(isZeroBasedContiguousSeq(op.getIndexVec())))
return failure();

Expand Down
13 changes: 13 additions & 0 deletions mlir/test/Dialect/Vector/canonicalize.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -3198,6 +3198,19 @@ func.func @contiguous_gather_step(%base: memref<?xf32>,

// -----

// CHECK-LABEL: @no_fold_contiguous_gather_tensor
func.func @no_fold_contiguous_gather_tensor(%base: tensor<8xf32>, %mask: vector<4xi1>, %pass_thru: vector<4xf32>) -> vector<4xf32> {
%c0 = arith.constant 0 : index
%indices = arith.constant dense<[0, 1, 2, 3]> : vector<4xindex>
// CHECK: vector.gather
// CHECK-NOT: vector.maskedload
%0 = vector.gather %base[%c0][%indices], %mask, %pass_thru :
tensor<8xf32>, vector<4xindex>, vector<4xi1>, vector<4xf32> into vector<4xf32>
return %0 : vector<4xf32>
}

// -----

// CHECK-LABEL: @gather_broadcast(
// TODO: Broadcast is not supported yet
// CHECK: %[[R:.*]] = vector.gather
Expand Down