Skip to content

[mlir][complex] Add Integer overflow flag in complex dialect ops #90823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions mlir/include/mlir/Dialect/Complex/IR/ComplexOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,24 @@ class Complex_Op<string mnemonic, list<Trait> traits = []>
// one result, all of which must be complex numbers of the same type.
class ComplexArithmeticOp<string mnemonic, list<Trait> traits = []> :
Complex_Op<mnemonic, traits # [Pure, SameOperandsAndResultType,
Elementwise, DeclareOpInterfaceMethods<ArithFastMathInterface>]> {
let arguments = (ins Complex<AnyFloat>:$lhs, Complex<AnyFloat>:$rhs, DefaultValuedAttr<
Arith_FastMathAttr, "::mlir::arith::FastMathFlags::none">:$fastmath);
Elementwise, DeclareOpInterfaceMethods<ArithFastMathInterface>, DeclareOpInterfaceMethods<ArithIntegerOverflowFlagsInterface>]> {
let arguments = (ins Complex<AnyFloat>:$lhs, Complex<AnyFloat>:$rhs,
DefaultValuedAttr<Arith_FastMathAttr, "::mlir::arith::FastMathFlags::none">:$fastmath,
DefaultValuedAttr<Arith_IntegerOverflowAttr,"::mlir::arith::IntegerOverflowFlags::none">:$overflowFlags);
let results = (outs Complex<AnyFloat>:$result);
let assemblyFormat = "$lhs `,` $rhs (`fastmath` `` $fastmath^)? attr-dict `:` type($result)";
let assemblyFormat = "$lhs `,` $rhs (`fastmath` `` $fastmath^)? (`overflow` `` $overflowFlags^)? attr-dict `:` type($result)";
}

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

//===----------------------------------------------------------------------===//
Expand Down
6 changes: 6 additions & 0 deletions mlir/test/Dialect/Complex/ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,11 @@ func.func @ops(%f: f32) {
// CHECK: complex.bitcast %[[C]]
%i64 = complex.bitcast %complex : complex<f32> to i64

// CHECK: complex.add %[[C]], %[[C]] overflow<nsw> : complex<f32>
%add_intflags = complex.add %complex, %complex overflow<nsw> : complex<f32>

// CHECK: complex.sub %[[C]], %[[C]] overflow<nsw, nuw> : complex<f32>
%sub_intflags = complex.sub %complex, %complex overflow<nsw, nuw> : complex<f32>

return
}
Loading