summary refs log tree commit diff
path: root/tests/mir-opt/pre-codegen
AgeCommit message (Collapse)AuthorLines
2024-08-18Bless *all* the mir-opt testsScott McMurray-379/+379
2024-08-18Update mir-opt filechecksScott McMurray-10/+10
2024-08-09Polymorphize RawVecBen Kimock-64/+124
2024-07-31Do not normalize constants eagerly.Camille GILLOT-28/+16
2024-07-29Perform instsimplify before inline to eliminate some trivial callsDianQK-50/+80
2024-07-12Rollup merge of #126502 - cuviper:dump-mir-exclude-alloc-bytes, r=estebankJubilee-17/+9
Ignore allocation bytes in some mir-opt tests This adds `rustc -Zdump-mir-exclude-alloc-bytes` to skip writing allocation bytes in MIR dumps, and applies it to tests that were failing on s390x due to its big-endian byte order. Fixes #126261
2024-07-01Avoid MIR bloat in inliningScott McMurray-795/+63
In 126578 we ended up with more binary size increases than expected. This change attempts to avoid inlining large things into small things, to avoid that kind of increase, in cases when top-down inlining will still be able to do that inlining later.
2024-06-26Bless mir-opt for excluded alloc bytesJosh Stone-16/+8
2024-06-26Use `-Zdump-mir-exclude-alloc-bytes` in some mir-opt testsJosh Stone-1/+1
2024-06-26Auto merge of #126844 - scottmcm:more-ptr-cast-gvn, r=saethlinbors-63/+954
Remove more `PtrToPtr` casts in GVN This addresses two things I noticed in MIR: 1. `NonNull::<T>::eq` does `(a as *mut T) == (b as *mut T)`, but it could just compare the `*const T`s, so this removes `PtrToPtr` casts that are on both sides of a pointer comparison, so long as they're not fat-to-thin casts. 2. `NonNull::<T>::addr` does `transmute::<_, usize>(p as *const ())`, but so long as `T: Thin` that cast doesn't do anything, and thus we can directly transmute the `*const T` instead. r? mir-opt
2024-06-23Also get `add nuw` from `uN::checked_add`Scott McMurray-30/+20
2024-06-23Make MIR inlining costs in build-std independent of config.tomlScott McMurray-63/+796
2024-06-22GVN away PtrToPtr-then-Transmute when possibleScott McMurray-22/+14
2024-06-22GVN away PtrToPtr before comparisonsScott McMurray-52/+36
Notably this happens in `NonNull::eq` :/
2024-06-22Add a mir test for `slice::Iter::is_empty`Scott McMurray-0/+182
2024-06-20Replace `NormalizeArrayLen` with `GVN`Scott McMurray-11/+11
GVN is actually on in release, and covers all the same things (or more), with `LowerSliceLen` changed to produce `PtrMetadata`.
2024-06-20More GVN for PtrMetadataScott McMurray-44/+36
`PtrMetadata` doesn't care about `*const`/`*mut`/`&`/`&mut`, so GVN away those casts in its argument. This includes updating MIR to allow calling PtrMetadata on references too, not just raw pointers. That means that `[T]::len` can be just `_0 = PtrMetadata(_1)`, for example. # Conflicts: # tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir # tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir
2024-06-19Give inlining bonuses to things that optimize outScott McMurray-43/+283
2024-06-19Ban `ArrayToPointer` and `MutToConstPointer` from runtime MIRScott McMurray-8/+8
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-15Redo SliceIndex implementationsScott McMurray-19/+285
2024-06-14Add ub-checks to slice_index MIR-opt testScott McMurray-1/+1
2024-06-10Add `SingleUseConsts` mir-opt passScott McMurray-334/+302
2024-06-06Enable GVN for `AggregateKind::RawPtr` & `UnOp::PtrMetadata`Scott McMurray-14/+10
2024-06-03rustfmt `tests/mir-opt`.Nicholas Nethercote-11/+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-05-31Revert "Auto merge of #115105 - cjgillot:dest-prop-default, r=oli-obk"Camille GILLOT-329/+383
This reverts commit cfb730450f847bb622243eaaab15e77e58d91767, reversing changes made to 91c0823ee63e793d990bb9fed898dc95b5d6db51.
2024-05-30Auto merge of #115105 - cjgillot:dest-prop-default, r=oli-obkbors-383/+329
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-383/+329
2024-05-29[ACP 362] genericize `ptr::from_raw_parts`Scott McMurray-4/+12
2024-05-28Add an intrinsic for `ptr::metadata`Scott McMurray-14/+6
2024-05-23Add assert_unsafe_precondition to unchecked_{add,sub,neg,mul,shl,shr} methodsltdk-136/+36
2024-05-17Remove `Rvalue::CheckedBinaryOp`Scott McMurray-8/+8
2024-05-06Avoid a cast in `ptr::slice_from_raw_parts(_mut)`Scott McMurray-66/+82
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-03Auto merge of #123602 - cjgillot:gvn-borrowed, r=oli-obkbors-137/+74
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-21Update tests after 123949Scott McMurray-82/+0
2024-04-21InstSimplify `from_raw_parts(p, ())` → `p as _`Scott McMurray-40/+4
2024-04-21Use it in the library, and `InstSimplify` it away in the easy placesScott McMurray-18/+234
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-20Merge borrowed locals too.Camille GILLOT-105/+73
2024-04-20GVN borrowed locals too.Camille GILLOT-66/+35
2024-04-18Make `checked` ops emit *unchecked* LLVM operations where feasibleScott McMurray-81/+27
For things with easily pre-checked overflow conditions -- shifts and unsigned subtraction -- write then checked methods in such a way that we stop emitting wrapping versions of them. For example, today <https://rust.godbolt.org/z/qM9YK8Txb> neither ```rust a.checked_sub(b).unwrap() ``` nor ```rust a.checked_sub(b).unwrap_unchecked() ``` actually optimizes to `sub nuw`. After this PR they do.
2024-04-18Ensure `[rust] debuginfo-level-std` doesn't change core's MIRScott McMurray-156/+14
2024-04-18Update `checked_ops` so 32- and 64-bit gets the same checksScott McMurray-19/+174
2024-04-18At debuginfo=0, don't inline debuginfo when inliningScott McMurray-936/+679
2024-04-03Remove MIR unsafe checkMatthew Jasper-234/+138
This also remove safety information from MIR.
2024-04-02Auto merge of #118310 - scottmcm:three-way-compare, r=davidtwcobors-0/+87
Add `Ord::cmp` for primitives as a `BinOp` in MIR Update: most of this OP was written months ago. See https://github.com/rust-lang/rust/pull/118310#issuecomment-2016940014 below for where we got to recently that made it ready for review. --- There are dozens of reasonable ways to implement `Ord::cmp` for integers using comparison, bit-ops, and branches. Those differences are irrelevant at the rust level, however, so we can make things better by adding `BinOp::Cmp` at the MIR level: 1. Exactly how to implement it is left up to the backends, so LLVM can use whatever pattern its optimizer best recognizes and cranelift can use whichever pattern codegens the fastest. 2. By not inlining those details for every use of `cmp`, we drastically reduce the amount of MIR generated for `derive`d `PartialOrd`, while also making it more amenable to MIR-level optimizations. Having extremely careful `if` ordering to μoptimize resource usage on broadwell (#63767) is great, but it really feels to me like libcore is the wrong place to put that logic. Similarly, using subtraction [tricks](https://graphics.stanford.edu/~seander/bithacks.html#CopyIntegerSign) (#105840) is arguably even nicer, but depends on the optimizer understanding it (https://github.com/llvm/llvm-project/issues/73417) to be practical. Or maybe [bitor is better than add](https://discourse.llvm.org/t/representing-in-ir/67369/2?u=scottmcm)? But maybe only on a future version that [has `or disjoint` support](https://discourse.llvm.org/t/rfc-add-or-disjoint-flag/75036?u=scottmcm)? And just because one of those forms happens to be good for LLVM, there's no guarantee that it'd be the same form that GCC or Cranelift would rather see -- especially given their very different optimizers. Not to mention that if LLVM gets a spaceship intrinsic -- [which it should](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Suboptimal.20inlining.20in.20std.20function.20.60binary_search.60/near/404250586) -- we'll need at least a rustc intrinsic to be able to call it. As for simplifying it in Rust, we now regularly inline `{integer}::partial_cmp`, but it's quite a large amount of IR. The best way to see that is with https://github.com/rust-lang/rust/commit/8811efa88b25b5e41d63850e6047e8257c677858#diff-d134c32d028fbe2bf835fef2df9aca9d13332dd82284ff21ee7ebf717bfa4765R113 -- I added a new pre-codegen MIR test for a simple 3-tuple struct, and this PR change it from 36 locals and 26 basic blocks down to 24 locals and 8 basic blocks. Even better, as soon as the construct-`Some`-then-match-it-in-same-BB noise is cleaned up, this'll expose the `Cmp == 0` branches clearly in MIR, so that an InstCombine (#105808) can simplify that to just a `BinOp::Eq` and thus fix some of our generated code perf issues. (Tracking that through today's `if a < b { Less } else if a == b { Equal } else { Greater }` would be *much* harder.) --- r? `@ghost` But first I should check that perf is ok with this ~~...and my true nemesis, tidy.~~
2024-03-27Eliminate `UbCheck` for non-standard librariesDianQK-10/+1
2024-03-24Slightly simplify the `iN::partial_cmp` MIRScott McMurray-13/+5
This saves some debug and scope metadata in every single function that calls it. Normally wouldn't be worth it, but with the derives there's *so* many of these.
2024-03-23Add+Use `mir::BinOp::Cmp`Scott McMurray-105/+32