-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Avoid wrapping constant allocations in packed structs when not necessary #138503
base: master
Are you sure you want to change the base?
Conversation
Some changes occurred in compiler/rustc_codegen_gcc |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Avoid wrapping constant allocations in packed structs when not necessary This way LLVM will set the string merging flag if the alloc is a nul terminated string, reducing binary sizes.
#[no_mangle] | ||
pub static mut L: u8 = 0; | ||
}; | ||
|
||
fn x() { | ||
// CHECK: @M = {{(dso_local )?}}local_unnamed_addr constant | ||
// CHECK-DAG: @M = {{(dso_local )?}}local_unnamed_addr constant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LLVM decided to put this definition before A
. Using CHECK-DAG everywhere allows filecheck to match independent of the order.
…r=<try> Nul terminate rust string literals This allows taking advantage of the C string merging functionality of linkers, reducing code size. Marked as draft to see if this actually has much of an effect. The disadvantage of this is that people may start to rely on string literals getting nul terminated. A potential solution for that would be to put a byte that is not part of a valid UTF-8 character right before the nul terminator. Builds on rust-lang#138503
This comment has been minimized.
This comment has been minimized.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (3da9ce8): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking 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. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis 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.
Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesResults (primary -2.2%, secondary -3.7%)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.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 775.364s -> 773.305s (-0.27%) |
No statistically significant binary size changes, which is not all that surprising as most strings are not nul terminated. Compilation gets a bit faster though. |
This way LLVM will set the string merging flag if the alloc is a nul terminated string, reducing binary sizes.
Seems that cg_gcc doesn't handle changing the type of the static to the actual type. Reverted the change for cg_gcc. |
Perhaps this was missing a |
I think it was rust/compiler/rustc_codegen_gcc/src/consts.rs Lines 89 to 92 in 9bad8ac
|
Oh, I meant an actual call to |
Can you add a regression test with C-string literals? An end-to-end test would be nice to ensure that everything works as expected, but LLVM code generation test with an explanation also seems sufficient. Can you also include a reference to https://github.com/rust-lang/llvm-project/blob/acaea3d2bb8f351b740db7ebce7d7a40b9e21488/llvm/lib/Target/TargetLoweringObjectFile.cpp#L249-L280. r? tmiasko |
This way LLVM will set the string merging flag if the alloc is a nul terminated string, reducing binary sizes.