This issue is designed to be a list of ideas to simplify MIR during optimization passes. Contributors are welcome to enhance this list.
Note: not all optimizations on this list are desirable. Some are put there to track why they were not implemented.
Instruction simplification
Avoid calling Index::index for slices of arrays and subslices, and replace if with a direct projection:
slice[constant1..constant2] to use Subslice { from: constant1, to: constant2, from_end: false};
slice[..constant2] to use Subslice { from: 0, to: constant2, from_end: false};
slice[constant1..] to use Subslice { from: constant1, to: 0, from_end: true};
slice[..] to directly reuse slice;
slice[constant1..slice.len() - constant2] to use Subslice { from: constant1, to: constant2, from_end: true};
slice[..slice.len() - constant2] to use Subslice { from: 0, to: constant2, from_end: true}.
replace manual pointer offset computations with Index projection Tracking issue for MIR simplification opportunities #111442 (comment)
Simple operations:
Aggregates:
Perform simplifications listed in clippy's perf lints #111442 (comment) .
Compile-time evaluation
Control-flow graph
This issue is designed to be a list of ideas to simplify MIR during optimization passes. Contributors are welcome to enhance this list.
Note: not all optimizations on this list are desirable. Some are put there to track why they were not implemented.
Instruction simplification
Avoid calling
Index::indexfor slices of arrays and subslices, and replace if with a direct projection:slice[constant1..constant2]to useSubslice { from: constant1, to: constant2, from_end: false};slice[..constant2]to useSubslice { from: 0, to: constant2, from_end: false};slice[constant1..]to useSubslice { from: constant1, to: 0, from_end: true};slice[..]to directly reuseslice;slice[constant1..slice.len() - constant2]to useSubslice { from: constant1, to: constant2, from_end: true};slice[..slice.len() - constant2]to useSubslice { from: 0, to: constant2, from_end: true}.Indexprojection Tracking issue for MIR simplification opportunities #111442 (comment)Simple operations:
i binop jby a statement directly in MIR, instead of inlining the trait method<T as BinOp>::bin_opTracking issue for MIR simplification opportunities #111442 (comment)Aggregates:
Perform simplifications listed in clippy's perf lints #111442 (comment).
Compile-time evaluation
Control-flow graph
SwitchInt(operand, [x -> bb, unreachable])by assume + goto --> Replace switch to unreachable by assume statements #113970