-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Re-block SRoA on SIMD types #144665
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
Re-block SRoA on SIMD types #144665
Conversation
Fixes 144621
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
@@ -72,8 +72,12 @@ fn escaping_locals<'tcx>( | |||
return true; | |||
} | |||
if let ty::Adt(def, _args) = ty.kind() | |||
&& tcx.is_lang_item(def.did(), LangItem::DynMetadata) | |||
&& (def.repr().simd() || tcx.is_lang_item(def.did(), LangItem::DynMetadata)) |
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.
Please update the doc comment on this function.
Also, could you rename this function? Calling it escaping_locals
seems a bit misleading given it has opt-outs for locals that are not necessarily escaping.
This comment has been minimized.
This comment has been minimized.
d942a9d
to
ec7e4f9
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.
I'm pretty confused about how this was refactored. This code distinguishes escaping
and excluded
, but AFAICT escaping
is a superset of the two that shouldn't change. Is there something I'm misunderstanding about the code, or are there further simplifications we can do here?
@@ -31,8 +31,9 @@ impl<'tcx> crate::MirPass<'tcx> for ScalarReplacementOfAggregates { | |||
let mut excluded = excluded_locals(body); | |||
let typing_env = body.typing_env(tcx); | |||
loop { | |||
add_type_based_exclusions(tcx, &mut excluded, body); |
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.
Does this need to happen in the loop? The set of excluded locals based off of type exclusions shouldn't change, right?
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.
Since we're in a loop I think it can because SRoA might add extra locals in the loop?
We can SRoA a (__m128, __m128)
, adding new locals which themselves need to not get SRoA'd.
body: &Body<'tcx>, | ||
) -> DenseBitSet<Local> { | ||
) { | ||
let is_excluded_ty = |ty: 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.
Why not just inline this closure? It's just a simple match on ADT, even if it's not written like that today.
let mut set = DenseBitSet::new_empty(body.local_decls.len()); | ||
set.insert_range(RETURN_PLACE..=Local::from_usize(body.arg_count)); | ||
for (local, decl) in body.local_decls().iter_enumerated() { | ||
if excluded.contains(local) || is_excluded_ty(decl.ty) { | ||
for local in body.local_decls().indices() { | ||
if excluded.contains(local) { | ||
set.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.
This is morally just a clone of excluded
, right?
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.
Hmm, probably. I'll give it a shot. (I don't know if there's potentially different lengths because of changing numbers of locals.)
Actually, @compiler-errors, would you be ok with just doing the first commit here for now -- since beta branches in 2 days and we should have a fix for this -- as a partial revert of #144543, and then doing the refactor in another PR? |
Sure |
r=me on the first commit |
ec7e4f9
to
fe08ba0
Compare
@bors r=compiler-errors |
I've been thinking about the structure here and pondering whether there's some useful loop invariants that can simplify the refactor. Notably, since we're already blocking Still TBD on trying that out and seeing how it feels, though. |
Fixes #144621