[Mlir-commits] [mlir] [mlir] Do not bufferize parallel_insert_slice dest to read for full slices (PR #112761)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Oct 18 07:38:34 PDT 2024
================
@@ -636,6 +637,34 @@ struct InsertOpInterface
}
};
+template <typename InsertOpTy>
+static bool insertSliceOpRequiresRead(InsertOpTy insertSliceOp,
+ OpOperand &opOperand) {
+ RankedTensorType destType = insertSliceOp.getDestType();
+
+ // The source is always read.
+ if (opOperand == insertSliceOp.getSourceMutable())
+ return true;
+
+ // For the destination, it depends...
+ assert(opOperand == insertSliceOp.getDestMutable() && "expected dest");
+
+ // Dest is not read if it is entirely overwritten. E.g.:
+ // tensor.insert_slice %a into %t[0][10][1] : ... into tensor<10xf32>
+ bool allOffsetsZero =
+ llvm::all_of(insertSliceOp.getMixedOffsets(),
+ [](OpFoldResult ofr) { return isConstantIntValue(ofr, 0); });
+ bool sizesMatchDestSizes = llvm::all_of(
+ llvm::enumerate(insertSliceOp.getMixedSizes()), [&](const auto &it) {
+ return getConstantIntValue(it.value()) ==
+ destType.getDimSize(it.index());
+ });
+ bool allStridesOne =
+ llvm::all_of(insertSliceOp.getMixedStrides(),
+ [](OpFoldResult ofr) { return isConstantIntValue(ofr, 1); });
----------------
Max191 wrote:
I opted to add two new StaticValueUtils `areConstantIntValues` and `areAllConstantIntValue`. I have wished such functions were available downstream on occasion as well, so I think they are both nice to have. WDYT?
https://github.com/llvm/llvm-project/pull/112761
More information about the Mlir-commits
mailing list