[Mlir-commits] [mlir] [mlir][tensor] Fold `tensor.reshape` for dynamic reshape (PR #88961)
Rob Suderman
llvmlistbot at llvm.org
Wed Apr 17 14:36:02 PDT 2024
================
@@ -1580,6 +1580,42 @@ OpFoldResult ReshapeOp::fold(FoldAdaptor adaptor) {
llvm::dyn_cast_if_present<DenseElementsAttr>(adaptor.getSource()),
getResult().getType()))
return reshapedSource;
+
+ auto source = getSource();
+ auto sourceTy = dyn_cast<RankedTensorType>(source.getType());
+ auto resultTy = dyn_cast<RankedTensorType>(getType());
+
+ if (!sourceTy || !resultTy || sourceTy != resultTy)
+ return {};
+
+ if (auto fromElements = getShape().getDefiningOp<tensor::FromElementsOp>()) {
+ auto elements = fromElements.getElements();
+ bool dynamicNoop =
+ sourceTy.getRank() == static_cast<int64_t>(elements.size());
+ for (auto [id, element] : llvm::enumerate(elements)) {
+ if (!dynamicNoop)
----------------
rsuderman wrote:
I reworked the loop to include the check in the loop arguments.
https://github.com/llvm/llvm-project/pull/88961
More information about the Mlir-commits
mailing list