-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Enable GVN for AggregateKind::RawPtr
#125041
Conversation
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
This comment has been minimized.
This comment has been minimized.
@@ -176,6 +176,9 @@ enum AggregateTy<'tcx> { | |||
Array, | |||
Tuple, | |||
Def(DefId, ty::GenericArgsRef<'tcx>), | |||
/// The type of the pointer can't be determined from the operands, | |||
/// so we have to keep the full thing here. | |||
RawPtr(Ty<'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.
it's this the type of the pointer, or the pointee? (*const A
vs A
)
d0b9aa6
to
9d266bf
Compare
This comment has been minimized.
This comment has been minimized.
9d266bf
to
b4bbd3a
Compare
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.
Thanks. For the desconstruction operations (cast and Len for now), do you plan to do it as a follow-up, or do you want me to do it?
b4bbd3a
to
1881281
Compare
Ok, with @rustbot ready |
1881281
to
63278d7
Compare
This comment has been minimized.
This comment has been minimized.
63278d7
to
94d1421
Compare
@@ -28,11 +27,8 @@ fn demo_byte_add_fat(_1: *const [u32], _2: usize) -> *const [u32] { | |||
_4 = Offset(_3, _2); | |||
StorageDead(_3); | |||
StorageLive(_5); | |||
_5 = _4 as *const () (PtrToPtr); |
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 most recent update to this PR was me realizing that smarter GVN consumption code could obviate the need for this cast that's bugged me for a while 🙂
This comment has been minimized.
This comment has been minimized.
94d1421
to
5a3eb4a
Compare
@@ -960,6 +1007,9 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { | |||
(UnOp::Not, Value::BinaryOp(BinOp::Ne, lhs, rhs)) => { | |||
Value::BinaryOp(BinOp::Eq, *lhs, *rhs) | |||
} | |||
(UnOp::PtrMetadata, Value::Aggregate(AggregateTy::RawPtr { .. }, _, fields)) => { | |||
return Some(fields[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.
Should we add such a line to Rvalue::Len
too?
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.
It's a bit more complex for Len
, because Len
has a deref as well.
I think my preference be would to work towards removing Len
, and not add a bunch more cases which we'd just delete later. Not having this for Len
isn't a regression, after all, so I think it's fine without it.
if was_updated && let Some(local) = self.try_as_local(fields[0], location) { | ||
field_ops[FieldIdx::ZERO] = Operand::Copy(Place::from(local)); | ||
self.reused_locals.insert(local); | ||
} |
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 usually check both constants and locals, to prefer keeping a constant when one is available. Or is it too unlikely here?
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 guess I might as well for consistency. It's probably quite uncommon, though, because this is the data pointer, and those usually aren't constants. But I suppose for ZSTs it's possible?
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.
...ok, done.
5a3eb4a
to
d178208
Compare
d178208
to
021ccf6
Compare
(Rebased to make sure there's no conflicts after #125893 ) |
Thanks! |
…=cjgillot Enable GVN for `AggregateKind::RawPtr` Looks like I was worried for nothing; this seems like it's much easier than I was originally thinking it would be. r? `@cjgillot` This should be useful for `x[..4]`-like things, should those start inlining enough to expose the lengths.
Rollup of 6 pull requests Successful merges: - rust-lang#125041 (Enable GVN for `AggregateKind::RawPtr`) - rust-lang#125253 (Add `FRAC_1_SQRT_2PI` constant to f16/f32/f64/f128) - rust-lang#125465 (bootstrap: vendor crates required by opt-dist to collect profiles ) - rust-lang#125470 (Add release notes for 1.79.0) - rust-lang#125963 (Remove hard-coded hashes from codegen tests) - rust-lang#126188 (Fix documentation for `impl_common_helpers` in `run-make-support`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#125041 - scottmcm:gvn-for-from-raw-parts, r=cjgillot Enable GVN for `AggregateKind::RawPtr` Looks like I was worried for nothing; this seems like it's much easier than I was originally thinking it would be. r? `@cjgillot` This should be useful for `x[..4]`-like things, should those start inlining enough to expose the lengths.
Looks like I was worried for nothing; this seems like it's much easier than I was originally thinking it would be.
r? @cjgillot
This should be useful for
x[..4]
-like things, should those start inlining enough to expose the lengths.