Skip to content

Commit 8feedd5

Browse files
authored
[mlir][linalg] Fix the semantic use of a flag (llvm#90081)
`useInBoundsInsteadOfMasking` was doing the opposite i.e., when set to true; was updating the mask instead of updating the inBounds.
1 parent 5350052 commit 8feedd5

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

mlir/include/mlir/Dialect/Vector/Utils/VectorUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ bool isLinearizableVector(VectorType type);
194194
/// for each dimension of the passed in tensor.
195195
Value createReadOrMaskedRead(OpBuilder &builder, Location loc, Value source,
196196
ArrayRef<int64_t> readShape, Value padValue,
197-
bool useInBoundsInsteadOfMasking = true);
197+
bool useInBoundsInsteadOfMasking);
198198

199199
/// Returns success if `inputVectorSizes` is a valid masking configuraion for
200200
/// given `shape`, i.e., it meets:

mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,11 +1499,11 @@ vectorizeAsTensorPackOp(RewriterBase &rewriter, tensor::PackOp packOp,
14991499
// If the input vector sizes are not provided, then the vector sizes are
15001500
// determined by the result tensor shape. In case the vector sizes aren't
15011501
// provided, we update the inBounds attribute instead of masking.
1502-
bool useInBoundsInsteadOfMasking = true;
1502+
bool useInBoundsInsteadOfMasking = false;
15031503
if (inputVectorSizes.empty()) {
15041504
ArrayRef<int64_t> resultTensorShape = packOp.getDestType().getShape();
15051505
inputVectorSizes = resultTensorShape.take_front(packOp.getSourceRank());
1506-
useInBoundsInsteadOfMasking = false;
1506+
useInBoundsInsteadOfMasking = true;
15071507
}
15081508

15091509
// Create masked TransferReadOp.
@@ -1612,7 +1612,8 @@ vectorizeAsTensorUnpackOp(RewriterBase &rewriter, tensor::UnPackOp unpackOp,
16121612
// to shape of source, then a mask is necessary.
16131613
Value readResult = vector::createReadOrMaskedRead(
16141614
rewriter, loc, unpackOp.getSource(),
1615-
ArrayRef<int64_t>(readMaskShape.begin(), readMaskShape.end()), padValue);
1615+
ArrayRef<int64_t>(readMaskShape.begin(), readMaskShape.end()), padValue,
1616+
/*useInBoundsInsteadOfMasking=*/false);
16161617

16171618
PackingMetadata packMetadata;
16181619
SmallVector<int64_t> lastDimToInsertPosPerm =
@@ -1669,7 +1670,8 @@ vectorizeAsTensorPadOp(RewriterBase &rewriter, tensor::PadOp padOp,
16691670
(void)status; // prevent unused variable warning on non-assert builds
16701671
assert(succeeded(status) && "failed to reify result shapes");
16711672
auto maskedRead = vector::createReadOrMaskedRead(
1672-
rewriter, loc, padOp.getSource(), inputVectorSizes, padValue);
1673+
rewriter, loc, padOp.getSource(), inputVectorSizes, padValue,
1674+
/*useInBoundsInsteadOfMasking=*/false);
16731675
Operation *write = createWriteOrMaskedWrite(
16741676
rewriter, loc, maskedRead, reifiedReturnShapes[0], inputVectorSizes);
16751677
newResults.push_back(write->getResult(0));

mlir/lib/Dialect/Vector/Utils/VectorUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ Value vector::createReadOrMaskedRead(OpBuilder &builder, Location loc,
345345
int64_t readRank = readShape.size();
346346
auto zero = builder.create<arith::ConstantIndexOp>(loc, 0);
347347
SmallVector<bool> inBoundsVal(readRank, true);
348-
if (!useInBoundsInsteadOfMasking) {
348+
if (useInBoundsInsteadOfMasking) {
349349
// Update the inBounds attribute.
350350
for (unsigned i = 0; i < readRank; i++)
351351
inBoundsVal[i] = (sourceShape[i] == readShape[i]) &&
@@ -359,7 +359,7 @@ Value vector::createReadOrMaskedRead(OpBuilder &builder, Location loc,
359359
/*padding=*/padValue,
360360
/*inBounds=*/inBoundsVal);
361361

362-
if (llvm::equal(readShape, sourceShape) || !useInBoundsInsteadOfMasking)
362+
if (llvm::equal(readShape, sourceShape) || useInBoundsInsteadOfMasking)
363363
return transferReadOp;
364364
SmallVector<OpFoldResult> mixedSourceDims =
365365
tensor::getMixedSizes(builder, loc, source);

0 commit comments

Comments
 (0)