about summary refs log tree commit diff
path: root/tests/mir-opt
AgeCommit message (Collapse)AuthorLines
2024-06-03rustfmt `tests/mir-opt`.Nicholas Nethercote-227/+246
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-258/+299
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-05-31Revert "Auto merge of #115105 - cjgillot:dest-prop-default, r=oli-obk"Camille GILLOT-371/+422
This reverts commit cfb730450f847bb622243eaaab15e77e58d91767, reversing changes made to 91c0823ee63e793d990bb9fed898dc95b5d6db51.
2024-05-30Auto merge of #115105 - cjgillot:dest-prop-default, r=oli-obkbors-422/+371
Enable DestinationPropagation by default. ~~Based on https://github.com/rust-lang/rust/pull/115291.~~ This PR proposes to enable the destination propagation pass by default. This pass is meant to reduce the amount of copies present in MIR. At the same time, this PR removes the `RenameReturnPlace` pass, as it is currently unsound. `DestinationPropagation` is not limited to `_0`, but does not handle borrowed locals.
2024-05-29Enable DestinationPropagation by default.Camille GILLOT-422/+371
2024-05-30Rollup merge of #125701 - scottmcm:generic-from-raw-parts, r=WaffleLapkinLeón Orell Valerian Liehr-5/+15
[ACP 362] genericize `ptr::from_raw_parts` This implements https://github.com/rust-lang/libs-team/issues/362 As such, it can partially undo https://github.com/rust-lang/rust/pull/124795 , letting `slice_from_raw_parts` just call `from_raw_parts` again without re-introducing the unnecessary cast to MIR. By doing this it also removes a spurious cast from `str::from_raw_parts`. And I think it does a good job of showing the value of the ACP, since the only thing that needed new turbofishing because of this is inside `ptr::null(_mut)`, but only because `ptr::without_provenance(_mut)` doesn't support pointers to extern types, which it absolutely could (without even changing the implementation).
2024-05-29[ACP 362] genericize `ptr::from_raw_parts`Scott McMurray-5/+15
2024-05-29Auto merge of #125360 - RalfJung:packed-field-reorder, r=fmeasebors-1/+1
don't inhibit random field reordering on repr(packed(1)) `inhibit_struct_field_reordering_opt` being false means we exclude this type from random field shuffling. However, `packed(1)` types can still be shuffled! The logic was added in https://github.com/rust-lang/rust/pull/48528 since it's pointless to reorder fields in packed(1) types (there's no padding that could be saved) -- but that shouldn't inhibit `-Zrandomize-layout` (which did not exist at the time). We could add an optimization elsewhere to not bother sorting the fields for `repr(packed)` types, but I don't think that's worth the effort. This *does* change the behavior in that we may now reorder fields of `packed(1)` structs (e.g. if there are niches, we'll try to move them to the start/end, according to `NicheBias`). We were always allowed to do that but so far we didn't. Quoting the [reference](https://doc.rust-lang.org/reference/type-layout.html): > On their own, align and packed do not provide guarantees about the order of fields in the layout of a struct or the layout of an enum variant, although they may be combined with representations (such as C) which do provide such guarantees.
2024-05-28Add custom mir support for `PtrMetadata`Scott McMurray-0/+23
2024-05-28Add an intrinsic for `ptr::metadata`Scott McMurray-14/+141
2024-05-28Create const block DefIds in typeck instead of ast loweringOli Scherer-1/+1
2024-05-26Rollup merge of #125559 - scottmcm:simplify-shift-ubcheck, r=workingjubileeJubilee-4/+4
Simplify the `unchecked_sh[lr]` ub-checks a bit It can use the constant in the check, rather than passing it as a parameter.
2024-05-26Auto merge of #125518 - saethlin:check-arguments-new-in-const, r=joboetbors-69/+61
Move the checks for Arguments constructors to inline const Thanks `@Skgland` for pointing out this opportunity: https://github.com/rust-lang/rust/pull/117804#discussion_r1612964362
2024-05-25Simplify the `unchecked_sh[lr]` ub-checks a bitScott McMurray-4/+4
2024-05-24Move the checks for Arguments constructors to inline constBen Kimock-69/+61
2024-05-23Add assert_unsafe_precondition to unchecked_{add,sub,neg,mul,shl,shr} methodsltdk-148/+128
2024-05-21don't inhibit random field reordering on repr(packed(1))Ralf Jung-1/+1
2024-05-20Rollup merge of #125173 - scottmcm:never-checked, r=davidtwcoMatthias Krüger-45/+45
Remove `Rvalue::CheckedBinaryOp` Zulip conversation: <https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/intrinsics.20vs.20binop.2Funop/near/438729996> cc `@RalfJung` While it's a draft, r? ghost
2024-05-20Rollup merge of #125106 - Zalathar:expressions, r=davidtwcoMatthias Krüger-10/+4
coverage: Memoize and simplify counter expressions When creating coverage counter expressions as part of coverage instrumentation, we often end up creating obviously-redundant expressions like `c1 + (c0 - c1)`, which is equivalent to just `c0`. To avoid doing so, this PR checks when we would create an expression matching one of 5 patterns, and uses the simplified form instead: - `(a - b) + b` → `a`. - `(a + b) - b` → `a`. - `(a + b) - a` → `b`. - `a + (b - a)` → `b`. - `a - (a - b)` → `b`. Of all the different ways to combine 3 operands and 2 operators, these are the patterns that allow simplification. (Some of those patterns currently don't occur in practice, but are included anyway for completeness, to avoid having to add them later as branch coverage and MC/DC coverage support expands.) --- This PR also adds memoization for newly-created (or newly-simplified) counter expressions, to avoid creating duplicates. This currently makes no difference to the final mappings, but is expected to be useful for MC/DC coverage of match expressions, as proposed by https://github.com/rust-lang/rust/pull/124278#issuecomment-2106754753.
2024-05-17Remove `Rvalue::CheckedBinaryOp`Scott McMurray-45/+45
2024-05-17Rename Unsafe to SafetySantiago Pastorino-10/+10
2024-05-14coverage: Simplify counter expressions using simple algebraZalathar-10/+4
Some of these cases currently don't occur in practice, but are included for completeness, and to avoid having to add them later as branch coverage and MC/DC coverage start building more complex expressions.
2024-05-08Auto merge of #124795 - scottmcm:simplify-slice-from-raw-parts, r=joboetbors-76/+128
Avoid a cast in `ptr::slice_from_raw_parts(_mut)` Casting to `*const ()` or `*mut ()` is no longer needed after https://github.com/rust-lang/rust/pull/123840 so let's make the MIR smaller (and more inline-able, as seen in the tests). If [ACP#362](https://github.com/rust-lang/libs-team/issues/362) goes through we can keep calling `ptr::from_raw_parts(_mut)` in these also without the cast, but that hasn't had any libs-api attention yet, so I'm not waiting on it.
2024-05-07Auto merge of #123332 - Nadrieril:testkind-never, r=matthewjasperbors-0/+155
never patterns: lower never patterns to `Unreachable` in MIR This lowers a `!` pattern to "goto Unreachable". Ideally I'd like to read from the place to make it clear that the UB is coming from an invalid value, but that's tricky so I'm leaving it for later. r? `@compiler-errors` how do you feel about a lil bit of MIR lowering
2024-05-06Avoid a cast in `ptr::slice_from_raw_parts(_mut)`Scott McMurray-76/+128
Casting to `*const ()` or `*mut ()` just bloats the MIR, so let's not. If ACP#362 goes through we can keep calling `ptr::from_raw_parts(_mut)` in these also without the cast, but that hasn't had any libs-api attention yet, so I'm not waiting on it.
2024-05-05Rollup merge of #124749 - RossSmyth:stable_range, r=davidtwcoGuillaume Gomez-1/+0
Stabilize exclusive_range_pattern (v2) This PR is identical to #124459, which was approved and merged but then removed from master by a force-push due to a [CI bug](https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/ci.20broken.3F). r? ghost Original PR description: --- Stabilization report: https://github.com/rust-lang/rust/issues/37854#issuecomment-1842398130 FCP: https://github.com/rust-lang/rust/issues/37854#issuecomment-1872520294 Stabilization was blocked by a lint that was merged here: #118879 Documentation PR is here: rust-lang/reference#1484 `@rustbot` label +F-exclusive_range_pattern +T-lang
2024-05-04Lower never patterns to Unreachable in mirNadrieril-17/+101
2024-05-04Add testsNadrieril-0/+71
2024-05-03Auto merge of #123602 - cjgillot:gvn-borrowed, r=oli-obkbors-206/+499
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-05-02Stabilize exclusive_rangeRoss Smyth-1/+0
2024-04-28Update mir-opt tests, add proper regression testGeorge Bateman-510/+172
2024-04-24Fix tests and blessGary Guo-4/+3
2024-04-24Error on using `yield` without also using `#[coroutine]` on the closureOli Scherer-39/+43
And suggest adding the `#[coroutine]` to the closure
2024-04-23Rollup merge of #122598 - Nadrieril:full-derefpats, r=matthewjasperLeón Orell Valerian Liehr-74/+74
deref patterns: lower deref patterns to MIR This lowers deref patterns to MIR. This is a bit tricky because this is the first kind of pattern that requires storing a value in a temporary. Thanks to https://github.com/rust-lang/rust/pull/123324 false edges are no longer a problem. The thing I'm not confident about is the handling of fake borrows. This PR ignores any fake borrows inside a deref pattern. We are guaranteed to at least fake borrow the place of the first pointer value, which could be enough, but I'm not certain.
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-22coverage: Add a mir-opt test for branch coverage of match armsZalathar-0/+165
2024-04-22coverage: Move mir-opt coverage tests into a subdirectoryZalathar-0/+0
2024-04-21Update tests after 123949Scott McMurray-82/+0
2024-04-21InstSimplify `from_raw_parts(p, ())` → `p as _`Scott McMurray-40/+13
2024-04-21Use it in the library, and `InstSimplify` it away in the easy placesScott McMurray-18/+234
2024-04-21Add an intrinsic that lowers to AggregateKind::RawPtrScott McMurray-0/+200
2024-04-21Add a mir-opt test for `byte_add` on pointersScott McMurray-0/+248
2024-04-21Add a MIR pre-codegen test for Vec::derefScott McMurray-0/+41
2024-04-21New slice indexing pre-codegen MIR testScott McMurray-0/+47
2024-04-20Use newly exposed Freeze trait.Camille GILLOT-54/+58
2024-04-20Dereference immutable borrows in GVN.Camille GILLOT-33/+57
2024-04-20Merge borrowed locals too.Camille GILLOT-111/+80
2024-04-20GVN borrowed locals too.Camille GILLOT-79/+52