Skip to content

Conversation

@terapines-osc-cir
Copy link
Contributor

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.

UnaryOpKind Inc, Dec, Plus and Minus can accept float operands, the lowering should also handle those situations.
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);
Copy link
Contributor

@bruteforceboy bruteforceboy Nov 28, 2025

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?

Copy link
Contributor Author

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(),
Copy link
Contributor

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.

Copy link
Contributor Author

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!

Copy link
Contributor

@bruteforceboy bruteforceboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@bcardosolopes bcardosolopes left a 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 *
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants