rust-lang / rust-lang/rust

Missing carry-optimization for subtraction on aarch64

Open
#121,566 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-LLVM C-optimization O-AArch64 S-has-mcve T-compiler
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

The compiler fails to optimize "sub-with-borrow" on aarch64 as demonstrated here:

https://godbolt.org/z/5MPxbfzsM

In more detail:

When adding big-integers, we would like the compiler to utilize "add-with-carry" instructions. Similarly for subtraction, we would like to utilize "sub-with-borrow". This works fine on x86_64 for both addition and subtraction, but on aarch64, only addition will utilize the carry-instructions. Subtraction on aarch64 fails to optimize and will use "cset" and "ccmp" instructions, where-as in the above link, the optimal assembly should be along "subs, sbcs, sbcs, sbcs".

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Godbolt reproduction linked in the issue and compare the AArch64 subtraction output with the expected subs/sbcs sequence and the working x86_64 behavior. Trace the Rust compiler's AArch64 lowering for subtraction with borrow; done when the generated code uses the carry instructions instead of cset and ccmp for the demonstrated case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.