Skip to content
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

CIRGen support for __sync_{and,or,xor,nand}_and_fetch builtin #1273

Closed
bcardosolopes opened this issue Jan 9, 2025 · 14 comments
Closed

CIRGen support for __sync_{and,or,xor,nand}_and_fetch builtin #1273

bcardosolopes opened this issue Jan 9, 2025 · 14 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@bcardosolopes
Copy link
Member

add and sub are already supported.

@bcardosolopes bcardosolopes added the good first issue Good for newcomers label Jan 9, 2025
@moar55
Copy link
Contributor

moar55 commented Jan 9, 2025

I would like to take this issue.

@bcardosolopes
Copy link
Member Author

@moar55 neat, assigned to you!

@moar55
Copy link
Contributor

moar55 commented Jan 27, 2025

Hey, I was looking at the previous tests. And was wondering why does sync_op_and_fetch translates to

cir.atomic.fetch(add, {{%.*}} : !cir.ptr<!s8i>, [[VAL0]] : !s8i, seq_cst) fetch_first : !s8i
cir.binop(add, [[RES0]], [[VAL0]]) : !s8i

Wouldn't it be less instructions if fetch_first was not set (and thus the following binop wouldn't be needed.
Or is there a reason for this that I may not be aware of?

@moar55
Copy link
Contributor

moar55 commented Jan 27, 2025

One other thing more related to this task, I don't see the BinOpKind::Nand. Should this be added along with the lowering logic to mlir::llvm?

@bcardosolopes
Copy link
Member Author

Wouldn't it be less instructions if fetch_first was not set (and thus the following binop wouldn't be needed.
Or is there a reason for this that I may not be aware of?

What have you found when you compared to LLVM output from OG? We go about the same

@bcardosolopes
Copy link
Member Author

bcardosolopes commented Jan 29, 2025

One other thing more related to this task, I don't see the BinOpKind::Nand. Should this be added along with the lowering logic to mlir::llvm?

Do you need it as part of implementing anything? If so yes, if just for completeness best we don't.

@moar55
Copy link
Contributor

moar55 commented Feb 6, 2025

One other thing more related to this task, I don't see the BinOpKind::Nand. Should this be added along with the lowering logic to mlir::llvm?

Do you need it as part of implementing anything? If so yes, if just for completeness best we don't.

Yes it seems so, because the allowed binary operations don't contain nand, and you need that for lowering __sync_nand_and_fetch

@moar55
Copy link
Contributor

moar55 commented Feb 6, 2025

Should I maybe create that in its own commit first?

@bcardosolopes
Copy link
Member Author

I suggest the opposite route: first create all variations that currently have binops, after that lands you go about introducing nand and the sync/fetch support. How does that sound?

@moar55
Copy link
Contributor

moar55 commented Feb 6, 2025

Sounds perfectly fine :)

@moar55
Copy link
Contributor

moar55 commented Feb 9, 2025

Actually I realized, that a Nand BinOpKind is not needed and quite unecessary since it doesn't match any real operator in C++. I found an implementation of sync_nand_and_fetch in clang/lib/CodeGen/CGBuiltin.cpp that makes sense to be imitated in the MLIR way.

Lancern pushed a commit that referenced this issue Feb 11, 2025
This addresses #1273.
`Nand` is missing here, as i didn't intuitively know how to implement it
initially.
I think I have figured it out and will push in an upcoming commit.

Co-authored-by: Omar Ibrahim <[email protected]>
bcardosolopes pushed a commit that referenced this issue Feb 19, 2025
@moar55
Copy link
Contributor

moar55 commented Feb 20, 2025

I think this can be closed now.

@bcardosolopes
Copy link
Member Author

Thanks @moar55

@moar55
Copy link
Contributor

moar55 commented Feb 20, 2025

Sure! 😄

lanza pushed a commit that referenced this issue Mar 18, 2025
This addresses #1273.
`Nand` is missing here, as i didn't intuitively know how to implement it
initially.
I think I have figured it out and will push in an upcoming commit.

Co-authored-by: Omar Ibrahim <[email protected]>
lanza pushed a commit that referenced this issue Mar 18, 2025
xlauko pushed a commit to trailofbits/instafix-llvm that referenced this issue Mar 28, 2025
This addresses llvm/clangir#1273.
`Nand` is missing here, as i didn't intuitively know how to implement it
initially.
I think I have figured it out and will push in an upcoming commit.

Co-authored-by: Omar Ibrahim <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants