-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Remove MIR assignments to ZST types #80493
Conversation
The job Click to see the possible cause of the failure (guessed by this bot)
|
@oli-obk I would need some help in what to do with those test errors. |
The job Click to see the possible cause of the failure (guessed by this bot)
|
Jup, exactly what I had in mind. I just thought we already had some code for this and just forgot turning it on again, but apparently not? You can bless most tests that changed. We do need to fix |
The job Click to see the possible cause of the failure (guessed by this bot)
|
You can fix codegen tests by looking at |
When the MIR does not have |
@bors r+ weird... but I guess that is an independent codegen problem |
📌 Commit 22f94499cc9c397420c4cf8ba0bbcabf4018bae7 has been approved by |
@bors r- I thought we had already did this via a combination of the |
Ah, ok. I see there was discussion in #80475 about this. I'm willing to accept the logic that we never need writes of ZST values even in the return place but in that case, I think the better thing to do would be to change the logic in |
I'll see how I can modify SimplifyLocals 👍 |
22f9449
to
d1a87e0
Compare
Force pushed a new approach that is an extension of SimplifyLocals instead. |
let mut is_zst = false; | ||
|
||
// ZST locals can be removed | ||
if used && !is_static { |
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.
We refactored this loop a few months ago to push most of this kind of logic into UsedLocals
. i think that's probably the place we need to make this change.
It might just be a matter of adjusting this logic:
rust/compiler/rustc_mir/src/transform/simplify.rs
Lines 392 to 398 in e226704
/// Checks if local is used. | |
/// | |
/// Return place and arguments are always considered used. | |
fn is_used(&self, local: Local) -> bool { | |
trace!("is_used({:?}): use_count: {:?}", local, self.use_count[local]); | |
local.as_u32() <= self.arg_count || self.use_count[local] != 0 | |
} |
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.
Took a stab at moving the logic into UsedLocals
with the lastest commits
src/test/codegen/naked-functions.rs
Outdated
@@ -9,6 +9,7 @@ | |||
#[naked] | |||
pub fn naked_empty() { | |||
// CHECK-NEXT: {{.+}}: | |||
// CHECK-NEXT: %0 = alloca {}, align 1 |
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.
I feel like this is probably invalid – for #[naked]
functions to be well-formed, they usually should only contain an optional inline assembly call and ret. alloca
here will likely make any use of #[naked]
plain unsound.
If #[naked]
wasn't as unstable as they are, this would be blocking, and IMHO it needing change now warrants at least a folllow-up issue.
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.
FWIW I'm pretty sure we skip codegenning ZST assignments/allocas/etc in the llvm backend which is why with _0 = const ()
in MIR it never generated any LLVM. Now that there are no assignments to the _0
, its probably taking a different path in the backend and ends up generating the alloca anyway.
If I had to guess this local is failing to be marked as a SSA value?
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.
So this pr should be blocked until the codegen is fixed to not generate ZST allocas for _0 if it is not assigned in MIR?
I haven't looked at codegen before, so any pointers are appreciated.
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.
Yeah, that looks like a use of an uninitialized ZST local marking it as non-SSA (implicit use in return terminator?). That part would be in non_ssa_locals
.
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.
The latest commit tries to eliminate the alloca
☔ The latest upstream changes (presumably #79328) made this pull request unmergeable. Please resolve the merge conflicts. |
|
||
let is_zst = self.fx.cx.layout_of(ty).is_zst(); | ||
debug!("is_zst: {}", is_zst); | ||
is_zst |
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.
I wonder if anything breaks if we do in fact just go ahead and unconditionally mark any variable without assignments as "ssa".
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.
I tried replacing is_zst
with true
which at least didn't break test/{mir-opt,codegen}. Should i push that instead of the current zst handling?
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.
Lets not do that in the current PR, especially because apparently this was added as part of a ICE fix, but without tests. I will experiment with it separately.
@@ -56,7 +56,6 @@ | |||
StorageLive(_6); // scope 3 at $DIR/cycle.rs:14:10: 14:11 | |||
- _6 = _1; // scope 3 at $DIR/cycle.rs:14:10: 14:11 | |||
+ _6 = _4; // scope 3 at $DIR/cycle.rs:14:10: 14:11 | |||
_5 = const (); // scope 4 at $DIR/cycle.rs:14:5: 14:12 | |||
StorageDead(_6); // scope 3 at $DIR/cycle.rs:14:11: 14:12 | |||
StorageDead(_5); // scope 3 at $DIR/cycle.rs:14:12: 14:13 | |||
_0 = const (); // scope 0 at $DIR/cycle.rs:8:11: 15:2 |
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.
Some assignments are not removed compared to earlier versions of this PR. Why are those not optimized now?
f1ae27c
to
60b0bb3
Compare
The job Click to see the possible cause of the failure (guessed by this bot)
|
60b0bb3
to
bab2e56
Compare
@bors r+ rollup- |
📌 Commit bab2e56 has been approved by |
I think you wanted to do @bors rollup=never
|
ooops, thanks. I had a feeling something was wrong when I typed that, but couldn't figure out what |
⌛ Testing commit bab2e56 with merge ef6fe77536ea1d8c722aad9fc949e031f01123c9... |
The job Click to see the possible cause of the failure (guessed by this bot)
|
💔 Test failed - checks-actions |
☔ The latest upstream changes (presumably #79100) made this pull request unmergeable. Please resolve the merge conflicts. |
ping from triage: |
Based on my understanding of #80475 (comment)
r? @oli-obk