-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Let MonoReachable traversal evaluate BinOps #129287
Conversation
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Let MonoReachable traversal evaluate BinOps This fixes the first bug in rust-lang#129282 I don't know what the right organization is for the code here, but something probably has to get rearranged because this traversal now depends on `rustc_const_eval` so that it can use an `InterpCx` internally, so it can't live in `rustc_middle`. r? `@ghost`
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
93ae299
to
10b7e0e
Compare
Pondering: Can we just tell people that they have to write this in a const block if they want this? It's not obvious to me that doing a bunch of extra const eval in mono is worth it. (AKA "we should have |
I'm not interested in changing or adding to the language. If you want to do that, go right ahead, but it's not my thing. This seems like a useful optimization for the compiler to do, so I'm trying to see how that turns out. I think the implementation ends up convoluted because of some deeper issues we have that I'm not going to solve. MIR is really not easy to ad-hoc evaluate, and also we don't have any post-mono MIR opts. Post-mono GVN for example would fix this. I'm pasting most of the impl out of GVN to do this. @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Let MonoReachable traversal evaluate BinOps This fixes the first bug in rust-lang#129282 I don't know what the right organization is for the code here, but something probably has to get rearranged because this traversal now depends on `rustc_const_eval` so that it can use an `InterpCx` internally, so it can't live in `rustc_middle`. r? `@ghost`
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (012c415): comparison URL. Overall result: no relevant changes - no action neededBenchmarking 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 Instruction countThis 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.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 749.351s -> 750.569s (0.16%) |
It shouldn't be needed to change the language. This is stable: if const { SIZE < 4096 } {
let arr = [0u8; SIZE];
std::hint::black_box(&arr);
} else {
let vec = vec![0u8; SIZE];
std::hint::black_box(&vec);
} If that works, IMO there's no sufficient justification for piling on hacks like this. |
Seems like that doesn't work. We should figure out why. I don't think we want to start integrating general optimizations into the monomorphization step -- if we decide we need post-mono optimizations on the MIR level, we should do it properly and generate MIR for that, not embed a bunch of hard-to-audit on-the-fly transformations hidden in various other passes. |
We already know why: #129283
This would require a broader discussion about either deciding how much compile time regression is acceptable or ripping out out codegen canonicalization from MIR to reduce it. I demonstrated that one of those is required in #125025 |
This PR is an experiment. Unfortunately I can't collect perf results without posting a PR. I've set the status to "experimental" instead of "waiting on author" is that more clear? |
Fair. :)
|
// SwitchInt(_1) | ||
// | ||
// And MIR for if intrinsics::ub_checks() looks like this: | ||
// _1 = UbChecks() |
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.
Should we just make this a variant for mir::Const and avoid having this logic?
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.
No, that would be really odd.
We could consider making UbChecks
a const (giving it a DefId), similar to how we are making nullary intrinsics effectively consts. However, UbChecks
is not actually a const: its value depends on tcx.sess
which can have different values in different crates across the crate graph!
The merge conflicts here are a mess, so I don't plan on fixing them. I think the way to get such an operation merged is by doing post-mono GVN or something like that. |
This fixes the first bug in #129282
I don't know what the right organization is for the code here, but something probably has to get rearranged because this traversal now depends on
rustc_const_eval
so that it can use anInterpCx
internally, so it can't live inrustc_middle
.r? @ghost