Don't use usub.with.overflow intrinsic by nikic · Pull Request #103299 · rust-lang/rust (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation14 Commits1 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

nikic

The canonical form of a usub.with.overflow check in LLVM are separate sub + icmp instructions, rather than a usub.with.overflow intrinsic. Using usub.with.overflow will generally result in worse optimization potential.

The backend will attempt to form usub.with.overflow when it comes to actual instruction selection. This is not fully reliable, but I believe this is a better tradeoff than using the intrinsic in IR.

Fixes #103285.

@nikic

The canonical form of a usub.with.overflow check in LLVM are separate sub + icmp instructions, rather than a usub.with.overflow intrinsic. Using usub.with.overflow will generally result in worse optimization potential.

The backend will attempt to form usub.with.overflow when it comes to actual instruction selection. This is not fully reliable, but I believe this is a better tradeoff than using the intrinsic in IR.

Fixes rust-lang#103285.

@rustbot rustbot added A-testsuite

Area: The testsuite used to check the correctness of rustc

T-compiler

Relevant to the compiler team, which will review and decide on the PR/issue.

labels

Oct 20, 2022

@rust-highfive

r? @wesleywiser

(rust-highfive has picked a reviewer for you, use r? to override)

@nikic nikic mentioned this pull request

Oct 20, 2022

@nikic

@rust-timer

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@bors

⌛ Trying commit 7833012 with merge 9e5787ab4583e67d16150a014f6c118dfa47ab43...

@bors

☀️ Try build successful - checks-actions
Build commit: 9e5787ab4583e67d16150a014f6c118dfa47ab43 (9e5787ab4583e67d16150a014f6c118dfa47ab43)

@rust-timer

@rust-timer

Finished benchmarking commit (9e5787ab4583e67d16150a014f6c118dfa47ab43): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌ (primary) - - 0
Regressions ❌ (secondary) 2.5% [2.5%, 2.5%] 1
Improvements ✅ (primary) - - 0
Improvements ✅ (secondary) - - 0
All ❌✅ (primary) - - 0

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌ (primary) - - 0
Regressions ❌ (secondary) - - 0
Improvements ✅ (primary) - - 0
Improvements ✅ (secondary) -2.3% [-2.3%, -2.3%] 1
All ❌✅ (primary) - - 0

Footnotes

  1. the arithmetic mean of the percent change ↩2
  2. number of relevant changes ↩2

wesleywiser

Choose a reason for hiding this comment

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

🎉

@wesleywiser

@bors

📌 Commit 7833012 has been approved by wesleywiser

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

and removed S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

labels

Oct 21, 2022

@bors

@bors

@rust-timer

Finished benchmarking commit (f42b6fa): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌ (primary) 1.3% [1.2%, 1.4%] 2
Regressions ❌ (secondary) 3.6% [3.2%, 4.1%] 6
Improvements ✅ (primary) - - 0
Improvements ✅ (secondary) - - 0
All ❌✅ (primary) 1.3% [1.2%, 1.4%] 2

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌ (primary) - - 0
Regressions ❌ (secondary) - - 0
Improvements ✅ (primary) - - 0
Improvements ✅ (secondary) -3.0% [-3.2%, -2.8%] 2
All ❌✅ (primary) - - 0

@nnethercote

This is benchmark noise.

@rustbot label: +perf-regression-triaged

Aaron1011 pushed a commit to Aaron1011/rust that referenced this pull request

Jan 6, 2023

@bors

Don't use usub.with.overflow intrinsic

The canonical form of a usub.with.overflow check in LLVM are separate sub + icmp instructions, rather than a usub.with.overflow intrinsic. Using usub.with.overflow will generally result in worse optimization potential.

The backend will attempt to form usub.with.overflow when it comes to actual instruction selection. This is not fully reliable, but I believe this is a better tradeoff than using the intrinsic in IR.

Fixes rust-lang#103285.

bors added a commit to rust-lang-ci/rust that referenced this pull request

Apr 19, 2024

@bors

Make checked ops emit unchecked LLVM operations where feasible

For things with easily pre-checked overflow conditions -- shifts and unsigned subtraction -- write then checked methods in such a way that we stop emitting wrapping versions of them.

For example, today <https://rust.godbolt.org/z/qM9YK8Txb> neither

a.checked_sub(b).unwrap()

nor

a.checked_sub(b).unwrap_unchecked()

actually optimizes to sub nuw. After this PR they do.

cc rust-lang#103299

bors added a commit to rust-lang-ci/rust that referenced this pull request

Apr 20, 2024

@bors

…bilee

Make checked ops emit unchecked LLVM operations where feasible

For things with easily pre-checked overflow conditions -- shifts and unsigned subtraction -- write the checked methods in such a way that we stop emitting wrapping versions of them.

For example, today <https://rust.godbolt.org/z/qM9YK8Txb> neither

a.checked_sub(b).unwrap()

nor

a.checked_sub(b).unwrap_unchecked()

actually optimizes to sub nuw. After this PR they do.

cc rust-lang#103299

bors added a commit to rust-lang-ci/rust that referenced this pull request

May 12, 2024

@bors

fmease added a commit to fmease/rust that referenced this pull request

May 15, 2024

@fmease

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request

May 15, 2024

@rust-timer