From 3f07077ff988e4ef870ce3d840391679e9acc03d Mon Sep 17 00:00:00 2001 From: Yuanqiang Liu Date: Thu, 12 Sep 2024 17:04:57 +0800 Subject: [PATCH] [Torch] enhance fold of aten.alias (#3705) --- lib/Dialect/Torch/IR/TorchOps.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Dialect/Torch/IR/TorchOps.cpp b/lib/Dialect/Torch/IR/TorchOps.cpp index d49bcaac2f9c..c4223ae55524 100644 --- a/lib/Dialect/Torch/IR/TorchOps.cpp +++ b/lib/Dialect/Torch/IR/TorchOps.cpp @@ -3505,7 +3505,11 @@ atenBinaryFloatOperatorFoldHelper(ArrayRef operands, // AtenAliasOp //===----------------------------------------------------------------------===// -OpFoldResult AtenAliasOp::fold(FoldAdaptor adaptor) { return getOperand(); } +OpFoldResult AtenAliasOp::fold(FoldAdaptor adaptor) { + if (getOperand().getType() != getResult().getType()) + return {}; + return getOperand(); +} //===----------------------------------------------------------------------===// // AtenFloordivIntOp