rust/src/test/mir-opt
Wesley Wiser 2ec73395b9 Improve SimplifyLocals pass so it can remove unused consts
The `ConstProp` can cause many locals to be initialized to a constant
value and then never read from. `ConstProp` can also evaluate ZSTs into
constant values. Previously, many of these would be removed by other
parts of the MIR optimization pipeline. However, evaluating ZSTs
(especially `()`) into constant values defeated those parts of the
optimizer and so in a2e3ed5c05, I added a
hack to `ConstProp` that skips evaluating ZSTs to avoid that regression.

This commit changes `SimplifyLocals` so that it doesn't consider writes
of const values to a local to be a use of that local. In doing so,
`SimplifyLocals` is able to remove otherwise unused locals left behind
by other optimization passes (`ConstProp` in particular).
2019-10-20 23:49:42 -04:00
..
const_prop [const-prop] Handle MIR Rvalue::Box 2019-10-18 19:16:49 -04:00
nll Use as_temp to evaluate statement expressions 2019-06-25 22:41:22 +01:00
array-index-is-temporary.rs Evaluate hair::ExprKind::Use in into 2019-04-24 19:38:02 +01:00
basic_assignment.rs Remove unnecessary ignore-tidy-linelength 2019-04-23 11:42:14 +01:00
box_expr.rs Upgrade Emscripten targets to use upstream LLVM backend 2019-10-16 17:06:48 -07:00
byte_slice.rs u8 is printed as a number, not a character 2019-05-25 10:07:01 +02:00
combine_array_len.rs Remove licenses 2018-12-25 21:08:33 -07:00
copy_propagation.rs Remove licenses 2018-12-25 21:08:33 -07:00
copy_propagation_arg.rs Use as_temp to evaluate statement expressions 2019-06-25 22:41:22 +01:00
deaggregator_test.rs Remove licenses 2018-12-25 21:08:33 -07:00
deaggregator_test_enum.rs Remove licenses 2018-12-25 21:08:33 -07:00
deaggregator_test_enum_2.rs Create fewer basic blocks in match MIR lowering 2019-06-13 21:05:21 +01:00
deaggregator_test_multiple.rs Remove licenses 2018-12-25 21:08:33 -07:00
generator-drop-cleanup.rs Use as_temp to evaluate statement expressions 2019-06-25 22:41:22 +01:00
generator-storage-dead-unwind.rs Upgrade Emscripten targets to use upstream LLVM backend 2019-10-16 17:06:48 -07:00
graphviz.rs cleanup: Remove DefIndexAddressSpace 2019-05-09 00:46:38 +03:00
inline-any-operand.rs Always emit an error for a query cycle 2019-02-15 03:51:47 +01:00
inline-closure-borrows-arg.rs cleanup: Remove DefIndexAddressSpace 2019-05-09 00:46:38 +03:00
inline-closure.rs cleanup: Remove DefIndexAddressSpace 2019-05-09 00:46:38 +03:00
inline-retag.rs Always emit an error for a query cycle 2019-02-15 03:51:47 +01:00
inline-trait-method.rs Print generic args in function calls in MIR 2019-05-25 10:07:01 +02:00
inline-trait-method_2.rs Print generic args in function calls in MIR 2019-05-25 10:07:01 +02:00
issue-38669.rs Use as_temp to evaluate statement expressions 2019-06-25 22:41:22 +01:00
issue-41110.rs Upgrade Emscripten targets to use upstream LLVM backend 2019-10-16 17:06:48 -07:00
issue-41697.rs rustc: rename item_path to def_path (except the module in ty). 2019-03-15 13:25:10 +02:00
issue-41888.rs Remove licenses 2018-12-25 21:08:33 -07:00
issue-49232.rs Use as_temp to evaluate statement expressions 2019-06-25 22:41:22 +01:00
issue-62289.rs Upgrade Emscripten targets to use upstream LLVM backend 2019-10-16 17:06:48 -07:00
loop_test.rs Only omit StorageLive/Dead for variable that are never initialized 2019-07-07 15:04:43 +01:00
match-arm-scopes.rs Update tests wrt. bind_by_by_move_pattern_guards stabilization. 2019-09-08 01:39:24 +02:00
match_false_edges.rs Add StorageDead statements for while conditions 2019-06-25 22:41:22 +01:00
match_test.rs Add StorageDead statements for while conditions 2019-06-25 22:41:22 +01:00
no-spurious-drop-after-call.rs Upgrade Emscripten targets to use upstream LLVM backend 2019-10-16 17:06:48 -07:00
packed-struct-drop-aligned.rs Upgrade Emscripten targets to use upstream LLVM backend 2019-10-16 17:06:48 -07:00
README.md fix more typos found by codespell. 2018-02-17 17:38:49 +01:00
remove_fake_borrows.rs Upgrade Emscripten targets to use upstream LLVM backend 2019-10-16 17:06:48 -07:00
retag.rs Upgrade Emscripten targets to use upstream LLVM backend 2019-10-16 17:06:48 -07:00
return_an_array.rs Remove licenses 2018-12-25 21:08:33 -07:00
simple-match.rs Add a test for simple matches 2019-06-13 21:05:21 +01:00
simplify-locals-removes-unused-consts.rs Improve SimplifyLocals pass so it can remove unused consts 2019-10-20 23:49:42 -04:00
simplify_cfg.rs Make SimplifyCfg collapse goto chains from bb0 2018-12-13 12:01:15 +09:00
simplify_if.rs Create fewer basic blocks in match MIR lowering 2019-06-13 21:05:21 +01:00
simplify_match.rs Create fewer basic blocks in match MIR lowering 2019-06-13 21:05:21 +01:00
slice-drop-shim.rs Improve SimplifyLocals pass so it can remove unused consts 2019-10-20 23:49:42 -04:00
storage_live_dead_in_statics.rs Schedule storage-dead of temporaries sooner 2019-05-21 19:37:38 +01:00
storage_ranges.rs Use as_temp to evaluate statement expressions 2019-06-25 22:41:22 +01:00
uniform_array_move_out.rs Use new 'p @ ..' syntax in tests. 2019-07-28 06:53:39 +02:00
uninhabited-enum.rs Add a mir-opt test 2018-12-11 12:18:51 +00:00
unusual-item-types.rs Don't run MIR passes on constructor shims 2019-06-06 16:10:37 +01:00
while-storage.rs Bless mir-opt/while-storage.rs. 2019-07-06 06:43:58 +02:00

