Skip to content

Commit 1de9312

Browse files
committed
Auto merge of #139411 - yotamofek:pr/mir_transform/instsimplify, r=compiler-errors
In `simplify_repeated_aggregate`, don't test first element against itself r? `@saethlin` Noticed that in `InstSimplifyContext::simplify_repeated_aggregate`, we're accidentally evaluating the first element's value twice, and then comparing it with itself, instead of just checking whether the rest of the elements are equal to the first one. This will probably save very few cycles, but since `InstSimplify` is always enabled, this might improve perf by a bit.
2 parents c211076 + 5b596cd commit 1de9312

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)