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

misc: fix arguments for riscv_lowering #3900

Merged
merged 10 commits into from
Feb 15, 2025

Conversation

oluwatimilehin
Copy link
Contributor

@oluwatimilehin oluwatimilehin commented Feb 13, 2025

@superlopuh Fixing some potential bugs I encountered while using xDSL as a backend

@oluwatimilehin oluwatimilehin marked this pull request as draft February 13, 2025 15:46
@oluwatimilehin oluwatimilehin marked this pull request as ready for review February 13, 2025 15:46
@@ -80,7 +80,7 @@ def match_and_rewrite(self, op: func.CallOp, rewriter: PatternRewriter) -> None:
new_result_types = list(a_regs(op.results))
new_op = riscv_func.CallOp(op.callee, moved_operands, new_result_types)
move_result_ops, moved_results = move_to_unallocated_regs(
new_op.results, operand_types
new_op.results, new_result_types
Copy link
Collaborator

Choose a reason for hiding this comment

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

this looks like a bug? maybe our funcs were void so far? could you please add a test case for this?
let us know if you need a hand

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey Chris, how would you recommend I test this? It looks like I need to modify line 6 here, but I am not sure how to exercise this change and don't remember how I encountered the bug :(

What do you have in mind?

Copy link
Member

Choose a reason for hiding this comment

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

Just modifying it to be (i32, f32) -> (i64, f64) should be enough

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean doing this:

    func.func @main() {
        %0, %1 = "test.op"() : () -> (i32, f32)
        %2, %3 = func.call @foo(%0, %1) : (i32, f32) -> (i64, f64)
        func. return
    }

Which I suppose will require changing foo() too to accept an f32 type:

    func.func @foo(%arg0 : i32, %arg1 : i32) -> (i32, i32) {
        %res0, %res1 = "test.op"(%arg0, %arg1) : (i32, i32) -> (i32, i32)
        func.return %res0, %res1 : i32, i32
    }

Is that right?

Copy link
Member

Choose a reason for hiding this comment

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

yeah these would all have to be consistent within the file but that's the essence of the change

Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks for splitting the PRs btw

Copy link

codecov bot commented Feb 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.29%. Comparing base (7be8c6f) to head (d5b7415).
Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3900      +/-   ##
==========================================
+ Coverage   91.26%   91.29%   +0.03%     
==========================================
  Files         466      466              
  Lines       57960    58012      +52     
  Branches     5567     5566       -1     
==========================================
+ Hits        52897    52962      +65     
+ Misses       3639     3622      -17     
- Partials     1424     1428       +4     

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

@oluwatimilehin oluwatimilehin changed the title misc: fix arguments for riscv_lowering and linalg conversion misc: fix arguments for riscv_lowering Feb 13, 2025
@compor compor added the backend Compiler backend in xDSL label Feb 14, 2025
@@ -77,10 +77,13 @@ def match_and_rewrite(self, op: func.CallOp, rewriter: PatternRewriter) -> None:
move_operand_ops, moved_operands = move_to_a_regs(
register_operands, operand_types
)

new_result_value_types = [result.type for result in op.results]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This fixes a bug here that makes it raise an error for floating point registers:

elif isinstance(rd, riscv.FloatRegisterType):
match value_type:
case builtin.Float64Type():
mv_op = riscv.FMvDOp(value, rd=rd)
case builtin.Float32Type():
mv_op = riscv.FMVOp(value, rd=rd)
case _:
raise NotImplementedError(
f"Move operation for float register containing value of type {value.type} is not implemented"
)
return mv_op, mv_op.rd

value_type in the original code is neither of the two.

Copy link
Member

Choose a reason for hiding this comment

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

what is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a FloatRegisterType.

@superlopuh superlopuh merged commit 887391b into xdslproject:main Feb 15, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Compiler backend in xDSL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants