Skip to content

Commit 3bcec8c

Browse files
committed
[mlir][complex] Integer overflow flag in complex dialect ops
1 parent b86e099 commit 3bcec8c

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

mlir/include/mlir/Dialect/Complex/IR/ComplexOps.td

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,24 @@ class Complex_Op<string mnemonic, list<Trait> traits = []>
2424
// one result, all of which must be complex numbers of the same type.
2525
class ComplexArithmeticOp<string mnemonic, list<Trait> traits = []> :
2626
Complex_Op<mnemonic, traits # [Pure, SameOperandsAndResultType,
27-
Elementwise, DeclareOpInterfaceMethods<ArithFastMathInterface>]> {
28-
let arguments = (ins Complex<AnyFloat>:$lhs, Complex<AnyFloat>:$rhs, DefaultValuedAttr<
29-
Arith_FastMathAttr, "::mlir::arith::FastMathFlags::none">:$fastmath);
27+
Elementwise, DeclareOpInterfaceMethods<ArithFastMathInterface>, DeclareOpInterfaceMethods<ArithIntegerOverflowFlagsInterface>]> {
28+
let arguments = (ins Complex<AnyFloat>:$lhs, Complex<AnyFloat>:$rhs,
29+
DefaultValuedAttr<Arith_FastMathAttr, "::mlir::arith::FastMathFlags::none">:$fastmath,
30+
DefaultValuedAttr<Arith_IntegerOverflowAttr,"::mlir::arith::IntegerOverflowFlags::none">:$overflowFlags);
3031
let results = (outs Complex<AnyFloat>:$result);
31-
let assemblyFormat = "$lhs `,` $rhs (`fastmath` `` $fastmath^)? attr-dict `:` type($result)";
32+
let assemblyFormat = "$lhs `,` $rhs (`fastmath` `` $fastmath^)? (`overflow` `` $overflowFlags^)? attr-dict `:` type($result)";
3233
}
3334

3435
// Base class for standard unary operations on complex numbers with a
3536
// floating-point element type. These operations take one operand and return
3637
// one result; the operand must be a complex number.
3738
class ComplexUnaryOp<string mnemonic, list<Trait> traits = []> :
38-
Complex_Op<mnemonic, traits # [Pure, Elementwise, DeclareOpInterfaceMethods<ArithFastMathInterface>]> {
39-
let arguments = (ins Complex<AnyFloat>:$complex, DefaultValuedAttr<
40-
Arith_FastMathAttr, "::mlir::arith::FastMathFlags::none">:$fastmath);
41-
let assemblyFormat = "$complex (`fastmath` `` $fastmath^)? attr-dict `:` type($complex)";
39+
Complex_Op<mnemonic, traits # [Pure, Elementwise,
40+
DeclareOpInterfaceMethods<ArithFastMathInterface>, DeclareOpInterfaceMethods<ArithIntegerOverflowFlagsInterface>]> {
41+
let arguments = (ins Complex<AnyFloat>:$complex,
42+
DefaultValuedAttr<Arith_FastMathAttr, "::mlir::arith::FastMathFlags::none">:$fastmath,
43+
DefaultValuedAttr<Arith_IntegerOverflowAttr,"::mlir::arith::IntegerOverflowFlags::none">:$overflowFlags);
44+
let assemblyFormat = "$complex (`fastmath` `` $fastmath^)? (`overflow` `` $overflowFlags^)? attr-dict `:` type($complex)";
4245
}
4346

4447
//===----------------------------------------------------------------------===//

mlir/test/Dialect/Complex/ops.mlir

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,11 @@ func.func @ops(%f: f32) {
8989
// CHECK: complex.bitcast %[[C]]
9090
%i64 = complex.bitcast %complex : complex<f32> to i64
9191

92+
// CHECK: complex.add %[[C]], %[[C]] overflow<nsw> : complex<f32>
93+
%add_intflags = complex.add %complex, %complex overflow<nsw> : complex<f32>
94+
95+
// CHECK: complex.sub %[[C]], %[[C]] overflow<nsw, nuw> : complex<f32>
96+
%sub_intflags = complex.sub %complex, %complex overflow<nsw, nuw> : complex<f32>
97+
9298
return
9399
}

0 commit comments

Comments
 (0)