[Mlir-commits] [mlir] [mlir] fix a crash when fold reshpeOp that has a splat operand (#73190) (PR #76321)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Dec 23 23:30:44 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: long.chen (lipracer)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/76321.diff
1 Files Affected:
- (modified) mlir/include/mlir/Dialect/Utils/ReshapeOpsUtils.h (+5-1)
``````````diff
diff --git a/mlir/include/mlir/Dialect/Utils/ReshapeOpsUtils.h b/mlir/include/mlir/Dialect/Utils/ReshapeOpsUtils.h
index 61c929dee0f272..db2b5c147c3527 100644
--- a/mlir/include/mlir/Dialect/Utils/ReshapeOpsUtils.h
+++ b/mlir/include/mlir/Dialect/Utils/ReshapeOpsUtils.h
@@ -93,7 +93,11 @@ static OpFoldResult foldReshapeOp(ReshapeOpTy reshapeOp,
return reshapeSrcOp.getSrc();
// Reshape of a constant can be replaced with a new constant.
if (auto elements = dyn_cast_or_null<DenseElementsAttr>(operands.front())) {
- return elements.reshape(cast<ShapedType>(reshapeOp.getResult().getType()));
+ return elements.isSplat()
+ ? elements.resizeSplat(
+ cast<ShapedType>(reshapeOp.getResult().getType()))
+ : elements.reshape(
+ cast<ShapedType>(reshapeOp.getResult().getType()));
}
return nullptr;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/76321
More information about the Mlir-commits
mailing list