diff options
| author | lewuathe <lewuathe@me.com> | 2022-06-29 10:32:23 +0200 |
|---|---|---|
| committer | Alexander Belyaev <pifon@google.com> | 2022-06-29 11:11:40 +0200 |
| commit | 01807095902d78313ef454896f34c801513b1d83 (patch) | |
| tree | ad29b2d51c99749724d572d346db8905e2471546 /mlir/lib/Dialect/Complex/IR/ComplexOps.cpp | |
| parent | d8ad018869aeb1ffe40e94ee4d6d377121581083 (diff) | |
[mlir][complex] Canonicalization for consecutive complex.neg
Consecutive complex.neg are redundant so that we can canonicalize them to the original operands.
Reviewed By: pifon2a
Differential Revision: https://reviews.llvm.org/D128781
Diffstat (limited to 'mlir/lib/Dialect/Complex/IR/ComplexOps.cpp')
| -rw-r--r-- | mlir/lib/Dialect/Complex/IR/ComplexOps.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/mlir/lib/Dialect/Complex/IR/ComplexOps.cpp b/mlir/lib/Dialect/Complex/IR/ComplexOps.cpp index 0390a00cf684..00dbb564481e 100644 --- a/mlir/lib/Dialect/Complex/IR/ComplexOps.cpp +++ b/mlir/lib/Dialect/Complex/IR/ComplexOps.cpp @@ -125,6 +125,20 @@ OpFoldResult AddOp::fold(ArrayRef<Attribute> operands) { } //===----------------------------------------------------------------------===// +// NegOp +//===----------------------------------------------------------------------===// + +OpFoldResult NegOp::fold(ArrayRef<Attribute> operands) { + assert(operands.size() == 1 && "unary op takes 1 operand"); + + // complex.neg(complex.neg(a)) -> a + if (auto negOp = getOperand().getDefiningOp<NegOp>()) + return negOp.getOperand(); + + return {}; +} + +//===----------------------------------------------------------------------===// // TableGen'd op method definitions //===----------------------------------------------------------------------===// |
