-
Notifications
You must be signed in to change notification settings - Fork 80
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: (riscv) add fastmath flag to RdRsRs Float Float Int operations #3276
Conversation
3e230b3
to
1af6acd
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3276 +/- ##
=======================================
Coverage 90.01% 90.01%
=======================================
Files 445 445
Lines 55850 55926 +76
Branches 5372 5358 -14
=======================================
+ Hits 50272 50341 +69
- Misses 4169 4177 +8
+ Partials 1409 1408 -1 ☔ View full report in Codecov by Sentry. |
1af6acd
to
4c18a73
Compare
xdsl/dialects/riscv.py
Outdated
@@ -2491,6 +2491,7 @@ class LiOp(RISCVInstruction, ABC): | |||
|
|||
rd = result_def(IntRegisterType) | |||
immediate = attr_def(base(Imm32Attr) | base(LabelAttr)) | |||
fastmath = opt_attr_def(FastMathFlagsAttr) |
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.
Is there a specific reason this is an attribute here where it was a property on the other PR?
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 would recommend changing to a property here
xdsl/dialects/riscv.py
Outdated
@@ -2527,12 +2530,19 @@ def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]: | |||
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]: | |||
attributes = dict[str, Attribute]() | |||
attributes["immediate"] = parse_immediate_value(parser, i32) | |||
fast = FastMathFlagsAttr("none") |
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.
Is this flag meant to be optional? It seems you can't parse it with the flag unset?
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.
As on the other PR, it's not meant to be optional, op_prop_def
just doesn't actually use the default
parameter at all, so parsing fails when it's set as a non-opt
prop_def
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 would recommend making it non-optional, and to do the default value handling manually. What's the error when you change the declaration to prop_def
?
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 guess this is more a question for the equivalent line below, if we're removing the LiOp changes
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.
# | raise VerifyException(f"property {prop_name} expected")
# | xdsl.utils.exceptions.VerifyException: property fastmath expected
That's the error I get, even with setting a default via `fastmath = prop_def(FastMathFlagsAttr, default=FastMathFlagsAttr("none")) (which also doesn't typecheck)
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.
yep, the default field here doesn't work. I think @alexarice is now looking into this, but for the time being we can just set it directly in the init and in the custom parser. So all that would be necessary in this PR is to change opt_prop_def
to prop_def
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've just pushed a commit that does exactly that, but it's failing the filecheck test with the same error as above. Is there something else I need to do ? I am setting the fastmath
property in both the parse and init methods
xdsl/dialects/riscv.py
Outdated
rd = result_def(IntRegisterType) | ||
rs1 = operand_def(FloatRegisterType) | ||
rs2 = operand_def(FloatRegisterType) | ||
fastmath = opt_attr_def(FastMathFlagsAttr) |
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.
Similar comments here about attr/prop and this being optional
xdsl/dialects/riscv.py
Outdated
@@ -2491,6 +2491,7 @@ class LiOp(RISCVInstruction, ABC): | |||
|
|||
rd = result_def(IntRegisterType) | |||
immediate = attr_def(base(Imm32Attr) | base(LabelAttr)) | |||
fastmath = opt_attr_def(FastMathFlagsAttr) |
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.
What is the semantics change of li being optionally fastmath?
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.
Probably worth documenting
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 spent a while trying to find any information on this, and I'm not seeing that there is any actual effect on the li
instr at all when compiled with fastmath. Chapter 15. Load Immediate
of the riscv-asm-manual doesn't mention fastmath at all, and godbolt doesn't seem to show any difference when compiled with/without -ffast-math
.
Is there anywhere else that I should look for information on this? If not, should I go ahead and remove the fastmath
attribute from LiOp
?
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 also don't know how it would affect anything. I don't think arith.constant can have fastmath, can it? It seems safe to remove from this PR, and add it later if we find a way to leverage it.
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've removed it now, and rebased everything into one commit since it was getting messy
Ok thanks, will do this stuff this evening hopefully Need to:
|
52a5eaa
to
7e647e4
Compare
…, with filecheck test
7e647e4
to
6474cd1
Compare
11cebbd
to
729668d
Compare
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.
Thank you!
…ons (xdslproject#3276) `riscv`-only part of xdslproject#3272, with a new dialect test added. Thanks for the suggestion of separate tests, I didn't realize those existed and caught an error in the LiOp implementation while adding the test cases.
`backend`(lowering)-only part of xdslproject#3272. Depends on xdslproject#3275 and xdslproject#3276. This should close xdslproject#2725 once merged Co-authored-by: Sasha Lopoukhine <superlopuh@gmail.com>
riscv
-only part of #3272, with a new dialect test added. Thanks for the suggestion of separate tests, I didn't realize those existed and caught an error in the LiOp implementation while adding the test cases.