diff options
| author | Yotam Ofek <yotam.ofek@gmail.com> | 2025-04-05 13:58:34 +0000 |
|---|---|---|
| committer | Yotam Ofek <yotam.ofek@gmail.com> | 2025-04-05 14:01:41 +0000 |
| commit | 5b596cd28b9ca38f8541aff1b05ec26c6207797b (patch) | |
| tree | c698a961bda89c3b25be9291a313b8ef63a3e09a | |
| parent | 1e008dd5d83e782ad37fc9cf6824733f824cc8cd (diff) | |
| download | rust-5b596cd28b9ca38f8541aff1b05ec26c6207797b.tar.gz rust-5b596cd28b9ca38f8541aff1b05ec26c6207797b.zip | |
In `simplify_repeated_aggregate`, don't test first element against itself
| -rw-r--r-- | compiler/rustc_mir_transform/src/instsimplify.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/compiler/rustc_mir_transform/src/instsimplify.rs b/compiler/rustc_mir_transform/src/instsimplify.rs index da346dfc48c..2eff6b31372 100644 --- a/compiler/rustc_mir_transform/src/instsimplify.rs +++ b/compiler/rustc_mir_transform/src/instsimplify.rs @@ -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 { 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; }; |
