-
Notifications
You must be signed in to change notification settings - Fork 13.8k
add an Rvalue
for is_val_statically_known
and use it in MIR optimization
#146550
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
base: master
Are you sure you want to change the base?
Conversation
cc @rust-lang/wg-const-eval The Miri subtree was changed cc @rust-lang/miri Some changes occurred in compiler/rustc_codegen_ssa Some changes occurred to the CTFE machinery This PR changes rustc_public cc @oli-obk, @celinval, @ouz-a Some changes occurred to constck cc @fee1-dead This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @vakaras Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri Some changes occurred in compiler/rustc_codegen_gcc Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter |
r? @SparrowLii rustbot has assigned @SparrowLii. Use |
} | ||
CopyForDeref(place) => crate::mir::Rvalue::CopyForDeref(place.stable(tables, cx)), | ||
WrapUnsafeBinder(..) => todo!("FIXME(unsafe_binders):"), | ||
StaticallyKnown(..) => todo!(), |
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.
Can I just add this to the public API or is there a special procedure for that?
This comment has been minimized.
This comment has been minimized.
No fundamental objection, but I am slightly concerned that if we have to make every intrinsic that optimizations should recognize into a MIR primitive, things will get unwieldy. It's not that hard to check if a given function call invokes a particular intrinsic (and we can add more convenience operations to make that simpler). What's the problem with using that approach? |
It also avoids requiring a terminator and new block, so for some intrinsics, changing them to an rvalue is very useful. I have not investigated whether that is true here, but it was one of the original motivations for lowering some intrinsics to rvalues |
751ecb9
to
bbcf44f
Compare
Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 |
Ok gave the changes a review. It's a lot of extra stuff to handle for sth that only one specific kind of optimization cares about. Does gvn so far have no optimizations that act on terminators, possibly replacing them wholesale? |
That's one of the reasons here – Also, this just felt right to me: But at the end of the day, this is my second compiler PR and I mostly made this decision just to follow the established pattern, so I don't feel too strongly. |
Not really, but I guess it wouldn't be too difficult: rust/compiler/rustc_mir_transform/src/gvn.rs Lines 1732 to 1753 in d1ed52b
|
The job Click to see the possible cause of the failure (guessed by this bot)
|
/// | ||
/// From an operational semantics perspective, the result is | ||
/// non-deterministically chosen. | ||
StaticallyKnown(Operand<'tcx>), |
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 assume this will still evaluate the Operand
for UB side-effects?
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.
Yes, at least it might. Skipping it should be sound though, right? And miri should detect the UB because const-eval calls eval_operand
...
pub const fn is_val_statically_known<T: Copy>(_arg: T) -> bool { | ||
false | ||
} | ||
#[rustc_intrinsic_const_stable_indirect] |
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.
Adding this attribute should not be needed for the rvalue refactor. Please don't just do a const-stabilization as a drive-by change! It's not even mentioned in the PR description.
As the comment at the top of this file explains, this needs t-lang FCP.
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.
Oh wait, there was a rustc_const_stable_indirect
before. Things just got reordered making this harder to see.
It's probably silly to keep an unused fallback body just to avoid this attribute. I assume t-lang won't insist on an FCP but we should still ping them when we resolved the other discussions in this PR.
// FIXME: should we check for validity here? It's tricky because we do not have a | ||
// place. Codegen does not seem to set any attributes like `noundef` for intrinsic | ||
// calls, so we don't *have* to do anything. |
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.
This comment is still relevant. Please be careful not to remove critical comments like this.
☔ The latest upstream changes (presumably #146666) made this pull request unmergeable. Please resolve the merge conflicts. |
By lowering the
is_val_statically_known
to anRvalue
instead of passing it through to codegen, it becomes easier to optimise in the MIR-opt const propagation passes.