Skip to content

Commit 0a3a110

Browse files
authored
Unrolled build for rust-lang#139644
Rollup merge of rust-lang#139644 - yotamofek:pr/mir_transform/instsimplify/simplify_primitive_clone, r=compiler-errors Micro-optimize `InstSimplify`'s `simplify_primitive_clone` r? ````@compiler-errors```` , since you already did rust-lang#139411 and got randomly selected for rust-lang#139638 (feel free to reassign!) Another one similar in spirit to rust-lang#139411, but this time for `simplify_primitive_clone`, which is doing a bit of redundant work. Might not show up in benches, but probably worth micro-optimizing since the transformation is run even for debug builds. See inline comments for my reasoning for making these changes.
2 parents 6e83046 + 0069cad commit 0a3a110

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

Diff for: compiler/rustc_mir_transform/src/instsimplify.rs

+8-17
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, layout};
1010
use rustc_span::{DUMMY_SP, Symbol, sym};
1111

1212
use crate::simplify::simplify_duplicate_switch_targets;
13-
use crate::take_array;
1413

1514
pub(super) enum InstSimplify {
1615
BeforeInline,
@@ -214,39 +213,31 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> {
214213
terminator: &mut Terminator<'tcx>,
215214
statements: &mut Vec<Statement<'tcx>>,
216215
) {
217-
let TerminatorKind::Call { func, args, destination, target, .. } = &mut terminator.kind
216+
let TerminatorKind::Call {
217+
func, args, destination, target: Some(destination_block), ..
218+
} = &terminator.kind
218219
else {
219220
return;
220221
};
221222

222223
// It's definitely not a clone if there are multiple arguments
223224
let [arg] = &args[..] else { return };
224225

225-
let Some(destination_block) = *target else { return };
226-
227226
// Only bother looking more if it's easy to know what we're calling
228-
let Some((fn_def_id, fn_args)) = func.const_fn_def() else { return };
229-
230-
// Clone needs one arg, so we can cheaply rule out other stuff
231-
if fn_args.len() != 1 {
232-
return;
233-
}
227+
let Some((fn_def_id, ..)) = func.const_fn_def() else { return };
234228

235229
// These types are easily available from locals, so check that before
236230
// doing DefId lookups to figure out what we're actually calling.
237231
let arg_ty = arg.node.ty(self.local_decls, self.tcx);
238232

239233
let ty::Ref(_region, inner_ty, Mutability::Not) = *arg_ty.kind() else { return };
240234

241-
if !inner_ty.is_trivially_pure_clone_copy() {
242-
return;
243-
}
244-
245-
if !self.tcx.is_lang_item(fn_def_id, LangItem::CloneFn) {
235+
if !self.tcx.is_lang_item(fn_def_id, LangItem::CloneFn)
236+
|| !inner_ty.is_trivially_pure_clone_copy()
237+
{
246238
return;
247239
}
248240

249-
let Ok([arg]) = take_array(args) else { return };
250241
let Some(arg_place) = arg.node.place() else { return };
251242

252243
statements.push(Statement {
@@ -258,7 +249,7 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> {
258249
)),
259250
))),
260251
});
261-
terminator.kind = TerminatorKind::Goto { target: destination_block };
252+
terminator.kind = TerminatorKind::Goto { target: *destination_block };
262253
}
263254

264255
fn simplify_nounwind_call(&self, terminator: &mut Terminator<'tcx>) {

0 commit comments

Comments
 (0)