Skip to content

[mlir][complex] Allow integer element types in complex.constant ops #74564

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

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion mlir/include/mlir/Dialect/Complex/IR/ComplexOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def ConstantOp : Complex_Op<"constant", [
}];

let arguments = (ins ArrayAttr:$value);
let results = (outs Complex<AnyFloat>:$complex);
let results = (outs AnyComplex:$complex);

let assemblyFormat = "$value attr-dict `:` type($complex)";
let hasFolder = 1;
Expand Down
10 changes: 6 additions & 4 deletions mlir/lib/Dialect/Complex/IR/ComplexOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ LogicalResult ConstantOp::verify() {
}

auto complexEltTy = getType().getElementType();
auto re = llvm::dyn_cast<FloatAttr>(arrayAttr[0]);
auto im = llvm::dyn_cast<FloatAttr>(arrayAttr[1]);
if (!re || !im)
return emitOpError("requires attribute's elements to be float attributes");
if (!isa<FloatAttr, IntegerAttr>(arrayAttr[0]) ||
!isa<FloatAttr, IntegerAttr>(arrayAttr[1]))
return emitOpError(
"requires attribute's elements to be float or integer attributes");
auto re = llvm::dyn_cast<TypedAttr>(arrayAttr[0]);
auto im = llvm::dyn_cast<TypedAttr>(arrayAttr[1]);
if (complexEltTy != re.getType() || complexEltTy != im.getType()) {
return emitOpError()
<< "requires attribute's element types (" << re.getType() << ", "
Expand Down
3 changes: 3 additions & 0 deletions mlir/test/Dialect/Complex/ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ func.func @ops(%f: f32) {
// CHECK: complex.constant [1.{{.*}} : f32, -1.{{.*}} : f32] : complex<f32>
%cst_f32 = complex.constant [0.1 : f32, -1.0 : f32] : complex<f32>

// CHECK: complex.constant [true, false] : complex<i1>
%cst_i1 = complex.constant [1 : i1, 0 : i1] : complex<i1>

// CHECK: %[[C:.*]] = complex.create %[[F]], %[[F]] : complex<f32>
%complex = complex.create %f, %f : complex<f32>

Expand Down