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

Emit trunc nuw for unchecked shifts and to_immediate_scalar #137058

Merged
merged 3 commits into from
Feb 20, 2025

Conversation

scottmcm
Copy link
Member

@scottmcm scottmcm commented Feb 15, 2025

  • For shifts this shrinks the IR by no longer needing an assume while still providing the UB information
  • Having this on the i8i1 truncations will hopefully help with some places that have to load i8s or pass those in LLVM structs without range information

@rustbot
Copy link
Collaborator

rustbot commented Feb 15, 2025

r? @Noratrieb

rustbot has assigned @Noratrieb.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 15, 2025
@rustbot
Copy link
Collaborator

rustbot commented Feb 15, 2025

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

let trunc = self.trunc(val, dest_ty);
if llvm_util::get_version() >= (19, 0, 0) {
unsafe {
if llvm::LLVMIsATruncInst(trunc).is_some() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Checking LLVMIsAInstruction would be fine as well, don't really need to export the extra API.

Copy link
Member Author

Choose a reason for hiding this comment

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

@nikic The assertions in #137058 (comment) are why I was using LLVMIsATruncInst here. Am I doing something wrong, and LLVMIsAInstruction should work, or should I go back to checking LLVMIsATruncInst?

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, that probably means that you have some cases with a trunc to the same type. In that case, you will end up trying to set the flag on an unrelated instruction (producing a crash with LLVMIsAInstruction -- with LLVMIsATruncInst it might end up setting the flag on an unrelated trunc).

You'll want to check for the no-op trunc case and bail out early.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, you were 100% correct -- extract field was calling to_immediate_scalar on things where that had already been called, resulting in no-op i1i1 truncates.

@nikic
Copy link
Contributor

nikic commented Feb 15, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 15, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 15, 2025
Emit `trunc nuw` for unchecked shifts and `to_immediate_scalar`

- For shifts this shrinks the IR by no longer needing an `assume` while still providing the UB information
- Having this on the `i8`→`i1` truncations will hopefully help with some places that have to load `i8`s or pass those in LLVM structs without range information
@bors
Copy link
Contributor

bors commented Feb 15, 2025

⌛ Trying commit 79891a0 with merge 70adb00...

@bors
Copy link
Contributor

bors commented Feb 15, 2025

☀️ Try build successful - checks-actions
Build commit: 70adb00 (70adb00341b574a0ec80325546b6653c0e47c460)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (70adb00): 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-perf -perf-regression

Instruction count

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

Max RSS (memory usage)

Results (primary -2.3%)

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)
-2.3% [-2.3%, -2.3%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.3% [-2.3%, -2.3%] 1

Cycles

Results (secondary -7.4%)

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)
-7.4% [-7.9%, -6.9%] 6
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 788.977s -> 789.501s (0.07%)
Artifact size: 347.33 MiB -> 347.37 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 15, 2025
@scottmcm

This comment was marked as outdated.

@scottmcm
Copy link
Member Author

LLVMIsAInstruction is asserting for me locally, so let's try the LLVM-19 jobs to see if it's just me or not:
@bors try

@bors
Copy link
Contributor

bors commented Feb 15, 2025

⌛ Trying commit 6629a40 with merge 7f462bb...

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 15, 2025
Emit `trunc nuw` for unchecked shifts and `to_immediate_scalar`

- For shifts this shrinks the IR by no longer needing an `assume` while still providing the UB information
- Having this on the `i8`→`i1` truncations will hopefully help with some places that have to load `i8`s or pass those in LLVM structs without range information

try-job: x86_64-gnu-llvm-19-1
try-job: x86_64-gnu-llvm-19-2
try-job: x86_64-gnu-llvm-19-3
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Feb 15, 2025

☀️ Try build successful - checks-actions
Build commit: 7f462bb (7f462bb604e024e270c17d4929aadce7796695f4)

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Feb 19, 2025

📌 Commit 0fb9186 has been approved by nikic

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 Feb 19, 2025
@bors
Copy link
Contributor

bors commented Feb 19, 2025

⌛ Testing commit 0fb9186 with merge 2cfc21b...

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 19, 2025
Emit `trunc nuw` for unchecked shifts and `to_immediate_scalar`

- For shifts this shrinks the IR by no longer needing an `assume` while still providing the UB information
- Having this on the `i8`→`i1` truncations will hopefully help with some places that have to load `i8`s or pass those in LLVM structs without range information
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Feb 19, 2025

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 19, 2025
- For shifts this shrinks the IR by no longer needing an `assume` while still providing the UB information
- Having this on the `i8`→`i1` truncations will hopefully help with some places that have to load `i8`s or pass those in LLVM structs without range information
…ar` on things which are already immediates

That means it stops trying to truncate things that are already `i1`s.
@scottmcm
Copy link
Member Author

@scottmcm
Copy link
Member Author

@bors r=nikic

@bors
Copy link
Contributor

bors commented Feb 19, 2025

📌 Commit 6f9cfd6 has been approved by nikic

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 Feb 19, 2025
@bors
Copy link
Contributor

bors commented Feb 20, 2025

⌛ Testing commit 6f9cfd6 with merge c62239a...

@bors
Copy link
Contributor

bors commented Feb 20, 2025

☀️ Test successful - checks-actions
Approved by: nikic
Pushing c62239a to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Feb 20, 2025
@bors bors merged commit c62239a into rust-lang:master Feb 20, 2025
7 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Feb 20, 2025
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (c62239a): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

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

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.7% [0.4%, 1.3%] 16
Improvements ✅
(primary)
-0.5% [-0.8%, -0.4%] 4
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.1%] 1
All ❌✅ (primary) -0.5% [-0.8%, -0.4%] 4

Max RSS (memory usage)

Results (primary -1.1%)

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)
1.7% [1.7%, 1.7%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.5% [-3.3%, -1.7%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.1% [-3.3%, 1.7%] 3

Cycles

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

Binary size

Results (primary -0.0%)

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.0% [-0.0%, -0.0%] 10
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.0% [-0.0%, -0.0%] 10

Bootstrap: 772.938s -> 773.474s (0.07%)
Artifact size: 360.27 MiB -> 360.26 MiB (-0.00%)

@rustbot rustbot added the perf-regression Performance regression. label Feb 20, 2025
@scottmcm scottmcm deleted the trunc-unchecked branch February 21, 2025 05:48
@rylev
Copy link
Member

rylev commented Feb 25, 2025

@scottmcm all the regressions are in the coercions benchmark which I would expect to see stressed by changes like this one. Do you think this warrants further investigation? Usually small changes in stress tests don't necessarily lead to perf investigations.

@scottmcm
Copy link
Member Author

@rylev I think I'm recovering the regressions to coercions in #137513 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants