Skip to content

Use an operand bundle for assume_nonnull in the LLVM backend - #166234

Open
nnethercote wants to merge 2 commits into
rust-lang:mainfrom
nnethercote:assume-bundle
Open

nnethercote wants to merge 2 commits into
rust-lang:mainfrom
nnethercote:assume-bundle

Conversation

@nnethercote

Copy link
Copy Markdown
Contributor

Details in individual commits.

r? @scottmcm

The sense is inverted.
But only for LLVM 23 onwards -- as of LLVM 23 the `InstCombine` pass
rewrites the `icmp` form into the bundle form.

In the common case this change means that we no longer generate this:
```
  %29 = icmp ne ptr %_93, null
  call void @llvm.assume(i1 %29)
```
But instead generate this:
```
  call void @llvm.assume(i1 true) [ "nonnull"(ptr %_93) ]
```

In the rare case (about 10x less common) we no longer generate this:
```
  call void @llvm.assume(i1 true)
```
But instead generate this:
```
  call void @llvm.assume(i1 true) [ "nonnull"(ptr @alloc_0c12d936522008f99725fd9502bec5dd) ]
```
This is because LLVM was previously able to fold a nonnull check on a
global pointer (`icmp ne ptr @alloc_0c1..., null`) when rustc asked it
to create the boolean value for the instruction form, but no longer does
when it's in bundle form. But LLVM itself should easily fold it away, so
I don't think this is a big deal.
@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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 Nov 20, 2026
@nnethercote

Copy link
Copy Markdown
Contributor Author

@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 Nov 20, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Nov 20, 2026
Use an operand bundle for `assume_nonnull` in the LLVM backend
@rust-bors

rust-bors Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 163a657 (163a657abe2e5078d1cff28ce10482d152b31caa)
Base parent: 4b5350e (4b5350e87e487aed08ab2f9f0160a4b2616438bc)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown

Finished benchmarking commit (163a657): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

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

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.7% [0.0%, 0.9%] 7
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary 0.5%, secondary 0.9%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
1.4% [0.8%, 2.1%] 2
Regressions ❌
(secondary)
1.3% [0.6%, 3.4%] 9
Improvements ✅
(primary)
-1.4% [-1.4%, -1.4%] 1
Improvements ✅
(secondary)
-2.8% [-2.8%, -2.8%] 1
All ❌✅ (primary) 0.5% [-1.4%, 2.1%] 3

Cycles

Results (secondary 1.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.2% [1.0%, 1.5%] 7
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 458.821s -> 461.585s (0.60%)
Artifact size: 405.37 MiB -> 405.39 MiB (0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 20, 2026
@nnethercote

Copy link
Copy Markdown
Contributor Author

next-solver-stress is an extremely new benchmark and I'm not sure if there is enough data for it to be reliable.

This PR isn't intended to make the compiler faster. It's more a case of "LLVM is heading in the direction of using operand bundles for these assertions, so we might as well get with the program".

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants