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
//===----------------------------------------------------------------------===//
%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>
}
\ No newline at end of file