-
Notifications
You must be signed in to change notification settings - Fork 184
[CIR][MLIR][LoweringThroughMLIR] CIRUnaryOpLowering on float values. #2032
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
base: main
Are you sure you want to change the base?
Conversation
UnaryOpKind Inc, Dec, Plus and Minus can accept float operands, the lowering should also handle those situations.
e8517f6 to
f3e89e6
Compare
| auto One = mlir::arith::ConstantOp::create( | ||
| rewriter, op.getLoc(), mlir::IntegerAttr::get(type, 1)); | ||
| rewriter.replaceOpWithNewOp<mlir::arith::SubIOp>(op, type, input, One); | ||
| addImmediate(op, type, input, -1, rewriter); |
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.
while this is correct, should this emit mlir::arith::SubIOp/mlir::arith::SubFOp instead, since that was the case previously?
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 did this just for keeping the duplicated code minimum. If we use subi, there will be another helper method subImmediate.
Instruction set like RISC-V does not have subi instruction, only addi. so I think this is not a weird choice.
| return rewriter.replaceOpWithNewOp<mlir::arith::AddFOp>(op, type, input, | ||
| imm); | ||
| } | ||
| auto imm = mlir::arith::ConstantOp::create(rewriter, op.getLoc(), |
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.
should we add an assertion that checks if type is an IntegerType before this? not sure if it's a possible case though.
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.
That makes sense! I've added some checks here, thank you!
bruteforceboy
left a comment
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
bcardosolopes
left a comment
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.
Content looks good, but one missing cleanup needed.
| return nullptr; | ||
| } | ||
|
|
||
| mlir::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.
please refactor the content of these two functions, they are almost identical. You could either use templates or pass a lambda for the replace part.
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.
Thanks for the suggestion! Code got refactored to use template.
UnaryOpKind Inc, Dec, Plus and Minus can accept float operands, the lowering should also handle those situations.
Before this commit, the compiler crash when it met float operands.