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

cranelift/x64: Optimize i128 comparisons #8427

Merged
merged 1 commit into from Apr 22, 2024

Conversation

jameysharp
Copy link
Contributor

Inequality comparisons between i128 values were previously eight instructions and this reduces them to two, plus one move if one of the inputs is still live afterward.

Equality comparisons were six instructions and are now three, plus up to two moves if both inputs are still live afterward.

This removes 45 instructions from the test in x64/i128.clif that generates all possible i128 comparisons. In addition to using fewer instructions for each comparison, it also reduces register pressure enough that the function no longer spills.

Conditional branches on i128 values are a special case but similar optimizations shrink them from six instructions to two.

This brings Cranelift in line with what rustc+LLVM generates for equivalent 128-bit comparisons.

This PR probably conflicts with #8421 in the filetest output; I'll rebase whichever one doesn't land first.

Inequality comparisons between i128 values were previously eight
instructions and this reduces them to two, plus one move if one of the
inputs is still live afterward.

Equality comparisons were six instructions and are now three, plus up to
two moves if both inputs are still live afterward.

This removes 45 instructions from the test in x64/i128.clif that
generates all possible i128 comparisons. In addition to using fewer
instructions for each comparison, it also reduces register pressure
enough that the function no longer spills.

Conditional branches on i128 values are a special case but similar
optimizations shrink them from six instructions to two.

This brings Cranelift in line with what rustc+LLVM generates for
equivalent 128-bit comparisons.
@jameysharp jameysharp requested a review from a team as a code owner April 22, 2024 01:45
@jameysharp jameysharp requested review from fitzgen and removed request for a team April 22, 2024 01:45
@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:area:x64 Issues related to x64 codegen labels Apr 22, 2024
Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

Do we cover this in run tests and/or the fuzzer? Seems like a good time to double check that we do.

@jameysharp
Copy link
Contributor Author

We do cover this in runtests, and I know this because I got it wrong several times in ways that the runtests caught. 😁

I think we also cover it in the Cranelift fuzz targets but I don't remember for sure.

@jameysharp jameysharp added this pull request to the merge queue Apr 22, 2024
Merged via the queue into bytecodealliance:main with commit 4fa2330 Apr 22, 2024
23 checks passed
@jameysharp jameysharp deleted the simplify-x64-i128 branch April 22, 2024 20:25
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 Issues related to the Cranelift code generator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants