Open
Description
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 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}
. - replace manual pointer offset computations with
Index
projection Tracking issue for MIR simplification opportunities #111442 (comment)
Simple operations:
- replace
i binop j
by a statement directly in MIR, instead of inlining the trait method<T as BinOp>::bin_op
Tracking issue for MIR simplification opportunities #111442 (comment)
Aggregates:
- Avoid constructing an aggregate just to project from it Tracking issue for MIR simplification opportunities #111442 (comment)
- Ensure calls to ADT constructors are always inlined.
Perform simplifications listed in clippy's perf lints #111442 (comment).
Compile-time evaluation
- Pre-compute more in formatting internals Tracking issue for MIR simplification opportunities #111442 (comment)
Control-flow graph
- Avoid an enum to switch on its discriminant just after Tracking issue for MIR simplification opportunities #111442 (comment)
- Replace
SwitchInt(operand, [x -> bb, unreachable])
by assume + goto --> Replace switch to unreachable by assume statements #113970 - Merge switchInt-assert Tracking issue for MIR simplification opportunities #111442 (comment)