[mlir][complex] Canonicalize consecutive complex.conj

We can canonicalize consecutive complex.conj just by removing all conjugate operations.

Reviewed By: pifon2a

Differential Revision: https://reviews.llvm.org/D130684
This commit is contained in:
lewuathe 2022-07-29 09:40:57 +09:00
parent 60e12068ff
commit bcd538ab92
3 changed files with 25 additions and 0 deletions

View File

@ -590,6 +590,7 @@ def ConjOp : ComplexUnaryOp<"conj", [SameOperandsAndResultType]> {
}];
let results = (outs Complex<AnyFloat>:$result);
let hasFolder = 1;
}
//===----------------------------------------------------------------------===//

View File

@ -166,6 +166,20 @@ OpFoldResult ExpOp::fold(ArrayRef<Attribute> operands) {
return {};
}
//===----------------------------------------------------------------------===//
// ConjOp
//===----------------------------------------------------------------------===//
OpFoldResult ConjOp::fold(ArrayRef<Attribute> operands) {
assert(operands.size() == 1 && "unary op takes 1 operand");
// complex.conj(complex.conj(a)) -> a
if (auto conjOp = getOperand().getDefiningOp<ConjOp>())
return conjOp.getOperand();
return {};
}
//===----------------------------------------------------------------------===//
// TableGen'd op method definitions
//===----------------------------------------------------------------------===//

View File

@ -113,4 +113,14 @@ func.func @complex_exp_log() -> complex<f32> {
%log = complex.log %complex1 : complex<f32>
%exp = complex.exp %log : complex<f32>
return %exp : complex<f32>
}
// CHECK-LABEL: func @complex_conj_conj
func.func @complex_conj_conj() -> 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>
%conj1 = complex.conj %complex1 : complex<f32>
%conj2 = complex.conj %conj1 : complex<f32>
return %conj2 : complex<f32>
}