[Mlir-commits] [mlir] [mlir][tensor] Fold `tensor.reshape` for dynamic reshape (PR #88961)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Apr 17 11:27:45 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)
----------------
MaheshRavishankar wrote:
Still strange that if the condition at 1593 is false to start with , it will enter the loop and break immediately.
https://github.com/llvm/llvm-project/pull/88961
More information about the Mlir-commits
mailing list