1
Fork 0

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.
This commit is contained in:
bors 2025-04-06 01:45:33 +00:00
commit 1de931283d

View file

@ -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;
};