This folder contains tests for MIR optimizations.

The test format is:

(arbitrary rust code)
// END RUST SOURCE
// START $file_name_of_some_mir_dump_0
//  $expected_line_0
// (lines or elision)
// $expected_line_N
// END $file_name_of_some_mir_dump_0
// (lines or elision)
// START $file_name_of_some_mir_dump_N
//  $expected_line_0
// (lines or elision)
// $expected_line_N
// END $file_name_of_some_mir_dump_N

All the test information is in comments so the test is runnable.

For each $file_name, compiletest expects [$expected_line_0, ..., $expected_line_N] to appear in the dumped MIR in order. Currently it allows other non-matched lines before and after, but not between $expected_lines, should you want to skip lines, you must include an elision comment, of the form (as a regex) //\s*...\s*. The lines will be skipped lazily, that is, if there are two identical lines in the output that match the line after the elision comment, the first one will be matched.

Examples:

The following blocks will not match the one after it.

bb0: {
    StorageLive(_1);
    _1 = const true;
    StorageDead(_1);
}
bb0: {
    StorageLive(_1);
    _1 = const true;
    goto -> bb1
}
bb1: {
    StorageDead(_1);
    return;
}

But this will match the one above,

bb0: {
    StorageLive(_1);
    _1 = const true;
    ...
    StorageDead(_1);
    ...
}

Lines match ignoring whitespace, and the prefix "//" is removed.

It also currently strips trailing comments -- partly because the full file path in "scope comments" is unpredictable and partly because tidy complains about the lines being too long.

compiletest handles dumping the MIR before and after every pass for you. The test writer only has to specify the file names of the dumped files (not the full path to the file) and what lines to expect. There is an option to rustc that tells it to dump the mir into some directly (rather then always dumping to the current directory).