Skip to content

Tell LLVM about read-only captures #145259

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nikic
Copy link
Contributor

@nikic nikic commented Aug 11, 2025

&Freeze parameters are not only readonly within the function, but any captures of the pointer can also only be used for reads. This can now be encoded using the captures(address, read_provenance) attribute.

r? ghost

nikic added 2 commits August 11, 2025 12:39
Set the dead_on_return attribute (added in LLVM 21) for arguments
that are passed indirectly, but not byval.

This indicates that the value of the argument on return does not
matter, enabling additional dead store elimination.
`&Freeze` parameters are not only `readonly` within the function,
but any captures of the pointer can also only be used for reads.
This can now be encoded using the `captures(address, read_provenance)`
attribute.
@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 11, 2025
@nikic
Copy link
Contributor Author

nikic commented Aug 11, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Aug 11, 2025
Tell LLVM about read-only captures
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 11, 2025
@rust-log-analyzer
Copy link
Collaborator

The job tidy failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
All checks passed!
checking python file formatting
27 files already formatted
checking C++ file formatting
/checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp:437:47: error: code should be clang-formatted [-Wclang-format-violations]
    return wrap(Attribute::getWithCaptureInfo(*unwrap(C),
                                              ^
/checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp:437:58: error: code should be clang-formatted [-Wclang-format-violations]
    return wrap(Attribute::getWithCaptureInfo(*unwrap(C),
                                                         ^
/checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp:438:57: error: code should be clang-formatted [-Wclang-format-violations]
                CaptureInfo(CaptureComponents::Address |
                                                        ^

clang-format linting failed! Printing diff suggestions:
--- /checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp (actual)
+++ /checkout/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp (formatted)
@@ -433,11 +433,11 @@
   if (RustAttr == LLVMRustAttributeKind::NoCapture) {
     return wrap(Attribute::getWithCaptureInfo(*unwrap(C), CaptureInfo::none()));
   }
   if (RustAttr == LLVMRustAttributeKind::CapturesReadOnly) {
-    return wrap(Attribute::getWithCaptureInfo(*unwrap(C),
-                CaptureInfo(CaptureComponents::Address |
-                            CaptureComponents::ReadProvenance)));
+    return wrap(Attribute::getWithCaptureInfo(
+        *unwrap(C), CaptureInfo(CaptureComponents::Address |
+                                CaptureComponents::ReadProvenance)));
   }
 #endif
   return wrap(Attribute::get(*unwrap(C), fromRust(RustAttr)));
 }

some tidy checks failed
tidy error: checks with external tool 'clang-format' failed
Command `/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/rust-tidy /checkout /checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo /checkout/obj/build 4 /node/bin/npm --extra-checks=py,cpp,js` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/tool.rs:1634:23
Executed at: src/bootstrap/src/core/build_steps/test.rs:1239:29

Command has failed. Rerun with -v to see more details.
Build completed unsuccessfully in 0:01:16
  local time: Mon Aug 11 16:10:15 UTC 2025
  network time: Mon, 11 Aug 2025 16:10:15 GMT
##[error]Process completed with exit code 1.
Post job cleanup.

@rust-bors
Copy link

rust-bors bot commented Aug 11, 2025

☀️ Try build successful (CI)
Build commit: 6bc3793 (6bc37934c6eaa84bfd300c54189bec62e15d42ed, parent: 577166503aee7290e09374da21f4045c455acfd5)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6bc3793): comparison URL.

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

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@bors rollup=never
@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.3% [0.3%, 0.4%] 5
Regressions ❌
(secondary)
1.0% [0.9%, 1.6%] 7
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.8% [-0.8%, -0.7%] 5
All ❌✅ (primary) 0.3% [0.3%, 0.4%] 5

Max RSS (memory usage)

Results (secondary 3.9%)

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

Cycles

Results (secondary -2.1%)

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

Binary size

Results (secondary 0.0%)

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

Bootstrap: 465.465s -> 464.036s (-0.31%)
Artifact size: 377.33 MiB -> 377.30 MiB (-0.01%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Aug 11, 2025
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. perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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