about summary refs log tree commit diff
path: root/tests/mir-opt/instsimplify
AgeCommit message (Collapse)AuthorLines
2025-09-16Add test.Camille Gillot-1/+153
2025-09-16Remove Rvalue::Len.Camille Gillot-0/+157
2025-07-28Simplify `align_of_val::<[T]>(…)` → `align_of::<T>()`Scott McMurray-3/+4
2025-07-28Add a MIR test for `align_of_val` on a sliceScott McMurray-0/+33
2025-07-23Give an AllocId to ConstValue::Slice.Camille GILLOT-0/+4
2025-05-21Add some track_caller info to precondition panicsBen Kimock-1/+1
2025-04-21mir-opt: execute MatchBranchSimplification after GVNdianqk-9/+9
This can provide more opportunities for MatchBranchSimplification.
2025-03-11Migrate core to Rust 2024Eric Huss-6/+6
2025-01-27Reapply "Auto merge of #133734 - scottmcm:lower-indexing-to-ptrmetadata, ↵Michael Goulet-169/+0
r=davidtwco,RalfJung" This reverts commit 122a55bb442bd1995df9cf9b36e6f65ed3ef4a1d.
2025-01-18Revert "Auto merge of #133734 - scottmcm:lower-indexing-to-ptrmetadata, ↵Rémy Rakic-0/+169
r=davidtwco,RalfJung" This reverts commit b57d93d8b9525fa261404b4cd9c0670eeb1264b8, reversing changes made to 0aeaa5eb22180fdf12a8489e63c4daa18da6f236.
2025-01-11Address PR feedbackScott McMurray-4/+23
2025-01-11[mir-opt] simplify `Repeat`s that don't actually repeat the operandScott McMurray-0/+31
2025-01-11Auto merge of #135274 - saethlin:array-repeats, r=compiler-errorsbors-0/+146
Add an InstSimplify for repetitive array expressions I noticed in https://github.com/rust-lang/rust/pull/135068#issuecomment-2569955426 that GVN's implementation of this same transform was quite profitable on the deep-vector benchmark. But of course GVN doesn't run in unoptimized builds, so this is my attempt to write a version of this transform that benefits the deep-vector case and is fast enough to run in InstSimplify. The benchmark suite indicates that this is effective.
2025-01-09Add an InstSimplify for repetitive array expressionsBen Kimock-0/+146
2025-01-08[mir-opt] GVN some more transmute casesScott McMurray-97/+41
We already did `Transmute`-then-`PtrToPtr`; this adds the nearly-identical `PtrToPtr`-then-`Transmute`. It also adds `transmute(Foo(x))` → `transmute(x)`, when `Foo` is a single-field transparent type. That's useful for things like `NonNull { pointer: p }.as_ptr()`. Found these as I was looking at MCP807-related changes.
2024-12-03Bounds-check with PtrMetadata instead of Len in MIRScott McMurray-169/+0
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-1/+1
2024-08-19Auto merge of #122551 - RayMuir:copy_fmt, r=saethlinbors-58/+58
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-51/+51
2024-08-18Update mir-opt filechecksScott McMurray-7/+7
2024-08-18stabilize raw_ref_opRalf Jung-1/+0
2024-07-29Perform instsimplify before inline to eliminate some trivial callsDianQK-83/+83
2024-06-19Ban `ArrayToPointer` and `MutToConstPointer` from runtime MIRScott McMurray-2/+2
Apparently MIR borrowck cares about at least one of these for checking variance. In runtime MIR, though, there's no need for them as `PtrToPtr` does the same thing. (Banning them simplifies passes like GVN that no longer need to handle multiple cast possibilities.)
2024-06-03rustfmt `tests/mir-opt`.Nicholas Nethercote-4/+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-2/+2
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-30Also InstSimplify `&raw*`Scott McMurray-0/+156
We do this for `&*` and `&mut*` already; might as well do it for raw pointers too.
2024-04-22Rollup merge of #124230 - reitermarkus:generic-nonzero-stable, r=dtolnayGuillaume Gomez-1/+0
Stabilize generic `NonZero`. Tracking issue: https://github.com/rust-lang/rust/issues/120257 r? `@dtolnay`
2024-04-22Stabilize generic `NonZero`.Markus Reiter-1/+0
2024-04-21InstSimplify `from_raw_parts(p, ())` → `p as _`Scott McMurray-0/+9
2024-04-20mir-opt tests: rename unit-test -> test-mir-passRalf Jung-8/+8
2024-04-18At debuginfo=0, don't inline debuginfo when inliningScott McMurray-3/+0
2024-04-03Remove MIR unsafe checkMatthew Jasper-17/+11
This also remove safety information from MIR.
2024-03-27Eliminate `UbCheck` for non-standard librariesDianQK-0/+75
2024-03-10MIR printing: print the path of uneval'd const; refer to promoteds in a ↵Ralf Jung-1/+1
consistent way
2024-02-25Use generic `NonZero` in tests.Markus Reiter-2/+2
2024-02-22[AUTO_GENERATED] Migrate compiletest to use `ui_test`-style `//@` directives许杰友 Jieyou Xu (Joe)-9/+9
2024-01-27Update tests.Markus Reiter-2/+2
2023-10-25Never consider raw pointer casts to be trivalNilstrieb-15/+25
HIR typeck tries to figure out which casts are trivial by doing them as coercions and seeing whether this works. Since HIR typeck is oblivious of lifetimes, this doesn't work for pointer casts that only change the lifetime of the pointee, which are, as borrowck will tell you, not trivial. This change makes it so that raw pointer casts are never considered trivial. This also incidentally fixes the "trivial cast" lint false positive on the same code. Unfortunately, "trivial cast" lints are now never emitted on raw pointer casts, even if they truly are trivial. This could be fixed by also doing the lint in borrowck for raw pointers specifically.
2023-10-19FileCheck casts.Camille GILLOT-0/+75
2023-10-19FileCheck combine_transmutes.Camille GILLOT-0/+211
2023-10-19FileCheck duplicate_switch_targets.Camille GILLOT-0/+50
2023-10-19FileCheck intrinsic_asserts.Camille GILLOT-0/+174
2023-10-19FileCheck combine_clone_of_primitives.Camille GILLOT-0/+162
2023-10-19FileCheck bool_compare.Camille GILLOT-0/+356
2023-10-19FileCheck combine_array_len.Camille GILLOT-0/+169