about summary refs log tree commit diff
path: root/tests/mir-opt/copy-prop
AgeCommit message (Collapse)AuthorLines
2025-07-10Propagate from borrowed locals in CopyPropTomasz Miąsko-10/+11
2025-07-06Do not unify borrowed locals in CopyProp.Camille GILLOT-12/+246
2025-06-16Reason about borrowed classes in CopyProp.Camille GILLOT-4/+3
2025-06-16Add test.Camille GILLOT-0/+76
2025-01-27Reapply "Auto merge of #133734 - scottmcm:lower-indexing-to-ptrmetadata, ↵Michael Goulet-14/+10
r=davidtwco,RalfJung" This reverts commit 122a55bb442bd1995df9cf9b36e6f65ed3ef4a1d.
2025-01-18Revert "Auto merge of #133734 - scottmcm:lower-indexing-to-ptrmetadata, ↵Rémy Rakic-10/+14
r=davidtwco,RalfJung" This reverts commit b57d93d8b9525fa261404b4cd9c0670eeb1264b8, reversing changes made to 0aeaa5eb22180fdf12a8489e63c4daa18da6f236.
2024-12-03Bounds-check with PtrMetadata instead of Len in MIRScott McMurray-14/+10
2024-09-24be even more precise about "cast" vs "coercion"Lukas Markeffsky-2/+2
2024-08-19Auto merge of #122551 - RayMuir:copy_fmt, r=saethlinbors-131/+131
Added "copy" to Debug fmt for copy operands In MIR's debug mode (--emit mir) the printing for Operands is slightly inconsistent. The RValues - values on the right side of an Assign - are usually printed with their Operand when they are Places. Example: _2 = move _3 But for arguments, the operand is omitted. _2 = _1 I propose a change be made, to display the place with the operand. _2 = copy _1 Move and copy have different semantics, meaning this difference is important and helpful to the user. It also adds consistency to the pretty printing. -- EDIT -- Consider this example Rust program and its MIR output with the **updated pretty printer.** This was generated with the arguments --emit mir --crate-type lib -Zmir-opt-level=0 (Otherwise, it's optimised away since it's a junk program). ```rust fn main(foo: i32) { let v = 10; if v == 20 { foo; } else { v; } } ``` ```MIR // WARNING: This output format is intended for human consumers only // and is subject to change without notice. Knock yourself out. fn main(_1: i32) -> () { debug foo => _1; let mut _0: (); let _2: i32; let mut _3: bool; let mut _4: i32; let _5: i32; let _6: i32; scope 1 { debug v => _2; } bb0: { StorageLive(_2); _2 = const 10_i32; StorageLive(_3); StorageLive(_4); _4 = copy _2; _3 = Eq(move _4, const 20_i32); switchInt(move _3) -> [0: bb2, otherwise: bb1]; } bb1: { StorageDead(_4); StorageLive(_5); _5 = copy _1; StorageDead(_5); _0 = const (); goto -> bb3; } bb2: { StorageDead(_4); StorageLive(_6); _6 = copy _2; StorageDead(_6); _0 = const (); goto -> bb3; } bb3: { StorageDead(_3); StorageDead(_2); return; } } ``` In this example program, we can see that when we move a place, it is preceded by "move". e.g. ``` _3 = Eq(move _4, const 20_i32);```. However, when we copy a place such as ```_5 = _1;```, it is not preceded by the operand in the original printout. I propose to change the print to include the copy ```_5 = copy _1``` as in this example. Regarding the arguments part. When I originally submitted this PR, I was under the impression this only affected the print for arguments to a function, but actually, it affects anything that uses a copy. This is preferable anyway with regard to consistency. The PR is about making ```copy``` explicit.
2024-08-18Bless *all* the mir-opt testsScott McMurray-123/+123
2024-08-18Update mir-opt filechecksScott McMurray-8/+8
2024-08-18stabilize raw_ref_opRalf Jung-2/+0
2024-06-03rustfmt `tests/mir-opt`.Nicholas Nethercote-3/+7
The only non-obvious changes: - `building/storage_live_dead_in_statics.rs` has a `#[rustfmt::skip]` attribute to avoid reformating a table of data. - Two `.mir` files have slight changes involving line numbers. - In `unusual_item_types.rs` an `EMIT_MIR` annotation is moved to outside a function, which is the usual spot, because `tidy` complains if such a comment is indented. The commit also tweaks the comments in `rustfmt.toml`.
2024-06-03Reformat `mir!` macro invocations to use braces.Nicholas Nethercote-32/+48
The `mir!` macro has multiple parts: - An optional return type annotation. - A sequence of zero or more local declarations. - A mandatory starting anonymous basic block, which is brace-delimited. - A sequence of zero of more additional named basic blocks. Some `mir!` invocations use braces with a "block" style, like so: ``` mir! { let _unit: (); { let non_copy = S(42); let ptr = std::ptr::addr_of_mut!(non_copy); // Inside `callee`, the first argument and `*ptr` are basically // aliasing places! Call(_unit = callee(Move(*ptr), ptr), ReturnTo(after_call), UnwindContinue()) } after_call = { Return() } } ``` Some invocations use parens with a "block" style, like so: ``` mir!( let x: [i32; 2]; let one: i32; { x = [42, 43]; one = 1; x = [one, 2]; RET = Move(x); Return() } ) ``` And some invocations uses parens with a "tighter" style, like so: ``` mir!({ SetDiscriminant(*b, 0); Return() }) ``` This last style is generally used for cases where just the mandatory starting basic block is present. Its braces are placed next to the parens. This commit changes all `mir!` invocations to use braces with a "block" style. Why? - Consistency is good. - The contents of the invocation is a block of code, so it's odd to use parens. They are more normally used for function-like macros. - Most importantly, the next commit will enable rustfmt for `tests/mir-opt/`. rustfmt is more aggressive about formatting macros that use parens than macros that use braces. Without this commit's changes, rustfmt would break a couple of `mir!` macro invocations that use braces within `tests/mir-opt` by inserting an extraneous comma. E.g.: ``` mir!(type RET = (i32, bool);, { // extraneous comma after ';' RET.0 = 1; RET.1 = true; Return() }) ``` Switching those `mir!` invocations to use braces avoids that problem, resulting in this, which is nicer to read as well as being valid syntax: ``` mir! { type RET = (i32, bool); { RET.0 = 1; RET.1 = true; Return() } } ```
2024-05-03Auto merge of #123602 - cjgillot:gvn-borrowed, r=oli-obkbors-11/+166
Account for immutably borrowed locals in MIR copy-prop and GVN For the most part, we consider that immutably borrowed `Freeze` locals still fulfill SSA conditions. As the borrow is immutable, any use of the local will have the value given by the single assignment, and there can be no surprise. This allows copy-prop to merge a non-borrowed local with a borrowed local. We chose to keep copy-classes heads unborrowed, as those may be easier to optimize in later passes. This also allows to GVN the value behind an immutable borrow. If a SSA local is borrowed, dereferencing that borrow is equivalent to copying the local's value: re-executing the assignment between the borrow and the dereference would be UB. r? `@ghost` for perf
2024-04-20Use newly exposed Freeze trait.Camille GILLOT-16/+18
2024-04-20Merge borrowed locals too.Camille GILLOT-6/+7
2024-04-20Add tests.Camille GILLOT-10/+162
2024-04-20mir-opt tests: rename unit-test -> test-mir-passRalf Jung-15/+15
2024-04-03Remove MIR unsafe checkMatthew Jasper-12/+4
This also remove safety information from MIR.
2024-02-22[AUTO_GENERATED] Migrate compiletest to use `ui_test`-style `//@` directives许杰友 Jieyou Xu (Joe)-17/+17
2024-02-12Start blocks eagerlyNadrieril-10/+10
2024-01-04Fix validation and linting of injected MIRTomasz Miąsko-13/+13
Reevaluate `body.should_skip()` after updating the MIR phase to ensure that injected MIR is processed correctly. Update a few custom MIR tests that were ill-formed for the injected phase.
2023-12-26custom mir: make it clear what the return block isRalf Jung-7/+7
2023-11-14Custom MIR: Support cleanup blocksTomasz Miąsko-7/+7
Cleanup blocks are declared with `bb (cleanup) = { ... }`. `Call` and `Drop` terminators take an additional argument describing the unwind action, which is one of the following: * `UnwindContinue()` * `UnwindUnreachable()` * `UnwindTerminate(reason)`, where reason is `ReasonAbi` or `ReasonInCleanup` * `UnwindCleanup(block)` Also support unwind resume and unwind terminate terminators: * `UnwindResume()` * `UnwindTerminate(reason)`
2023-10-19Allow to run filecheck in mir-opt tests.Camille GILLOT-0/+15
2023-10-08Also consider call and yield as MIR SSA.Camille GILLOT-0/+88
2023-08-19custom_mir: change Call() terminator syntax to something more readableRalf Jung-6/+6
2023-07-10Perform reference propagation earlier.Camille GILLOT-0/+2
2023-07-07Rename `adjustment::PointerCast` and variants using it to `PointerCoercion`Nilstrieb-2/+2
It makes it sound like the `ExprKind` and `Rvalue` are supposed to represent all pointer related casts, when in reality their just used to share a some enum variants. Make it clear there these are only coercion to make it clear why only some pointer related "casts" are in the enum.
2023-06-23Bless testsGary Guo-33/+33
2023-06-15Remove comments from mir-opt MIR dumpsBen Kimock-955/+817
2023-06-12bless mir-optPietro Albini-0/+761
To reproduce the changes in this commit locally: - Run `./x test tidy` and remove all the output files not associated with a test file anymore, as reported by tidy. - Run `./x test tests/mir-opt --bless` to generate the new outputs.
2023-06-12properly mark tests that require panic=abortPietro Albini-11/+11
2023-05-14Merge return place with other locals in CopyProp.Camille GILLOT-5/+7
2023-05-10Use visit_assign to detect SSA locals.Camille GILLOT-0/+31
2023-05-09Do not consider borrowed Freeze locals as SSA.Camille GILLOT-2/+1
2023-04-06Ignore many tests on wasm32Gary Guo-23/+34
2023-02-27Do not grow `assignment_order` needlessly.Camille GILLOT-20/+87
2023-02-27Special case deref projections in SsaVisitor.Camille GILLOT-0/+187
2023-02-16Auto merge of #107449 - saethlin:enable-copyprop, r=oli-obkbors-0/+63
Enable CopyProp r? `@tmiasko` `@rustbot` label +A-mir-opt
2023-02-13Clearly document intentional UB in mir-opt testsBen Kimock-0/+10
Co-authored-by: Jakob Degen <jakob.e.degen@gmail.com>
2023-02-12Fix UB in the test caseBen Kimock-3/+4
2023-02-12Enable CopyProp by default, tune the impl a bitBen Kimock-0/+62
2023-02-04Turn projections into copies in CopyProp.Camille GILLOT-0/+65
2023-02-02Bless tests.Camille GILLOT-3/+1
2023-01-31Remove assignment.Camille GILLOT-78/+70
2023-01-31Remove both StorageLive and StorageDead in CopyProp.Camille GILLOT-4/+2
2023-01-31Add test.Camille GILLOT-0/+161
2023-01-27Do not merge locals that have their address taken.Camille GILLOT-1/+76