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

dialects: (llvm) Add a bunch of float methods #3781

Merged
merged 1 commit into from
Jan 27, 2025

Conversation

AntonLydike
Copy link
Collaborator

@AntonLydike AntonLydike commented Jan 23, 2025

Adds the following llvm floating point operations:

  • llvm.fadd
  • llvm.fsub
  • llvm.fmul
  • llvm.fdiv
  • llvm.frem
  • llvm.sitofp
  • llvm.fpext

Closes #3780

I also took the liberty to sort the dialect lists alphabetically

@AntonLydike AntonLydike added the dialects Changes on the dialects label Jan 23, 2025
@AntonLydike AntonLydike self-assigned this Jan 23, 2025
@AntonLydike AntonLydike force-pushed the anton/llvm-float-stuff branch from 47272fd to 73d8169 Compare January 23, 2025 11:12
Copy link

codecov bot commented Jan 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.23%. Comparing base (9e4c872) to head (861f44c).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3781      +/-   ##
==========================================
- Coverage   91.23%   91.23%   -0.01%     
==========================================
  Files         461      461              
  Lines       57445    57480      +35     
  Branches     5546     5547       +1     
==========================================
+ Hits        52411    52441      +30     
- Misses       3612     3616       +4     
- Partials     1422     1423       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alexarice
Copy link
Collaborator

Do we have an mlir integration test for llvm ops? If not I feel it would be useful.

@AntonLydike AntonLydike force-pushed the anton/llvm-float-stuff branch 4 times, most recently from 3a9d650 to 7c83cf7 Compare January 23, 2025 11:43
@AntonLydike
Copy link
Collaborator Author

Do we have an mlir integration test for llvm ops? If not I feel it would be useful.

Added!

@AntonLydike AntonLydike force-pushed the anton/llvm-float-stuff branch 2 times, most recently from 55813c5 to bf4562f Compare January 23, 2025 11:44
@AntonLydike AntonLydike force-pushed the anton/llvm-float-stuff branch 4 times, most recently from bbec3c8 to f9e9a99 Compare January 23, 2025 12:06
@AntonLydike AntonLydike force-pushed the anton/llvm-float-stuff branch 2 times, most recently from 117e9eb to d018456 Compare January 23, 2025 12:12
Copy link
Collaborator

@alexarice alexarice left a comment

Choose a reason for hiding this comment

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

This should be working with assembly format and I'd prefer to get the bugged fixed rather than introducing custom parsing for something that shouldn't need it

@AntonLydike AntonLydike force-pushed the anton/llvm-float-stuff branch from d018456 to f1c4442 Compare January 23, 2025 12:14
@AntonLydike
Copy link
Collaborator Author

This should be working with assembly format and I'd prefer to get the bugged fixed rather than introducing custom parsing for something that shouldn't need it

But it doesn't.

And fixing the assembly format is outside the scope of this PR.

I'm not able to fix the assembly format today.

@AntonLydike AntonLydike force-pushed the anton/llvm-float-stuff branch 3 times, most recently from cb55182 to 8a3c409 Compare January 23, 2025 13:57
@AntonLydike AntonLydike force-pushed the anton/llvm-float-stuff branch from 8a3c409 to 774aee4 Compare January 23, 2025 14:09
@AntonLydike AntonLydike changed the base branch from main to alexarice/default-prop-in-dict January 23, 2025 14:10
@AntonLydike
Copy link
Collaborator Author

Rebased on top of #3783, @alexarice can you okay now?

Copy link
Collaborator

@alexarice alexarice left a comment

Choose a reason for hiding this comment

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

Will leave the parent PR up to give people time to review.



@irdl_op_definition
class SIToFPOp(GenericCastOp):
Copy link
Collaborator

Choose a reason for hiding this comment

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

These are currently very unconstrained but this isn't technically wrong

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it kinda is, you can't cast from a float with this. Added a verify check.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The custom verifier is verify_

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Damn, LinkageAttr also uses the wrong verifier then. Just copied from there as I'm never sure which one to use 🙃

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's different for attributes

@AntonLydike AntonLydike force-pushed the anton/llvm-float-stuff branch from 774aee4 to f256fae Compare January 23, 2025 14:28
Copy link
Collaborator

@alexarice alexarice left a comment

Choose a reason for hiding this comment

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

I'd prefer to either revert to how it was before or check the input and output types with constraints



@irdl_op_definition
class SIToFPOp(GenericCastOp):
Copy link
Collaborator

Choose a reason for hiding this comment

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

The custom verifier is verify_

if not isinstance(self.arg.type, IntegerType):
raise VerifyException("Expected integer type as input")
if not isinstance(self.result.type, AnyFloat):
raise VerifyException("Expected output to be a float")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't really understand why you would check input and output types in a custom verifier

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

because then I can subclass the main conversion thingy class and keep the remaining bits.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The only shared functionality seems to be the assembly format

@alexarice
Copy link
Collaborator

Could you stop resolving discussions please, makes it hard to check what's happened


fastmathFlags = prop_def(FastMathAttr, default_value=FastMathAttr(None))

traits = traits_def(Pure())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please use theSameOperandsAndResultType trait where applicable?
It shouldn't be here, as not all ops that inherit from this base should comply to it.

// float arith:

%fmul = llvm.fmul %f1, %f1 : f32
// CHECK: %{{\d+}} = llvm.fmul %2, %2 : f32
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any reason for not using a pattern capture here (i.e., {{.*}} instead of %2)?

Copy link
Member

Choose a reason for hiding this comment

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

hmm, why are they not %f1 in the first place?

Copy link
Member

Choose a reason for hiding this comment

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

Ah because of mlir-opt

Copy link
Collaborator

Choose a reason for hiding this comment

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

Likely better to use a numeric capture if you really want to avoid hard coding this

Suggested change
// CHECK: %{{\d+}} = llvm.fmul %2, %2 : f32
// CHECK: %{{\d+}} = llvm.fmul %[[#in:]], %[[#in]] : f32

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, that's what I meant :)

Base automatically changed from alexarice/default-prop-in-dict to main January 24, 2025 10:59
@AntonLydike AntonLydike force-pushed the anton/llvm-float-stuff branch from f256fae to 539ee08 Compare January 27, 2025 10:37

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@AntonLydike AntonLydike force-pushed the anton/llvm-float-stuff branch from 539ee08 to 861f44c Compare January 27, 2025 11:00
@AntonLydike AntonLydike merged commit ef0da35 into main Jan 27, 2025
16 checks passed
@AntonLydike AntonLydike deleted the anton/llvm-float-stuff branch January 27, 2025 12:50
oluwatimilehin pushed a commit to oluwatimilehin/xdsl that referenced this pull request Feb 13, 2025
Adds the following llvm floating point operations:

- `llvm.fadd`
- `llvm.fsub`
- `llvm.fmul`
- `llvm.fdiv`
- `llvm.frem`
- `llvm.sitofp`
- `llvm.fpext`

Closes xdslproject#3780 

I also took the liberty to sort the dialect lists alphabetically
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dialects Changes on the dialects
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement missing ops for translating sympy to llvm
5 participants