Skip to content

[CIR][CIRGen][Builtin][Neon] Lower neon_vqadds_s32 #1200

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 2 commits into from
Dec 9, 2024

Conversation

ghehg
Copy link
Contributor

@ghehg ghehg commented Dec 3, 2024

This can't be simply implemented by our CIR Add via LLVM::AddOp, as it's saturated add.

@ghehg ghehg marked this pull request as ready for review December 3, 2024 15:00
@bcardosolopes
Copy link
Member

Looks like we have LLVM intrinsics for saturating instructions, have you considered changing binop to add a unitattr for saturation? Does the lowering for LLVM saturating intrinsics lead to the same neon instructions?

@bcardosolopes
Copy link
Member

@ghehg
Copy link
Contributor Author

ghehg commented Dec 3, 2024

Looks like we have LLVM intrinsics for saturating instructions, have you considered changing binop to add a unitattr for saturation? Does the lowering for LLVM saturating intrinsics lead to the same neon instructions?

I thought about it, wasn't sure if we're willing to saturation unitattr to BinOp as some kinds (like logical ones) wouldn't care about it.
But if you think it's worth it, certainly it is better approach in my opinion

@ghehg
Copy link
Contributor Author

ghehg commented Dec 3, 2024

@ghehg
Copy link
Contributor Author

ghehg commented Dec 3, 2024

Looks like we have LLVM intrinsics for saturating instructions, have you considered changing binop to add a unitattr for saturation? Does the lowering for LLVM saturating intrinsics lead to the same neon instructions?

Actually, thanks for the point. Surprisingly, LLVM saturating intrinsics does not lead to the neon instruction. It generates more cubersome instruction sequences.

@ghehg ghehg closed this Dec 4, 2024
@ghehg ghehg reopened this Dec 4, 2024
@ghehg
Copy link
Contributor Author

ghehg commented Dec 4, 2024

After talking to @bcardosolopes, implement this with CIR AddOp with saturated attribute. This attribute also applies to kind Sub too. Also in this PR, did some cleanup in BinOp LLVM Lowering as mentioned by @bcardosolopes comments as I understand it in
PR [CIR][Dialect] Add BinOpKind_Max.
So it makes sense to land this PR first, then rebase PR [CIR][Dialect] Add BinOpKind_Max later.

// TODO: Ideally, we should only need to check cir::IntType here.
return mlir::isa<cir::IntType>(type)
? mlir::cast<cir::IntType>(type).isUnsigned()
: mlir::cast<mlir::IntegerType>(type).isUnsigned();
Copy link
Member

Choose a reason for hiding this comment

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

We can actually check for unsigned for mlir::IntegerType too, so perhaps it will be fine to just rely on adaptor type if we need to.

@bcardosolopes bcardosolopes merged commit 21e8647 into llvm:main Dec 9, 2024
6 checks passed
lanza pushed a commit that referenced this pull request Mar 18, 2025
This can't be simply implemented by our CIR Add via LLVM::AddOp, as
i[t's saturated add.](https://godbolt.org/z/MxqGrj6fP)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants