Skip to content

Commit ff85554

Browse files
committed
Rename InstCombine to InstSimplify
1 parent a77c552 commit ff85554

35 files changed

+100
-100
lines changed

compiler/rustc_mir_transform/src/instcombine.rs renamed to compiler/rustc_mir_transform/src/instsimplify.rs

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Performs various peephole optimizations.
22
3-
use crate::simplify::combine_duplicate_switch_targets;
3+
use crate::simplify::simplify_duplicate_switch_targets;
44
use crate::MirPass;
55
use rustc_hir::Mutability;
66
use rustc_middle::mir::*;
@@ -10,15 +10,15 @@ use rustc_middle::ty::{self, ParamEnv, SubstsRef, Ty, TyCtxt};
1010
use rustc_span::symbol::Symbol;
1111
use rustc_target::abi::FieldIdx;
1212

13-
pub struct InstCombine;
13+
pub struct InstSimplify;
1414

15-
impl<'tcx> MirPass<'tcx> for InstCombine {
15+
impl<'tcx> MirPass<'tcx> for InstSimplify {
1616
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
1717
sess.mir_opt_level() > 0
1818
}
1919

2020
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
21-
let ctx = InstCombineContext {
21+
let ctx = InstSimplifyContext {
2222
tcx,
2323
local_decls: &body.local_decls,
2424
param_env: tcx.param_env_reveal_all_normalized(body.source.def_id()),
@@ -27,43 +27,43 @@ impl<'tcx> MirPass<'tcx> for InstCombine {
2727
for statement in block.statements.iter_mut() {
2828
match statement.kind {
2929
StatementKind::Assign(box (_place, ref mut rvalue)) => {
30-
ctx.combine_bool_cmp(&statement.source_info, rvalue);
31-
ctx.combine_ref_deref(&statement.source_info, rvalue);
32-
ctx.combine_len(&statement.source_info, rvalue);
33-
ctx.combine_cast(&statement.source_info, rvalue);
30+
ctx.simplify_bool_cmp(&statement.source_info, rvalue);
31+
ctx.simplify_ref_deref(&statement.source_info, rvalue);
32+
ctx.simplify_len(&statement.source_info, rvalue);
33+
ctx.simplify_cast(&statement.source_info, rvalue);
3434
}
3535
_ => {}
3636
}
3737
}
3838

39-
ctx.combine_primitive_clone(
39+
ctx.simplify_primitive_clone(
4040
&mut block.terminator.as_mut().unwrap(),
4141
&mut block.statements,
4242
);
43-
ctx.combine_intrinsic_assert(
43+
ctx.simplify_intrinsic_assert(
4444
&mut block.terminator.as_mut().unwrap(),
4545
&mut block.statements,
4646
);
47-
combine_duplicate_switch_targets(block.terminator.as_mut().unwrap());
47+
simplify_duplicate_switch_targets(block.terminator.as_mut().unwrap());
4848
}
4949
}
5050
}
5151

52-
struct InstCombineContext<'tcx, 'a> {
52+
struct InstSimplifyContext<'tcx, 'a> {
5353
tcx: TyCtxt<'tcx>,
5454
local_decls: &'a LocalDecls<'tcx>,
5555
param_env: ParamEnv<'tcx>,
5656
}
5757

58-
impl<'tcx> InstCombineContext<'tcx, '_> {
59-
fn should_combine(&self, source_info: &SourceInfo, rvalue: &Rvalue<'tcx>) -> bool {
58+
impl<'tcx> InstSimplifyContext<'tcx, '_> {
59+
fn should_simplify(&self, source_info: &SourceInfo, rvalue: &Rvalue<'tcx>) -> bool {
6060
self.tcx.consider_optimizing(|| {
61-
format!("InstCombine - Rvalue: {:?} SourceInfo: {:?}", rvalue, source_info)
61+
format!("InstSimplify - Rvalue: {:?} SourceInfo: {:?}", rvalue, source_info)
6262
})
6363
}
6464

6565
/// Transform boolean comparisons into logical operations.
66-
fn combine_bool_cmp(&self, source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) {
66+
fn simplify_bool_cmp(&self, source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) {
6767
match rvalue {
6868
Rvalue::BinaryOp(op @ (BinOp::Eq | BinOp::Ne), box (a, b)) => {
6969
let new = match (op, self.try_eval_bool(a), self.try_eval_bool(b)) {
@@ -94,7 +94,7 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
9494
_ => None,
9595
};
9696

97-
if let Some(new) = new && self.should_combine(source_info, rvalue) {
97+
if let Some(new) = new && self.should_simplify(source_info, rvalue) {
9898
*rvalue = new;
9999
}
100100
}
@@ -109,14 +109,14 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
109109
}
110110

111111
/// Transform "&(*a)" ==> "a".
112-
fn combine_ref_deref(&self, source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) {
112+
fn simplify_ref_deref(&self, source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) {
113113
if let Rvalue::Ref(_, _, place) = rvalue {
114114
if let Some((base, ProjectionElem::Deref)) = place.as_ref().last_projection() {
115115
if rvalue.ty(self.local_decls, self.tcx) != base.ty(self.local_decls, self.tcx).ty {
116116
return;
117117
}
118118

119-
if !self.should_combine(source_info, rvalue) {
119+
if !self.should_simplify(source_info, rvalue) {
120120
return;
121121
}
122122

@@ -129,11 +129,11 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
129129
}
130130

131131
/// Transform "Len([_; N])" ==> "N".
132-
fn combine_len(&self, source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) {
132+
fn simplify_len(&self, source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) {
133133
if let Rvalue::Len(ref place) = *rvalue {
134134
let place_ty = place.ty(self.local_decls, self.tcx).ty;
135135
if let ty::Array(_, len) = *place_ty.kind() {
136-
if !self.should_combine(source_info, rvalue) {
136+
if !self.should_simplify(source_info, rvalue) {
137137
return;
138138
}
139139

@@ -144,7 +144,7 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
144144
}
145145
}
146146

147-
fn combine_cast(&self, _source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) {
147+
fn simplify_cast(&self, _source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) {
148148
if let Rvalue::Cast(kind, operand, cast_ty) = rvalue {
149149
let operand_ty = operand.ty(self.local_decls, self.tcx);
150150
if operand_ty == *cast_ty {
@@ -196,7 +196,7 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
196196
}
197197
}
198198

199-
fn combine_primitive_clone(
199+
fn simplify_primitive_clone(
200200
&self,
201201
terminator: &mut Terminator<'tcx>,
202202
statements: &mut Vec<Statement<'tcx>>,
@@ -239,7 +239,7 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
239239

240240
if !self.tcx.consider_optimizing(|| {
241241
format!(
242-
"InstCombine - Call: {:?} SourceInfo: {:?}",
242+
"InstSimplify - Call: {:?} SourceInfo: {:?}",
243243
(fn_def_id, fn_substs),
244244
terminator.source_info
245245
)
@@ -262,7 +262,7 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
262262
terminator.kind = TerminatorKind::Goto { target: destination_block };
263263
}
264264

265-
fn combine_intrinsic_assert(
265+
fn simplify_intrinsic_assert(
266266
&self,
267267
terminator: &mut Terminator<'tcx>,
268268
_statements: &mut Vec<Statement<'tcx>>,

compiler/rustc_mir_transform/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ mod ffi_unwind_calls;
7373
mod function_item_references;
7474
mod generator;
7575
mod inline;
76-
mod instcombine;
76+
mod instsimplify;
7777
mod large_enums;
7878
mod lower_intrinsics;
7979
mod lower_slice_len;
@@ -547,7 +547,7 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
547547
&match_branches::MatchBranchSimplification,
548548
// inst combine is after MatchBranchSimplification to clean up Ne(_1, false)
549549
&multiple_return_terminators::MultipleReturnTerminators,
550-
&instcombine::InstCombine,
550+
&instsimplify::InstSimplify,
551551
&separate_const_switch::SeparateConstSwitch,
552552
&simplify::SimplifyLocals::BeforeConstProp,
553553
&copy_prop::CopyProp,

compiler/rustc_mir_transform/src/simplify.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> {
278278
}
279279
}
280280

281-
pub fn combine_duplicate_switch_targets(terminator: &mut Terminator<'_>) {
281+
pub fn simplify_duplicate_switch_targets(terminator: &mut Terminator<'_>) {
282282
if let TerminatorKind::SwitchInt { targets, .. } = &mut terminator.kind {
283283
let otherwise = targets.otherwise();
284284
if targets.iter().any(|t| t.1 == otherwise) {
@@ -310,7 +310,7 @@ pub fn remove_duplicate_unreachable_blocks<'tcx>(tcx: TyCtxt<'tcx>, body: &mut B
310310
}
311311
}
312312

313-
combine_duplicate_switch_targets(terminator);
313+
simplify_duplicate_switch_targets(terminator);
314314

315315
self.super_terminator(terminator, location);
316316
}

compiler/rustc_session/src/options.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,7 @@ options! {
15551555
"emit Retagging MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0 \
15561556
(default: no)"),
15571557
mir_enable_passes: Vec<(String, bool)> = (Vec::new(), parse_list_with_polarity, [TRACKED],
1558-
"use like `-Zmir-enable-passes=+DestProp,-InstCombine`. Forces the specified passes to be \
1558+
"use like `-Zmir-enable-passes=+DestinationPropagation,-InstSimplify`. Forces the specified passes to be \
15591559
enabled, overriding all other checks. Passes that are not specified are enabled or \
15601560
disabled by other flags as usual."),
15611561
mir_keep_place_mention: bool = (false, parse_bool, [TRACKED],

tests/mir-opt/bool_compare.opt1.InstCombine.diff renamed to tests/mir-opt/bool_compare.opt1.InstSimplify.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- // MIR for `opt1` before InstCombine
2-
+ // MIR for `opt1` after InstCombine
1+
- // MIR for `opt1` before InstSimplify
2+
+ // MIR for `opt1` after InstSimplify
33

44
fn opt1(_1: bool) -> u32 {
55
debug x => _1; // in scope 0 at $DIR/bool_compare.rs:+0:9: +0:10

tests/mir-opt/bool_compare.opt2.InstCombine.diff renamed to tests/mir-opt/bool_compare.opt2.InstSimplify.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- // MIR for `opt2` before InstCombine
2-
+ // MIR for `opt2` after InstCombine
1+
- // MIR for `opt2` before InstSimplify
2+
+ // MIR for `opt2` after InstSimplify
33

44
fn opt2(_1: bool) -> u32 {
55
debug x => _1; // in scope 0 at $DIR/bool_compare.rs:+0:9: +0:10

tests/mir-opt/bool_compare.opt3.InstCombine.diff renamed to tests/mir-opt/bool_compare.opt3.InstSimplify.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- // MIR for `opt3` before InstCombine
2-
+ // MIR for `opt3` after InstCombine
1+
- // MIR for `opt3` before InstSimplify
2+
+ // MIR for `opt3` after InstSimplify
33

44
fn opt3(_1: bool) -> u32 {
55
debug x => _1; // in scope 0 at $DIR/bool_compare.rs:+0:9: +0:10

tests/mir-opt/bool_compare.opt4.InstCombine.diff renamed to tests/mir-opt/bool_compare.opt4.InstSimplify.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- // MIR for `opt4` before InstCombine
2-
+ // MIR for `opt4` after InstCombine
1+
- // MIR for `opt4` before InstSimplify
2+
+ // MIR for `opt4` after InstSimplify
33

44
fn opt4(_1: bool) -> u32 {
55
debug x => _1; // in scope 0 at $DIR/bool_compare.rs:+0:9: +0:10

tests/mir-opt/bool_compare.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
// unit-test: InstCombine
1+
// unit-test: InstSimplify
22

3-
// EMIT_MIR bool_compare.opt1.InstCombine.diff
3+
// EMIT_MIR bool_compare.opt1.InstSimplify.diff
44
fn opt1(x: bool) -> u32 {
55
if x != true { 0 } else { 1 }
66
}
77

8-
// EMIT_MIR bool_compare.opt2.InstCombine.diff
8+
// EMIT_MIR bool_compare.opt2.InstSimplify.diff
99
fn opt2(x: bool) -> u32 {
1010
if true != x { 0 } else { 1 }
1111
}
1212

13-
// EMIT_MIR bool_compare.opt3.InstCombine.diff
13+
// EMIT_MIR bool_compare.opt3.InstSimplify.diff
1414
fn opt3(x: bool) -> u32 {
1515
if x == false { 0 } else { 1 }
1616
}
1717

18-
// EMIT_MIR bool_compare.opt4.InstCombine.diff
18+
// EMIT_MIR bool_compare.opt4.InstSimplify.diff
1919
fn opt4(x: bool) -> u32 {
2020
if false == x { 0 } else { 1 }
2121
}

tests/mir-opt/casts.redundant.InstCombine.diff renamed to tests/mir-opt/casts.redundant.InstSimplify.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- // MIR for `redundant` before InstCombine
2-
+ // MIR for `redundant` after InstCombine
1+
- // MIR for `redundant` before InstSimplify
2+
+ // MIR for `redundant` after InstSimplify
33

44
fn redundant(_1: *const &u8) -> *const &u8 {
55
debug x => _1; // in scope 0 at $DIR/casts.rs:+0:30: +0:31

tests/mir-opt/casts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![crate_type = "lib"]
22

3-
// EMIT_MIR casts.redundant.InstCombine.diff
3+
// EMIT_MIR casts.redundant.InstSimplify.diff
44
// EMIT_MIR casts.redundant.PreCodegen.after.mir
55
pub fn redundant<'a, 'b: 'a>(x: *const &'a u8) -> *const &'a u8 {
66
generic_cast::<&'a u8, &'b u8>(x) as *const &'a u8

tests/mir-opt/combine_array_len.norm2.InstCombine.diff renamed to tests/mir-opt/combine_array_len.norm2.InstSimplify.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- // MIR for `norm2` before InstCombine
2-
+ // MIR for `norm2` after InstCombine
1+
- // MIR for `norm2` before InstSimplify
2+
+ // MIR for `norm2` after InstSimplify
33

44
fn norm2(_1: [f32; 2]) -> f32 {
55
debug x => _1; // in scope 0 at $DIR/combine_array_len.rs:+0:10: +0:11

tests/mir-opt/combine_array_len.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ignore-wasm32 compiled with panic=abort by default
2-
// unit-test: InstCombine
3-
// EMIT_MIR combine_array_len.norm2.InstCombine.diff
2+
// unit-test: InstSimplify
3+
// EMIT_MIR combine_array_len.norm2.InstSimplify.diff
44

55
fn norm2(x: [f32; 2]) -> f32 {
66
let a = x[0];

tests/mir-opt/combine_clone_of_primitives.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// unit-test: InstCombine
1+
// unit-test: InstSimplify
22
// ignore-wasm32 compiled with panic=abort by default
33

4-
// EMIT_MIR combine_clone_of_primitives.{impl#0}-clone.InstCombine.diff
4+
// EMIT_MIR combine_clone_of_primitives.{impl#0}-clone.InstSimplify.diff
55

66
#[derive(Clone)]
77
struct MyThing<T> {

tests/mir-opt/combine_clone_of_primitives.{impl#0}-clone.InstCombine.diff renamed to tests/mir-opt/combine_clone_of_primitives.{impl#0}-clone.InstSimplify.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- // MIR for `<impl at $DIR/combine_clone_of_primitives.rs:6:10: 6:15>::clone` before InstCombine
2-
+ // MIR for `<impl at $DIR/combine_clone_of_primitives.rs:6:10: 6:15>::clone` after InstCombine
1+
- // MIR for `<impl at $DIR/combine_clone_of_primitives.rs:6:10: 6:15>::clone` before InstSimplify
2+
+ // MIR for `<impl at $DIR/combine_clone_of_primitives.rs:6:10: 6:15>::clone` after InstSimplify
33

44
fn <impl at $DIR/combine_clone_of_primitives.rs:6:10: 6:15>::clone(_1: &MyThing<T>) -> MyThing<T> {
55
debug self => _1; // in scope 0 at $DIR/combine_clone_of_primitives.rs:+0:10: +0:15

tests/mir-opt/combine_transmutes.adt_transmutes.InstCombine.diff renamed to tests/mir-opt/combine_transmutes.adt_transmutes.InstSimplify.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- // MIR for `adt_transmutes` before InstCombine
2-
+ // MIR for `adt_transmutes` after InstCombine
1+
- // MIR for `adt_transmutes` before InstSimplify
2+
+ // MIR for `adt_transmutes` after InstSimplify
33

44
fn adt_transmutes() -> () {
55
let mut _0: (); // return place in scope 0 at $DIR/combine_transmutes.rs:+0:32: +0:32

tests/mir-opt/combine_transmutes.identity_transmutes.InstCombine.diff renamed to tests/mir-opt/combine_transmutes.identity_transmutes.InstSimplify.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- // MIR for `identity_transmutes` before InstCombine
2-
+ // MIR for `identity_transmutes` after InstCombine
1+
- // MIR for `identity_transmutes` before InstSimplify
2+
+ // MIR for `identity_transmutes` after InstSimplify
33

44
fn identity_transmutes() -> () {
55
let mut _0: (); // return place in scope 0 at $DIR/combine_transmutes.rs:+0:37: +0:37

tests/mir-opt/combine_transmutes.integer_transmutes.InstCombine.diff renamed to tests/mir-opt/combine_transmutes.integer_transmutes.InstSimplify.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- // MIR for `integer_transmutes` before InstCombine
2-
+ // MIR for `integer_transmutes` after InstCombine
1+
- // MIR for `integer_transmutes` before InstSimplify
2+
+ // MIR for `integer_transmutes` after InstSimplify
33

44
fn integer_transmutes() -> () {
55
let mut _0: (); // return place in scope 0 at $DIR/combine_transmutes.rs:+0:36: +0:36

tests/mir-opt/combine_transmutes.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// unit-test: InstCombine
1+
// unit-test: InstSimplify
22
// compile-flags: -C panic=abort
33

44
#![crate_type = "lib"]
@@ -8,15 +8,15 @@
88
use std::intrinsics::mir::*;
99
use std::mem::{MaybeUninit, ManuallyDrop, transmute};
1010

11-
// EMIT_MIR combine_transmutes.identity_transmutes.InstCombine.diff
11+
// EMIT_MIR combine_transmutes.identity_transmutes.InstSimplify.diff
1212
pub unsafe fn identity_transmutes() {
1313
// These are nops and should be removed
1414
let _a = transmute::<i32, i32>(1);
1515
let _a = transmute::<Vec<i32>, Vec<i32>>(Vec::new());
1616
}
1717

1818
#[custom_mir(dialect = "runtime", phase = "initial")]
19-
// EMIT_MIR combine_transmutes.integer_transmutes.InstCombine.diff
19+
// EMIT_MIR combine_transmutes.integer_transmutes.InstSimplify.diff
2020
pub unsafe fn integer_transmutes() {
2121
mir! {
2222
{
@@ -30,7 +30,7 @@ pub unsafe fn integer_transmutes() {
3030
}
3131
}
3232

33-
// EMIT_MIR combine_transmutes.adt_transmutes.InstCombine.diff
33+
// EMIT_MIR combine_transmutes.adt_transmutes.InstSimplify.diff
3434
pub unsafe fn adt_transmutes() {
3535
let _a: u8 = transmute(EnumNoRepr::A);
3636
let _a: i8 = transmute(EnumNoRepr::B);

tests/mir-opt/const_prop/slice_len.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ignore-wasm32 compiled with panic=abort by default
22
// unit-test: ConstProp
3-
// compile-flags: -Zmir-enable-passes=+InstCombine
3+
// compile-flags: -Zmir-enable-passes=+InstSimplify
44
// EMIT_MIR_FOR_EACH_BIT_WIDTH
55

66
// EMIT_MIR slice_len.main.ConstProp.diff

tests/mir-opt/dont_yeet_assert.generic.InstCombine.diff renamed to tests/mir-opt/dont_yeet_assert.generic.InstSimplify.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- // MIR for `generic` before InstCombine
2-
+ // MIR for `generic` after InstCombine
1+
- // MIR for `generic` before InstSimplify
2+
+ // MIR for `generic` after InstSimplify
33

44
fn generic() -> () {
55
let mut _0: (); // return place in scope 0 at $DIR/dont_yeet_assert.rs:+0:21: +0:21

0 commit comments

Comments
 (0)