forked from OSchip/llvm-project
[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
This commit is contained in:
parent
d8ad018869
commit
0180709590
|
@ -365,6 +365,8 @@ def NegOp : ComplexUnaryOp<"neg", [SameOperandsAndResultType]> {
|
|||
}];
|
||||
|
||||
let results = (outs Complex<AnyFloat>:$result);
|
||||
|
||||
let hasFolder = 1;
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
|
@ -124,6 +124,20 @@ OpFoldResult AddOp::fold(ArrayRef<Attribute> operands) {
|
|||
return {};
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// 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
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
|
@ -83,4 +83,14 @@ func.func @complex_add_sub_rhs() -> complex<f32> {
|
|||
%sub = complex.sub %complex1, %complex2 : complex<f32>
|
||||
%add = complex.add %complex2, %sub : complex<f32>
|
||||
return %add : complex<f32>
|
||||
}
|
||||
|
||||
// CHECK-LABEL: func @complex_neg_neg
|
||||
func.func @complex_neg_neg() -> complex<f32> {
|
||||
%complex1 = complex.constant [1.0 : f32, 0.0 : f32] : complex<f32>
|
||||
// CHECK: %[[CPLX:.*]] = complex.constant [1.000000e+00 : f32, 0.000000e+00 : f32] : complex<f32>
|
||||
// CHECK-NEXT: return %[[CPLX:.*]] : complex<f32>
|
||||
%neg1 = complex.neg %complex1 : complex<f32>
|
||||
%neg2 = complex.neg %neg1 : complex<f32>
|
||||
return %neg2 : complex<f32>
|
||||
}
|
Loading…
Reference in New Issue