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

Add special cases in the x64 emit_cmp helper #5869

Open
elliottt opened this issue Feb 23, 2023 · 5 comments
Open

Add special cases in the x64 emit_cmp helper #5869

elliottt opened this issue Feb 23, 2023 · 5 comments
Labels
cranelift:area:x64 Issues related to x64 codegen cranelift:E-easy Issues suitable for newcomers to investigate, including Rust newcomers! good first issue Issues that are good for new contributors to tackle!

Comments

@elliottt
Copy link
Member

Feature

The x64 backend has a helper named emit_cmp in inst.isle that is used when emitting comparisons. Currently it will always use x64_cmp to emit the comparison, but for cases of equality comparisons with 0, x64_test would be a better choice. Additionally, the select lowering does not use emit_cmp right now, and could be refactored to do so with this change in place.

Benefit

This will generate better code for cases where emit_cmp is used to compile a use of icmp in the x64 backend.

@elliottt elliottt added good first issue Issues that are good for new contributors to tackle! cranelift:E-easy Issues suitable for newcomers to investigate, including Rust newcomers! cranelift:area:x64 Issues related to x64 codegen labels Feb 23, 2023
meithecatte added a commit to meithecatte/wasmtime that referenced this issue Mar 22, 2023
jameysharp pushed a commit that referenced this issue Mar 27, 2023
* x64: emit_cmp: use x64_test for comparisons with 0

See #5869

* fixup! x64: emit_cmp: use x64_test for comparisons with 0
@jameysharp
Copy link
Contributor

The first part of this issue (using test for comparisons with 0) was finished in #6086, but there's still work to do with simplifying the lowering for Cranelift's select instruction on x86.

@Solo-steven
Copy link
Contributor

Hi @jameysharp I am interested in this issue, I am a beginner to both compiler backend and isle, so I would like to discuss my solution there before I open PR ~

I think the second part of the issue can be solved by adding a helper for lowering select inst.

(decl lower_select_icmp (Type IcmpCondResult Value Value) InstOutput)
(rule (lower_select_icmp ty (IcmpCondResult.Condition flags cc) x y)
      (with_flags flags (cmove_from_values ty cc x y)))

I think we can change the existing rule to use the helper above, form existed code

(rule (lower (has_type ty (select (maybe_uextend (icmp cc a @ (value_type (fits_in_64 a_ty)) b)) x y)))

to use helper above :

(rule (lower (has_type ty (select (maybe_uextend (icmp cc a @ (value_type (fits_in_64 a_ty)) b)) x y)))
      (lower_select_icmp ty (emit_cmp cc a b ) x y))

@cfallin
Copy link
Member

cfallin commented Oct 23, 2023

@Solo-steven your refactor looks reasonable -- we'd be happy to review a PR with this. Thanks!

@sudoHackIn
Copy link

Hi, @cfallin is this issue still actual or should be closed after Solo-steven's pr is merged?

@cfallin
Copy link
Member

cfallin commented Sep 10, 2024

@sudoHackIn the PR above addresed the second bit (select using the helper) but not the first (using test rather than cmp), so this issue should remain open, I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:area:x64 Issues related to x64 codegen cranelift:E-easy Issues suitable for newcomers to investigate, including Rust newcomers! good first issue Issues that are good for new contributors to tackle!
Projects
None yet
Development

No branches or pull requests

5 participants