-
Notifications
You must be signed in to change notification settings - Fork 131
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
[CIR] Add support for complex cast operations #758
Conversation
return builder | ||
.create<mlir::cir::TernaryOp>( | ||
op.getLoc(), srcRealToBool, | ||
[&](mlir::OpBuilder &, mlir::Location) { | ||
builder.createYield(op.getLoc(), | ||
builder.getTrue(op.getLoc()).getResult()); | ||
}, | ||
[&](mlir::OpBuilder &, mlir::Location) { | ||
auto inner = | ||
builder | ||
.create<mlir::cir::TernaryOp>( | ||
op.getLoc(), srcImagToBool, | ||
[&](mlir::OpBuilder &, mlir::Location) { | ||
builder.createYield( | ||
op.getLoc(), | ||
builder.getTrue(op.getLoc()).getResult()); | ||
}, | ||
[&](mlir::OpBuilder &, mlir::Location) { | ||
builder.createYield( | ||
op.getLoc(), | ||
builder.getFalse(op.getLoc()).getResult()); | ||
}) | ||
.getResult(); | ||
builder.createYield(op.getLoc(), inner); | ||
}) | ||
.getResult(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the first time I write code like these to implement a simple boolean binary op like a && b
or a || b
. I think a dedicated operation for binary logical operations are really necessary and they allow generation of much better LLVM IR, although these operations won't be generated from CIRGen directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have gone through the same feeling, we need a ternary that's basically a select operation. If you wanna add that it would be a great addition. cir.ternary_select
or something, then a fold operation can even transform a cir.ternary
into cir.ternary_select
to handle all really simple cases like this one (some CIRGen will use generic code and might emit this pattern regardless of cases we actually know we want a select-like op).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have gone through the same feeling, we need a ternary that's basically a select operation.
Do we additionally need a boolean binary op, something like cir.binop logical_and
? This is preferable to me since it lowers to different code with select operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how usable this would be, given that usually those have short-circuiting semantics. We have folders and other transformations passes that can help out with this, have you explored any of those solutions already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's track this in #785 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nit on testcase
Rebased onto the latest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some remaining conflict but other than that good to go
This patch adds support for complex cast operations. It adds the following new cast kind variants to the `cir.cast` operation: - `float_to_complex`, - `int_to_complex`, - `float_complex_to_real`, - `int_complex_to_real`, - `float_complex_to_bool`, - `int_complex_to_bool`, - `float_complex`, - `float_complex_to_int_complex`, - `int_complex`, and - `int_complex_to_float_complex`. CIRGen and LLVM IR support for these new cast variants are also included.
Rebased onto the latest |
This PR adds support for complex cast operations. It adds the following new cast kind variants to the `cir.cast` operation: - `float_to_complex`, - `int_to_complex`, - `float_complex_to_real`, - `int_complex_to_real`, - `float_complex_to_bool`, - `int_complex_to_bool`, - `float_complex`, - `float_complex_to_int_complex`, - `int_complex`, and - `int_complex_to_float_complex`. CIRGen and LLVM IR support for these new cast variants are also included.
This PR adds support for complex cast operations. It adds the following new cast kind variants to the `cir.cast` operation: - `float_to_complex`, - `int_to_complex`, - `float_complex_to_real`, - `int_complex_to_real`, - `float_complex_to_bool`, - `int_complex_to_bool`, - `float_complex`, - `float_complex_to_int_complex`, - `int_complex`, and - `int_complex_to_float_complex`. CIRGen and LLVM IR support for these new cast variants are also included.
This PR adds support for complex cast operations. It adds the following new cast kind variants to the `cir.cast` operation: - `float_to_complex`, - `int_to_complex`, - `float_complex_to_real`, - `int_complex_to_real`, - `float_complex_to_bool`, - `int_complex_to_bool`, - `float_complex`, - `float_complex_to_int_complex`, - `int_complex`, and - `int_complex_to_float_complex`. CIRGen and LLVM IR support for these new cast variants are also included.
This PR adds support for complex cast operations. It adds the following new cast kind variants to the `cir.cast` operation: - `float_to_complex`, - `int_to_complex`, - `float_complex_to_real`, - `int_complex_to_real`, - `float_complex_to_bool`, - `int_complex_to_bool`, - `float_complex`, - `float_complex_to_int_complex`, - `int_complex`, and - `int_complex_to_float_complex`. CIRGen and LLVM IR support for these new cast variants are also included.
This PR adds support for complex cast operations. It adds the following new cast kind variants to the `cir.cast` operation: - `float_to_complex`, - `int_to_complex`, - `float_complex_to_real`, - `int_complex_to_real`, - `float_complex_to_bool`, - `int_complex_to_bool`, - `float_complex`, - `float_complex_to_int_complex`, - `int_complex`, and - `int_complex_to_float_complex`. CIRGen and LLVM IR support for these new cast variants are also included.
This PR adds support for complex cast operations. It adds the following new cast kind variants to the
cir.cast
operation:float_to_complex
,int_to_complex
,float_complex_to_real
,int_complex_to_real
,float_complex_to_bool
,int_complex_to_bool
,float_complex
,float_complex_to_int_complex
,int_complex
, andint_complex_to_float_complex
.CIRGen and LLVM IR support for these new cast variants are also included.