Skip to content

Commit 5b596cd

Browse files
committed
In simplify_repeated_aggregate, don't test first element against itself
1 parent 1e008dd commit 5b596cd

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

compiler/rustc_mir_transform/src/instsimplify.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,20 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> {
7878
/// GVN can also do this optimization, but GVN is only run at mir-opt-level 2 so having this in
7979
/// InstSimplify helps unoptimized builds.
8080
fn simplify_repeated_aggregate(&self, rvalue: &mut Rvalue<'tcx>) {
81-
let Rvalue::Aggregate(box AggregateKind::Array(_), fields) = rvalue else {
81+
let Rvalue::Aggregate(box AggregateKind::Array(_), fields) = &*rvalue else {
8282
return;
8383
};
8484
if fields.len() < 5 {
8585
return;
8686
}
87-
let first = &fields[rustc_abi::FieldIdx::ZERO];
87+
let (first, rest) = fields[..].split_first().unwrap();
8888
let Operand::Constant(first) = first else {
8989
return;
9090
};
9191
let Ok(first_val) = first.const_.eval(self.tcx, self.typing_env, first.span) else {
9292
return;
9393
};
94-
if fields.iter().all(|field| {
94+
if rest.iter().all(|field| {
9595
let Operand::Constant(field) = field else {
9696
return false;
9797
};

0 commit comments

Comments
 (0)