@@ -1659,9 +1659,10 @@ createWriteOrMaskedWrite(OpBuilder &builder, Location loc, Value vectorToStore,
1659
1659
static_cast <size_t >(vecToStoreType.getRank ()) &&
1660
1660
" Insufficient number of input vector sizes!" );
1661
1661
// Update the inBounds attribute.
1662
- for (unsigned i = 0 ; i < destRank; i++)
1663
- inBoundsVal[i] = (destShape[i] == inputVecSizesForLeadingDims[i]) &&
1664
- !ShapedType::isDynamic (destShape[i]);
1662
+ for (unsigned i = 0 ; i < vecToStoreRank; i++)
1663
+ inBoundsVal[i] =
1664
+ (destShape[i] == inputVecSizesForLeadingDims[i]) &&
1665
+ !ShapedType::isDynamic (destShape[destRank - vecToStoreRank + i]);
1665
1666
}
1666
1667
1667
1668
// If missing, initialize the write indices to 0.
@@ -1670,7 +1671,7 @@ createWriteOrMaskedWrite(OpBuilder &builder, Location loc, Value vectorToStore,
1670
1671
" Invalid number of write indices!" );
1671
1672
if (writeIndices.empty ()) {
1672
1673
auto zero = builder.create <arith::ConstantIndexOp>(loc, 0 );
1673
- writeIndices = SmallVector<Value> (destRank, zero);
1674
+ writeIndices. assign (destRank, zero);
1674
1675
}
1675
1676
1676
1677
// Generate the xfer_write Op
@@ -1826,8 +1827,7 @@ vectorizeAsTensorPackOp(RewriterBase &rewriter, linalg::PackOp packOp,
1826
1827
transposeOp.getResult ().getType ().getElementType ());
1827
1828
Operation *write = createWriteOrMaskedWrite (
1828
1829
rewriter, loc, transposeOp.getResult (), dest,
1829
- /* inputVecSizesForLeadingDims=*/ inputVectorSizes, /* writeIndices=*/ {},
1830
- /* useInBoundsInsteadOfMasking=*/ false );
1830
+ /* inputVecSizesForLeadingDims=*/ inputVectorSizes);
1831
1831
newResults.push_back (write->getResult (0 ));
1832
1832
return success ();
1833
1833
}
@@ -2000,8 +2000,7 @@ vectorizeAsTensorPadOp(RewriterBase &rewriter, tensor::PadOp padOp,
2000
2000
loc, reifiedReturnShapes[0 ], padOp.getResultType ().getElementType ());
2001
2001
Operation *write = createWriteOrMaskedWrite (
2002
2002
rewriter, loc, maskedRead, dest,
2003
- /* inputVecSizesForLeadingDims=*/ inputVectorSizes, {},
2004
- /* useInBoundsInsteadOfMasking=*/ false );
2003
+ /* inputVecSizesForLeadingDims=*/ inputVectorSizes);
2005
2004
newResults.push_back (write->getResult (0 ));
2006
2005
return success ();
2007
2006
}
@@ -3007,39 +3006,24 @@ vectorizeAsInsertSliceOp(RewriterBase &rewriter, tensor::InsertSliceOp sliceOp,
3007
3006
sliceOp.getLoc (), elemType, rewriter.getZeroAttr (elemType));
3008
3007
}
3009
3008
3010
- // 2. Get the vector shape and in-bounds attributes
3009
+ // 2. Get the vector shape
3011
3010
SmallVector<int64_t > vecShape;
3012
- SmallVector<bool > readInBounds;
3013
- SmallVector<bool > writeInBounds;
3014
3011
size_t rankDiff = resultType.getRank () - sourceType.getRank ();
3015
3012
for (int64_t i = 0 , end = sourceType.getRank (); i < end; ++i) {
3016
3013
if (!inputVectorSizes.empty ()) {
3017
3014
vecShape.push_back (inputVectorSizes[i]);
3018
- readInBounds.push_back (false );
3019
- writeInBounds.push_back (false );
3020
3015
} else if (!sourceType.isDynamicDim (i)) {
3021
3016
vecShape.push_back (sourceType.getDimSize (i));
3022
- // Source shape is statically known: Neither read nor write are
3023
- // out-of-bounds.
3024
- readInBounds.push_back (true );
3025
- writeInBounds.push_back (true );
3026
3017
} else if (!resultType.isDynamicDim (i)) {
3027
3018
// Source shape is not statically known, but result shape is.
3028
3019
// Vectorize with size of result shape. This may be larger than the
3029
3020
// source size.
3030
3021
// FIXME: Using rankDiff implies that the source tensor is inserted at
3031
3022
// the end of the destination tensor. However, that's not required.
3032
3023
vecShape.push_back (resultType.getDimSize (rankDiff + i));
3033
- // Read may be out-of-bounds because the result size could be larger
3034
- // than the source size.
3035
- readInBounds.push_back (false );
3036
- // Write will be in-bounds provided that the corresponding write idx is 0.
3037
- // To keep this logic simple, conservatively mark as out-of-bounds.
3038
- writeInBounds.push_back (false );
3039
3024
} else {
3040
3025
// Neither source nor result dim of padOp is static. Cannot vectorize
3041
3026
// the copy.
3042
- // TODO: Add support for masking
3043
3027
return failure ();
3044
3028
}
3045
3029
}
@@ -3052,13 +3036,15 @@ vectorizeAsInsertSliceOp(RewriterBase &rewriter, tensor::InsertSliceOp sliceOp,
3052
3036
SmallVector<Value> readIndices (
3053
3037
vecType.getRank (), rewriter.create <arith::ConstantIndexOp>(loc, 0 ));
3054
3038
Value read = mlir::vector::createReadOrMaskedRead (
3055
- rewriter, loc, source, vecType.getShape (), padValue);
3039
+ rewriter, loc, source, vecType.getShape (), padValue,
3040
+ /* useInBoundsInsteadOfMasking=*/ inputVectorSizes.empty ());
3056
3041
3057
3042
// Create write
3058
3043
auto writeIndices =
3059
3044
getValueOrCreateConstantIndexOp (rewriter, loc, sliceOp.getMixedOffsets ());
3060
3045
Operation *write = createWriteOrMaskedWrite (
3061
- rewriter, loc, read, sliceOp.getDest (), vecType.getShape (), writeIndices);
3046
+ rewriter, loc, read, sliceOp.getDest (), vecType.getShape (), writeIndices,
3047
+ /* useInBoundsInsteadOfMasking=*/ inputVectorSizes.empty ());
3062
3048
3063
3049
// 4. Finalize
3064
3050
newResults.push_back (write->getResult (0 ));
0 commit comments