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.
| 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.
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
cjgillot
left a comment
There was a problem hiding this comment.
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
| _4 = Offset(_3, _2); | ||
| StorageDead(_3); | ||
| StorageLive(_5); | ||
| _5 = _4 as *const () (PtrToPtr); |
There was a problem hiding this comment.
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
| } | ||
| (UnOp::PtrMetadata, Value::Aggregate(AggregateTy::RawPtr { .. }, _, fields)) => { | ||
| return Some(fields[1]); | ||
| } |
There was a problem hiding this comment.
Should we add such a line to Rvalue::Len too?
There was a problem hiding this comment.
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.
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.
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?
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.