-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir][vector] Add folders for full constant transfer masks #71676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3937,6 +3937,23 @@ static LogicalResult foldTransferInBoundsAttribute(TransferOp op) { | |
return success(); | ||
} | ||
|
||
template <typename TransferOp> | ||
static LogicalResult foldTransferFullMask(TransferOp op) { | ||
auto mask = op.getMask(); | ||
if (!mask) | ||
return failure(); | ||
|
||
auto constantMask = mask.template getDefiningOp<vector::ConstantMaskOp>(); | ||
if (!constantMask) | ||
return failure(); | ||
|
||
if (!constantMask.isFullMask()) | ||
return failure(); | ||
|
||
op.getMaskMutable().clear(); | ||
return success(); | ||
} | ||
|
||
/// ``` | ||
/// %w0 = vector.transfer_write %v0, %arg0[%c1, %c0] {in_bounds = [true, true]} | ||
/// : vector<1x4xf32>, tensor<4x4xf32> | ||
|
@@ -3969,6 +3986,8 @@ OpFoldResult TransferReadOp::fold(FoldAdaptor) { | |
/// transfer_read(memrefcast) -> transfer_read | ||
if (succeeded(foldTransferInBoundsAttribute(*this))) | ||
return getResult(); | ||
if (succeeded(foldTransferFullMask(*this))) | ||
return getResult(); | ||
if (succeeded(memref::foldMemRefCast(*this))) | ||
return getResult(); | ||
if (succeeded(tensor::foldTensorCast(*this))) | ||
|
@@ -4334,6 +4353,8 @@ LogicalResult TransferWriteOp::fold(FoldAdaptor adaptor, | |
return success(); | ||
if (succeeded(foldTransferInBoundsAttribute(*this))) | ||
return success(); | ||
if (succeeded(foldTransferFullMask(*this))) | ||
return success(); | ||
return memref::foldMemRefCast(*this); | ||
} | ||
|
||
|
@@ -5601,6 +5622,22 @@ LogicalResult ConstantMaskOp::verify() { | |
return success(); | ||
} | ||
|
||
bool ConstantMaskOp::isFullMask() { | ||
auto resultType = getVectorType(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think @aartbik had already created some utilities to check if a mask is all ones or zeros. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you happen to know where those utilities are? I poked around and couldn't find anything. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought Aart would know by heart but I found it :) https://github.com/llvm/llvm-project/blob/main/mlir/lib/Dialect/Vector/IR/VectorOps.cpp#L56-L120 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh nice, although I don't think this would be something we should run as a folder, given that it might iterate over the elements of an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A canonicalization would be nice because we could turn an all-false transfer_read into a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I would expect this to be a canonicalization. |
||
// Check the corner case of 0-D vectors first. | ||
if (resultType.getRank() == 0) { | ||
assert(getMaskDimSizes().size() == 1 && "invalid sizes for zero rank mask"); | ||
return llvm::cast<IntegerAttr>(getMaskDimSizes()[0]).getInt() == 1; | ||
} | ||
for (const auto [resultSize, intAttr] : | ||
llvm::zip_equal(resultType.getShape(), getMaskDimSizes())) { | ||
int64_t maskDimSize = llvm::cast<IntegerAttr>(intAttr).getInt(); | ||
if (maskDimSize < resultSize) | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// CreateMaskOp | ||
//===----------------------------------------------------------------------===// | ||
|
Uh oh!
There was an error while loading. Please reload this page.