rust/src/test/mir-opt
bors 357f660729 Auto merge of #101168 - jachris:dataflow-const-prop, r=oli-obk
Add new MIR constant propagation based on dataflow analysis

The current constant propagation in `rustc_mir_transform/src/const_prop.rs` fails to handle many cases that would be expected from a constant propagation optimization. For example:
```rust
let x = if true { 0 } else { 0 };
```
This pull request adds a new constant propagation MIR optimization pass based on the existing dataflow analysis framework. Since most of the analysis is not unique to constant propagation, a generic framework has been extracted. It works on top of the existing framework and could be reused for other optimzations.

Closes #80038. Closes #81605.

## Todo
### Essential
- [x] [Writes to inactive enum variants](https://github.com/rust-lang/rust/pull/101168#pullrequestreview-1089493974). Resolved by rejecting the registration of places with downcast projections for now. Could be improved by flooding other variants if mutable access to a variant is observed.
- [X] Handle [`StatementKind::CopyNonOverlapping`](https://github.com/rust-lang/rust/pull/101168#discussion_r957774914). Resolved by flooding the destination.
- [x] Handle `UnsafeCell` / `!Freeze` correctly.
- [X] Overflow propagation of `CheckedBinaryOp`: Decided to not propagate if overflow flag is `true` (`false` will still be propagated)
- [x] More documentation in general.
- [x] Arguments for correctness, documentation of necessary assumptions.
- [x] Better performance, or alternatively, require `-Zmir-opt-level=3` for now.

### Extra
- [x]  Add explicit unreachability, i.e. upgrading the lattice from $\mathbb{P} \to \mathbb{V}$ to $\set{\bot} \cup (\mathbb{P} \to \mathbb{V})$.
- [x] Use storage statements to improve precision.
- [ ] Consider opening issue for duplicate diagnostics: https://github.com/rust-lang/rust/pull/101168#issuecomment-1276609950
- [ ] Flood moved-from places with $\bot$ (requires some changes for places with tracked projections).
- [ ] Add downcast projections back in.
- [ ] [Algebraic simplifications](https://github.com/rust-lang/rust/pull/101168#discussion_r957967878) (possibly with a shared API; done by old const prop).
- [ ] Propagation through slices / arrays.
- [ ] Find other optimizations that are done by old `const_prop.rs`, but not by this one.
2022-11-15 09:38:05 +00:00
..
building Add support for custom MIR parsing 2022-11-08 23:13:15 -08:00
const_prop Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
dataflow-const-prop Exclude locals completely, instead of individual places 2022-11-12 14:57:14 +01:00
dead-store-elimination
dest-prop
inline Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issues Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
nll Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
76803_regression.encode.SimplifyBranchSame.diff
76803_regression.rs
address_of.address_of_reborrow.SimplifyCfg-initial.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
address_of.borrow_and_cast.SimplifyCfg-initial.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
address_of.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
array_index_is_temporary.main.SimplifyCfg-elaborate-drops.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
array_index_is_temporary.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
asm_unwind_panic_abort.main.AbortUnwindingCalls.after.mir
asm_unwind_panic_abort.rs
basic_assignment.main.SimplifyCfg-initial.after.mir
basic_assignment.rs
bool_compare.opt1.InstCombine.diff
bool_compare.opt2.InstCombine.diff
bool_compare.opt3.InstCombine.diff
bool_compare.opt4.InstCombine.diff
bool_compare.rs
box_expr.main.ElaborateDrops.before.mir
box_expr.rs
byte_slice.main.SimplifyCfg-elaborate-drops.after.mir
byte_slice.rs
combine_array_len.norm2.InstCombine.diff
combine_array_len.rs
combine_clone_of_primitives.{impl#0}-clone.InstCombine.diff
combine_clone_of_primitives.rs
const_allocation2.main.ConstProp.after.32bit.mir
const_allocation2.main.ConstProp.after.64bit.mir
const_allocation2.rs
const_allocation3.main.ConstProp.after.32bit.mir
const_allocation3.main.ConstProp.after.64bit.mir
const_allocation3.rs
const_allocation.main.ConstProp.after.32bit.mir
const_allocation.main.ConstProp.after.64bit.mir
const_allocation.rs
const_debuginfo.main.ConstDebugInfo.diff
const_debuginfo.rs
const_goto_const_eval_fail.f.ConstGoto.diff
const_goto_const_eval_fail.rs
const_goto_storage.match_nested_if.ConstGoto.diff
const_goto_storage.rs
const_goto.issue_77355_opt.ConstGoto.diff
const_goto.rs
const_promotion_extern_static.BAR-promoted[0].SimplifyCfg-elaborate-drops.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
const_promotion_extern_static.BAR.PromoteTemps.diff Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
const_promotion_extern_static.BOP.built.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
const_promotion_extern_static.FOO-promoted[0].SimplifyCfg-elaborate-drops.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
const_promotion_extern_static.FOO.PromoteTemps.diff Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
const_promotion_extern_static.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
const_prop_miscompile.bar.ConstProp.diff
const_prop_miscompile.foo.ConstProp.diff
const_prop_miscompile.rs
coverage_graphviz.bar.InstrumentCoverage.0.dot Bless graphviz tests 2022-11-14 15:11:30 +01:00
coverage_graphviz.main.InstrumentCoverage.0.dot Bless graphviz tests 2022-11-14 15:11:30 +01:00
coverage_graphviz.rs
deaggregator_test_enum_2.rs
deaggregator_test_enum_2.test1.Deaggregator.diff
deaggregator_test_enum.bar.Deaggregator.diff
deaggregator_test_enum.rs
deaggregator_test_multiple.rs
deaggregator_test_multiple.test.Deaggregator.diff
deaggregator_test.bar.Deaggregator.diff
deaggregator_test.rs
deduplicate_blocks.is_line_doc_comment_2.DeduplicateBlocks.diff
deduplicate_blocks.rs
derefer_complex_case.main.Derefer.diff
derefer_complex_case.rs
derefer_inline_test.main.Derefer.diff
derefer_inline_test.rs
derefer_terminator_test.main.Derefer.diff
derefer_terminator_test.rs
derefer_test_multiple.main.Derefer.diff
derefer_test_multiple.rs
derefer_test.main.Derefer.diff
derefer_test.rs
early_otherwise_branch_3_element_tuple.opt1.EarlyOtherwiseBranch.diff
early_otherwise_branch_3_element_tuple.rs
early_otherwise_branch_68867.rs
early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff
early_otherwise_branch_noopt.noopt1.EarlyOtherwiseBranch.diff
early_otherwise_branch_noopt.rs
early_otherwise_branch_soundness.no_deref_ptr.EarlyOtherwiseBranch.diff
early_otherwise_branch_soundness.no_downcast.EarlyOtherwiseBranch.diff
early_otherwise_branch_soundness.rs
early_otherwise_branch.opt1.EarlyOtherwiseBranch.diff
early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff
early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff
early_otherwise_branch.rs
equal_true.opt.InstCombine.diff
equal_true.rs
exponential_or.match_tuple.SimplifyCfg-initial.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
exponential_or.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
fn_ptr_shim.core.ops-function-Fn-call.AddMovesForPackedDrops.before.mir
fn_ptr_shim.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
funky_arms.float_to_exponential_common.ConstProp.diff
funky_arms.rs
generator_drop_cleanup.main-{closure#0}.generator_drop.0.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
generator_drop_cleanup.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
generator_storage_dead_unwind.main-{closure#0}.StateTransform.before.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
generator_storage_dead_unwind.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
generator_tiny.main-{closure#0}.generator_resume.0.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
generator_tiny.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
graphviz.main.built.after.dot Replace mir_map.0 dump with built phase change dump 2022-10-27 00:21:57 -07:00
graphviz.rs Replace mir_map.0 dump with built phase change dump 2022-10-27 00:21:57 -07:00
if_condition_int.dont_opt_bool.SimplifyComparisonIntegral.diff Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
if_condition_int.dont_opt_floats.SimplifyComparisonIntegral.diff Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
if_condition_int.dont_remove_comparison.SimplifyComparisonIntegral.diff Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
if_condition_int.opt_char.SimplifyComparisonIntegral.diff Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
if_condition_int.opt_i8.SimplifyComparisonIntegral.diff Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
if_condition_int.opt_multiple_ifs.SimplifyComparisonIntegral.diff Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
if_condition_int.opt_negative.SimplifyComparisonIntegral.diff Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
if_condition_int.opt_u32.SimplifyComparisonIntegral.diff Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
if_condition_int.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
instrument_coverage.bar.InstrumentCoverage.diff
instrument_coverage.main.InstrumentCoverage.diff
instrument_coverage.rs
issue_38669.main.SimplifyCfg-initial.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_38669.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_41110.main.ElaborateDrops.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_41110.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_41110.test.ElaborateDrops.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_41697.{impl#0}-{constant#0}.SimplifyCfg-promote-consts.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_41697.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_41888.main.ElaborateDrops.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_41888.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_62289.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_62289.test.ElaborateDrops.before.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_72181_1.f.built.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_72181_1.main.built.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_72181_1.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_72181.bar.built.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_72181.foo.built.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_72181.main.built.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_72181.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_73223.main.SimplifyArmIdentity.diff Update other test results 2022-11-07 10:35:12 +01:00
issue_73223.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_76432.rs
issue_76432.test.SimplifyComparisonIntegral.diff
issue_78192.f.InstCombine.diff Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_78192.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_91633.bar.built.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_91633.foo.built.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_91633.fun.built.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_91633.hey.built.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_91633.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_99325.main.built.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_99325.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
issue_101973.inner.ConstProp.diff Fix rebase 2022-11-07 11:01:44 +01:00
issue_101973.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
loop_test.main.SimplifyCfg-promote-consts.after.mir
loop_test.rs
lower_array_len_e2e.array_bound_mut.PreCodegen.after.mir
lower_array_len_e2e.array_bound.PreCodegen.after.mir
lower_array_len_e2e.array_len_by_value.PreCodegen.after.mir
lower_array_len_e2e.array_len.PreCodegen.after.mir
lower_array_len_e2e.rs
lower_array_len.array_bound_mut.NormalizeArrayLen.diff
lower_array_len.array_bound.NormalizeArrayLen.diff
lower_array_len.array_len_by_value.NormalizeArrayLen.diff
lower_array_len.array_len.NormalizeArrayLen.diff
lower_array_len.rs
lower_intrinsics_e2e.f_u64.PreCodegen.after.mir Rebase onto master 2022-11-07 10:35:13 +01:00
lower_intrinsics_e2e.f_unit.PreCodegen.after.mir
lower_intrinsics_e2e.rs
lower_intrinsics.align_of.LowerIntrinsics.diff
lower_intrinsics.assume.LowerIntrinsics.diff
lower_intrinsics.discriminant.LowerIntrinsics.diff
lower_intrinsics.f_copy_nonoverlapping.LowerIntrinsics.diff
lower_intrinsics.forget.LowerIntrinsics.diff
lower_intrinsics.non_const.LowerIntrinsics.diff
lower_intrinsics.rs
lower_intrinsics.size_of.LowerIntrinsics.diff
lower_intrinsics.unreachable.LowerIntrinsics.diff
lower_intrinsics.wrapping.LowerIntrinsics.diff
lower_slice_len.bound.LowerSliceLenCalls.diff
lower_slice_len.rs
match_arm_scopes.complicated_match.SimplifyCfg-initial.after-ElaborateDrops.after.diff Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
match_arm_scopes.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
match_test.main.SimplifyCfg-initial.after.mir
match_test.rs
matches_reduce_branches.bar.MatchBranchSimplification.diff
matches_reduce_branches.foo.MatchBranchSimplification.diff
matches_reduce_branches.match_nested_if.MatchBranchSimplification.diff
matches_reduce_branches.rs
matches_u8.exhaustive_match_i8.MatchBranchSimplification.diff
matches_u8.exhaustive_match.MatchBranchSimplification.diff
matches_u8.rs
multiple_return_terminators.rs
multiple_return_terminators.test.MultipleReturnTerminators.diff
no_drop_for_inactive_variant.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
no_drop_for_inactive_variant.unwrap.SimplifyCfg-elaborate-drops.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
no_spurious_drop_after_call.main.ElaborateDrops.before.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
no_spurious_drop_after_call.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
not_equal_false.opt.InstCombine.diff
not_equal_false.rs
nrvo_simple.nrvo.RenameReturnPlace.diff Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
nrvo_simple.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
packed_struct_drop_aligned.main.SimplifyCfg-elaborate-drops.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
packed_struct_drop_aligned.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
README.md
remove_fake_borrows.match_guard.CleanupNonCodegenStatements.diff
remove_fake_borrows.rs
remove_never_const.no_codegen.PreCodegen.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
remove_never_const.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
remove_storage_markers.main.RemoveStorageMarkers.diff
remove_storage_markers.rs
remove_unneeded_drops.cannot_opt_generic.RemoveUnneededDrops.diff
remove_unneeded_drops.dont_opt.RemoveUnneededDrops.diff
remove_unneeded_drops.opt_generic_copy.RemoveUnneededDrops.diff
remove_unneeded_drops.opt.RemoveUnneededDrops.diff
remove_unneeded_drops.rs
remove_zsts_dont_touch_unions.get_union.RemoveZsts.after.mir
remove_zsts_dont_touch_unions.rs
retag.{impl#0}-foo_shr.SimplifyCfg-elaborate-drops.after.mir
retag.{impl#0}-foo.SimplifyCfg-elaborate-drops.after.mir
retag.array_casts.SimplifyCfg-elaborate-drops.after.mir
retag.core.ptr-drop_in_place.Test.SimplifyCfg-make_shim.after.mir
retag.main-{closure#0}.SimplifyCfg-elaborate-drops.after.mir
retag.main.SimplifyCfg-elaborate-drops.after.mir
retag.rs
return_an_array.rs
separate_const_switch.identity.SeparateConstSwitch.diff
separate_const_switch.rs
separate_const_switch.too_complex.SeparateConstSwitch.diff
simplify_arm_identity.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
simplify_arm.id_try.SimplifyArmIdentity.diff
simplify_arm.id_try.SimplifyBranchSame.diff
simplify_arm.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
simplify_cfg.main.SimplifyCfg-early-opt.diff
simplify_cfg.main.SimplifyCfg-initial.diff
simplify_cfg.rs
simplify_if.main.SimplifyConstCondition-after-const-prop.diff
simplify_if.rs
simplify_locals_fixedpoint.foo.SimplifyLocals.diff Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
simplify_locals_fixedpoint.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
simplify_locals_removes_unused_consts.main.SimplifyLocals.diff Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
simplify_locals_removes_unused_consts.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
simplify_locals_removes_unused_discriminant_reads.map.SimplifyLocals.diff Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
simplify_locals_removes_unused_discriminant_reads.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
simplify_locals.c.SimplifyLocals.diff Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
simplify_locals.d1.SimplifyLocals.diff Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
simplify_locals.d2.SimplifyLocals.diff Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
simplify_locals.expose_addr.SimplifyLocals.diff Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
simplify_locals.r.SimplifyLocals.diff Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
simplify_locals.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
simplify_locals.t1.SimplifyLocals.diff Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
simplify_locals.t2.SimplifyLocals.diff Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
simplify_locals.t3.SimplifyLocals.diff Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
simplify_locals.t4.SimplifyLocals.diff Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
simplify_match.main.ConstProp.diff
simplify_match.rs
simplify_try_if_let.{impl#0}-append.SimplifyArmIdentity.diff
simplify_try_if_let.rs
slice_drop_shim.core.ptr-drop_in_place.[String].AddMovesForPackedDrops.before.mir
slice_drop_shim.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
spanview_block.main.built.after.html Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
spanview_block.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
spanview_statement.main.built.after.html Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
spanview_statement.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
spanview_terminator.main.built.after.html Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
spanview_terminator.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
storage_ranges.main.nll.0.mir
storage_ranges.rs
tls_access.main.PreCodegen.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
tls_access.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
try_identity_e2e.new.PreCodegen.after.mir
try_identity_e2e.old.PreCodegen.after.mir
try_identity_e2e.rs
uninhabited_enum_branching2.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir
uninhabited_enum_branching2.main.UninhabitedEnumBranching.diff
uninhabited_enum_branching2.rs
uninhabited_enum_branching.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir
uninhabited_enum_branching.main.UninhabitedEnumBranching.diff
uninhabited_enum_branching.rs
uninhabited_enum.process_never.SimplifyLocals.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
uninhabited_enum.process_void.SimplifyLocals.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
uninhabited_enum.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
uninhabited_fallthrough_elimination.eliminate_fallthrough.UninhabitedEnumBranching.diff
uninhabited_fallthrough_elimination.keep_fallthrough.UninhabitedEnumBranching.diff
uninhabited_fallthrough_elimination.rs
unreachable_diverging.main.UnreachablePropagation.diff
unreachable_diverging.rs
unreachable.main.UnreachablePropagation.diff
unreachable.rs
unusual_item_types.{impl#0}-ASSOCIATED_CONSTANT.built.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
unusual_item_types.core.ptr-drop_in_place.Vec_i32_.AddMovesForPackedDrops.before.mir
unusual_item_types.E-V-{constant#0}.built.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
unusual_item_types.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
unusual_item_types.Test-X-{constructor#0}.built.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
while_let_loops.change_loop_body.ConstProp.diff
while_let_loops.change_loop_body.PreCodegen.after.mir
while_let_loops.rs
while_storage.rs Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00
while_storage.while_loop.PreCodegen.after.mir Ban dashes in miropt test file names 2022-11-02 15:54:46 -07:00

This folder contains tests for MIR optimizations.

The mir-opt test format emits MIR to extra files that you can automatically update by specifying --bless on the command line (just like ui tests updating .stderr files).

--blessable test format

By default 32 bit and 64 bit targets use the same dump files, which can be problematic in the presence of pointers in constants or other bit width dependent things. In that case you can add

// EMIT_MIR_FOR_EACH_BIT_WIDTH

to your test, causing separate files to be generated for 32bit and 64bit systems.

Unit testing

If you are only testing the behavior of a particular mir-opt pass on some specific input (as is usually the case), you should add

// unit-test: PassName

to the top of the file. This makes sure that other passes don't run which means you'll get the input you expected and your test won't break when other code changes.

Emit a diff of the mir for a specific optimization

This is what you want most often when you want to see how an optimization changes the MIR.

// EMIT_MIR $file_name_of_some_mir_dump.diff

Emit mir after a specific optimization

Use this if you are just interested in the final state after an optimization.

// EMIT_MIR $file_name_of_some_mir_dump.after.mir

Emit mir before a specific optimization

This exists mainly for completeness and is rarely useful.

// EMIT_MIR $file_name_of_some_mir_dump.before.mir