Skip to content

In simplify_repeated_aggregate, don't test first element against itself #139411

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

Merged
merged 1 commit into from
Apr 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/rustc_mir_transform/src/instsimplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,20 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> {
/// GVN can also do this optimization, but GVN is only run at mir-opt-level 2 so having this in
/// InstSimplify helps unoptimized builds.
fn simplify_repeated_aggregate(&self, rvalue: &mut Rvalue<'tcx>) {
let Rvalue::Aggregate(box AggregateKind::Array(_), fields) = rvalue else {
let Rvalue::Aggregate(box AggregateKind::Array(_), fields) = &*rvalue else {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just so fields is immutable, which makes it a bit easier to reason about, IMHO.

return;
};
if fields.len() < 5 {
return;
}
let first = &fields[rustc_abi::FieldIdx::ZERO];
let (first, rest) = fields[..].split_first().unwrap();
let Operand::Constant(first) = first else {
return;
};
let Ok(first_val) = first.const_.eval(self.tcx, self.typing_env, first.span) else {
return;
};
if fields.iter().all(|field| {
if rest.iter().all(|field| {
let Operand::Constant(field) = field else {
return false;
};
Expand Down
Loading