about summary refs log tree commit diff
path: root/tests/mir-opt
AgeCommit message (Collapse)AuthorLines
2025-09-09don't trim paths in mir dumping when filtering and at the top of the filebeepster4096-5/+5
2025-09-08pass `sub_relations` into canonical querieslcnr-9/+9
2025-09-08inline `CanonicalTyVarKind`lcnr-9/+9
2025-09-07Auto merge of #145541 - cjgillot:dest-prop-live-range, r=Amanieubors-29/+31
Reimplement DestinationPropagation according to live ranges. This PR reimplements DestinationPropagation as a problem of merging live-ranges of locals. We merge locals that have disjoint live-ranges. This allows merging several locals in the same round by updating live range information. Live ranges are mainly computed using the `MaybeLiveLocals` analysis. The subtlety is that we split each statement and terminator in 2 positions. The first position is the regular statement. The second position is a shadow, which is always more live. It encodes partial writes and dead writes as a local being live for half a statement. This half statement ensures that writes conflict with another local's writes and regular liveness. r? `@Amanieu`
2025-09-07Unify a source with all possible destinations.Camille Gillot-34/+36
2025-09-07Use regular MaybeLiveLocals.Camille Gillot-1/+5
2025-09-07Reimplement DestinationPropagation according to live ranges.Camille GILLOT-18/+14
2025-09-07Allow simplifying aggregates if LHS is not a simple local.Camille GILLOT-2/+73
2025-09-01Auto merge of #144783 - folkertdev:loop-match-diverging-loop, r=SparrowLiibors-0/+369
fix `#[loop_match]` on diverging loop tracking issue: https://github.com/rust-lang/rust/issues/132306 fixes https://github.com/rust-lang/rust/issues/144492 fixes https://github.com/rust-lang/rust/issues/144493 fixes https://github.com/rust-lang/rust/issues/144781 this generated invalid MIR before. issue https://github.com/rust-lang/rust/issues/143806 still has an issue where we assign `state = state` which is invalid in MIR. Fixing that problem is tricky, so I'd like to do that separately. r? `@bjorn3`
2025-08-26Use -Zmir-opt-level=0 in tests for MIR buildingBen Kimock-47/+69
2025-08-22Rollup merge of #142185 - saethlin:refprop-moves, r=cjgillotJacob Pratt-85/+158
Convert moves of references to copies in ReferencePropagation This is a fix for https://github.com/rust-lang/rust/issues/141101. The root cause of this miscompile is that the SsaLocals analysis that MIR transforms use is supposed to detect locals that are only written to once, in their single assignment. But that analysis is subtly wrong; it does not consider `Operand::Move` to be a write even though the meaning ascribed to `Operand::Move` (at least as a function parameter) by Miri is that the callee may have done arbitrary writes to the caller's Local that the Operand wraps (because `Move` is pass-by-pointer). So Miri conwiders `Operand::Move` to be a write but both the MIR visitor system considers it a read, and so does SsaLocals. I have tried fixing this by changing the `PlaceContext` that is ascribed to an `Operand::Move` to a `MutatingUseContext` but that seems to have borrow checker implications, and changing SsaLocals seems to have wide-ranging regressions in MIR optimizations. So instead of doing those, this PR adds a new kludge to ReferencePropagation, which follows the same line of thinking as the kludge in CopyProp that solves this same problem inside that pass: https://github.com/rust-lang/rust/blob/a5584a8fe16037dc01782064fa41424a6dbe9987/compiler/rustc_mir_transform/src/copy_prop.rs#L65-L98
2025-08-21Consolidate panicking functions in `slice/index.rs`Karl Meakin-2/+136
Consolidate all the panicking functions in `slice/index.rs` to use a single `slice_index_fail` function, similar to how it is done in `str/traits.rs`.
2025-08-18Remove the no_sanitize attribute in favor of sanitizeBastian Kersting-11/+11
This removes the #[no_sanitize] attribute, which was behind an unstable feature named no_sanitize. Instead, we introduce the sanitize attribute which is more powerful and allows to be extended in the future (instead of just focusing on turning sanitizers off). This also makes sanitize(kernel_address = ..) attribute work with -Zsanitize=address To do it the same as how clang disables address sanitizer, we now disable ASAN on sanitize(kernel_address = "off") and KASAN on sanitize(address = "off"). The same was added to clang in https://reviews.llvm.org/D44981.
2025-08-11Convert moves of references to copies in RefPropBen Kimock-85/+158
2025-08-10add place mention for `#[loop_match]` scrutineeFolkert de Vries-0/+369
2025-08-09Rollup merge of #144883 - scottmcm:remove-unneeded-drop_in_place, r=nnethercoteStuart Cook-0/+37
Remove unneeded `drop_in_place` calls Might as well pull this out from rust-lang/rust#144561 because this is still used in things like `Vec::truncate` where it'd be nice to allow it be removed if inlined enough to see that the type is `Copy`. So long as perf says it's ok, at least 🤞
2025-08-08Rollup merge of #145030 - cjgillot:gvn-no-flatten-index, r=saethlinStuart Cook-0/+140
GVN: Do not flatten derefs with ProjectionElem::Index. r? `@saethlin` This should fix the bug you found with https://github.com/rust-lang/rust/pull/131650
2025-08-07Do not flatten derefs with ProjectionElem::Index.Camille Gillot-4/+2
2025-08-07Add test.Camille Gillot-0/+142
2025-08-07Rollup merge of #143764 - dianne:primary-binding-drop-order, ↵Stuart Cook-32/+32
r=Nadrieril,traviscross lower pattern bindings in the order they're written and base drop order on primary bindings' order To fix rust-lang/rust#142163, this PR does two things: - Makes match arms base their drop order on the first sub-branch instead of the last sub-branch. Together with the second change, this makes bindings' drop order correspond to the relative order of when each binding first appears (i.e. the order of the "primary" bindings). - Lowers pattern bindings in the order they're written (still treating the right-hand side of a ``@`` as coming before the binding on the left). In each sub-branch of a match arm, this is the order that would be obtained if the or-alternatives chosen in that sub-branch were inlined into the arm's pattern. This both affects drop order (making bindings in or-patterns not be dropped first) and fixes the issue in [this test](https://github.com/rust-lang/rust/blob/2a023bf80a6fbd6a06d5460a34eb247b986286ed/tests/ui/pattern/bindings-after-at/bind-by-copy-or-pat.rs) from rust-lang/rust#121716. My approach to the second point is admittedly a bit trickier than may be necessary. To avoid passing around a counter when building `FlatPat`s, I've instead added just enough information to recover the original structure of the pattern's bindings from a `MatchTreeSubBranch`'s path through the `Candidate` tree. Some alternatives: - We could use a counter, then sort bindings by their ordinals when making `MatchTreeSubBranch`es. - I'd like to experiment with always merging sub-candidates and removing `test_remaining_match_pairs_after_or`; that would require lowering bindings and guards in a different way. That makes it a bigger change too, though, so I figure it might be simplest to start here. - For a very big change, we could track which or-alternatives succeed at runtime to base drop order on the binding order in the particular alternatives matched. This is a breaking change. It will need a crater run, language team sign-off, and likely updates to the Reference. This will conflict with rust-lang/rust#143376 and probably also rust-lang/rust#143028, so they shouldn't be merged at the same time. r? `@matthewjasper` or `@Nadrieril`
2025-08-07Rollup merge of #143028 - dianne:let-else-storage, r=oli-obk,traviscrossStuart Cook-9/+5
emit `StorageLive` and schedule `StorageDead` for `let`-`else`'s bindings after matching This PR removes special handling of `let`-`else`, so that `StorageLive`s are emitted and `StorageDead`s are scheduled only after pattern-matching has succeeded. This means `StorageDead`s will no longer appear for all of its bindings on the `else` branch (because they're not live yet) and its drops&`StorageDead`s will happen together like they do elsewhere, rather than having all drops first, then all `StorageDead`s. This fixes rust-lang/rust#142056, and is therefore a breaking change. I believe it'll need a crater run and a T-lang nomination/fcp thereafter. Specifically, this makes drop-checking slightly more restrictive for `let`-`else` to match the behavior of other variable binding forms. An alternative approach could be to change the relative order of drops and `StorageDead`s for other binding forms to make drop-checking more permissive, but making that consistent would be a significantly more involved change. r? mir cc `````@dingxiangfei2009````` `````@rustbot````` label +T-lang +needs-crater
2025-08-06base drop order on the first sub-branchdianne-32/+32
2025-08-04Let `RemoveUnneededDrops` also remove `drop_in_place`Scott McMurray-5/+9
2025-08-04Dont print arg span in MIR dump for tail callMichael Goulet-5/+5
2025-08-03Add a mir-opt test for an unneeded drop_in_placeScott McMurray-0/+33
2025-08-04Rollup merge of #144875 - scottmcm:more-mir-tests, r=cjgillotStuart Cook-0/+403
Add some pre-codegen MIR tests for debug mode No functional changes; just some tests. I made these for rust-lang/rust#144483, but that's going in a different direction, so I wanted to propose we just add them to help see the impact of other related changes in the future. r? mir
2025-08-04Rollup merge of #144667 - scottmcm:alignment-is-usize, r=tgross35Stuart Cook-34/+17
`AlignmentEnum` should just be `repr(usize)` now These used to use specific sizes because they were compiled on all widths. But now that the types themselves are `#[cfg]`'d, we can save some conversions by having it always be `repr(usize)`.
2025-08-03Add a debug-mode MIR pre-codegen test for `?`-on-`Option`Scott McMurray-0/+197
2025-08-03Add a mir-opt test for *debug* MIR from `derive(PartialOrd, Ord)`Scott McMurray-0/+206
Because the follow-up commits will affect it, and the goal is to show how.
2025-08-02Rollup merge of #144614 - cjgillot:fortify-unneeded, r=scottmcmSamuel Tardieu-222/+94
Fortify RemoveUnneededDrops test. Test tweak that is useful in preparation for https://github.com/rust-lang/rust/pull/144561
2025-07-31Remove the witness type from coroutine argsMichael Goulet-8/+0
2025-07-31Auto merge of #144723 - Zalathar:rollup-f9e0rfo, r=Zalatharbors-0/+50
Rollup of 3 pull requests Successful merges: - rust-lang/rust#144657 (fix: Only "close the window" when its the last annotated file) - rust-lang/rust#144665 (Re-block SRoA on SIMD types) - rust-lang/rust#144713 (`rustc_middle::ty` cleanups) r? `@ghost` `@rustbot` modify labels: rollup
2025-07-31Rollup merge of #144663 - Zalathar:empty-span, r=petrochenkovStuart Cook-8/+8
coverage: Re-land "Enlarge empty spans during MIR instrumentation" This allows us to assume that coverage spans will only be discarded during codegen in very unusual situations. --- This seemingly-simple change has a rather messy history: - rust-lang/rust#140847 - rust-lang/rust#141650 - rust-lang/rust#144298 - rust-lang/rust#144480 Since then, a number of related changes have landed that should make it reasonable to try again: - rust-lang/rust#144530 - rust-lang/rust#144560 - rust-lang/rust#144616 In particular, we have multiple fixes/mitigations, and a confirmed regression test for the original bug that is not triggered by re-landing the changes in this PR.
2025-07-31Rollup merge of #143672 - beepster4096:box_drop_flags_again, r=oli-obkStuart Cook-0/+225
Fix Box allocator drop elaboration New version of rust-lang/rust#131146. Clearing Box's drop flag after running its destructor can cause it to skip dropping its allocator, so just don't. Its cleared by the drop ladder code afterwards already. Unlike the last PR this also handles other types with destructors properly, in the event that we can have open drops on them in the future (by partial initialization or DerefMove or something). Finally, I also added tests for the interaction with async drop here but I discovered rust-lang/rust#143658, so one of the tests has a `knownbug` annotation. Not sure if it should be in this PR at all though. Fixes rust-lang/rust#131082 r? wesleywiser - prev. reviewer
2025-07-30`AlignmentEnum` should just be `repr(usize)` nowScott McMurray-34/+17
Since it's cfg'd instead of type-aliased
2025-07-29Re-block SRoA on SIMD typesScott McMurray-0/+50
Fixes 144621
2025-07-30coverage: Re-land "Enlarge empty spans during MIR instrumentation"Zalathar-8/+8
This allows us to assume that coverage spans will only be discarded during codegen in very unusual situations.
2025-07-28Simplify `align_of_val::<[T]>(…)` → `align_of::<T>()`Scott McMurray-48/+37
2025-07-28Add a MIR test for `align_of_val` on a sliceScott McMurray-0/+33
2025-07-28Add a mir-opt pre-codegen test for dropping a `Box<[impl Copy]>`Scott McMurray-0/+463
2025-07-29Fortify RemoveUnneededDrops test.Camille GILLOT-222/+94
2025-07-27Allow more MIR SROAScott McMurray-40/+32
2025-07-26Rollup merge of #144480 - Zalathar:revert-empty-span, r=ZalatharJacob Pratt-8/+8
Revert "coverage: Enlarge empty spans during MIR instrumentation, not codegen" Surprisingly, rust-lang/rust#144298 alone (extracted from rust-lang/rust#140847) was enough to re-trigger the failures observed in https://github.com/rust-lang/rust/issues/141577#issuecomment-3120667286. --- This reverts commit f877aa7d14916f71a2f88c6d4c009e7ded7684c4. --- r? ghost
2025-07-26Rollup merge of #144331 - ↵Matthias Krüger-10/+26
jplatte:matches-allow-non_exhaustive_omitted_patterns, r=Nadrieril Disable non_exhaustive_omitted_patterns within matches! macro Closes rust-lang/rust#117304. I believe I can skip all of the bootstrap stuff mentioned in https://github.com/rust-lang/rust/issues/117304#issuecomment-1784414453 due to https://blog.rust-lang.org/inside-rust/2025/05/29/redesigning-the-initial-bootstrap-sequence/, right? cc `@Jules-Bertholet`
2025-07-26Revert "coverage: Enlarge empty spans during MIR instrumentation, not codegen"Zalathar-8/+8
This reverts commit f877aa7d14916f71a2f88c6d4c009e7ded7684c4.
2025-07-25add //@ needs-unwind to testbeepster4096-0/+1
2025-07-25Update mir-opt expected output for matches! macroJonas Platte-10/+26
2025-07-25fix box destructor generationbeepster4096-0/+224
2025-07-24Auto merge of #144389 - scottmcm:no-more-mir-cast-assume, r=davidtwcobors-33/+7
MIR-build: No longer emit assumes in enum-as casting This just uses the `valid_range` from the backend, so it's duplicating the range metadata that now we include on parameters and loads, and thus no longer seems to be useful -- notably there's no codegen test failures from removing it. (Because it's using data from the same source as the backend annotations, it doesn't do anything to mitigate things like rust-lang/rust#144388 where the range in the layout is more permissive than the actual possible discriminants. A variant of this that actually checked the discriminants more specifically might be useful, so could potentially be added in future, but I don't think the *current* checks are actually providing value.) r? mir Randomly turns out that this Fixes https://github.com/rust-lang/rust/issues/121097
2025-07-24MIR-build: No longer emit assumes in enum-as castingScott McMurray-33/+7
This just uses the `valid_range` from the backend, so it's duplicating the range metadata that now we include on parameters and loads.