about summary refs log tree commit diff
path: root/tests/mir-opt/pre-codegen
AgeCommit message (Collapse)AuthorLines
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
2024-03-23Add a MIR pre-codegen test for derived PartialOrdScott McMurray-0/+168
2024-03-23Auto merge of #122629 - RalfJung:assert-unsafe-precondition, r=saethlinbors-1/+5
refactor check_{lang,library}_ub: use a single intrinsic This enacts the plan I laid out [here](https://github.com/rust-lang/rust/pull/122282#issuecomment-1996917998): use a single intrinsic, called `ub_checks` (in aniticpation of https://github.com/rust-lang/compiler-team/issues/725), that just exposes the value of `debug_assertions` (consistently implemented in both codegen and the interpreter). Put the language vs library UB logic into the library. This makes it easier to do something like https://github.com/rust-lang/rust/pull/122282 in the future: that just slightly alters the semantics of `ub_checks` (making it more approximating when crates built with different flags are mixed), but it no longer affects whether these checks can happen in Miri or compile-time. The first commit just moves things around; I don't think these macros and functions belong into `intrinsics.rs` as they are not intrinsics. r? `@saethlin`
2024-03-23refactor check_{lang,library}_ub: use a single intrinsic, put policy into ↵Ralf Jung-1/+5
library
2024-03-22Enable more mir-opt tests in debug buildsBen Kimock-4/+1
2024-03-18Remove some only- clauses from mir-opt testsBen Kimock-11/+2
2024-03-10MIR printing: print the path of uneval'd const; refer to promoteds in a ↵Ralf Jung-11/+11
consistent way
2024-03-08Distinguish between library and lang UB in assert_unsafe_preconditionBen Kimock-1/+1
2024-03-08Update MIR with `MirPatch` in `UninhabitedEnumBranching`DianQK-46/+46
2024-02-29Bless testr0cky-12/+12
2024-02-23Ignore less tests in debug buildsBen Kimock-3/+2
2024-02-22[AUTO_GENERATED] Migrate compiletest to use `ui_test`-style `//@` directives许杰友 Jieyou Xu (Joe)-31/+31
2024-02-21rename ptr::invalid -> ptr::without_provenanceRalf Jung-6/+6
also introduce ptr::dangling matching NonNull::dangling
2024-02-19Convert debug_assert_nounwind to intrinsics::debug_assertionsBen Kimock-340/+24
2024-02-11Auto merge of #120405 - cjgillot:gvn-pointer, r=oli-obkbors-494/+462
Fold pointer operations in GVN This PR proposes 2 combinations of cast operations in MIR GVN: - a chain of `PtrToPtr` or `MutToConstPointer` casts can be folded together into a single `PtrToPtr` cast; - we attempt to evaluate more ptr ops when there is no provenance. In particular, this allows to read from static slices. This is not yet sufficient to see through slice operations that use `PtrComponents` (because that's a union), but still a step forward. r? `@ghost`
2024-02-09Remove ConstGoto and SeparateConstSwitch.Camille GILLOT-0/+49
2024-02-09Enable by default.Camille GILLOT-374/+201
2024-02-09Fold consecutive PtrToPtr casts.Camille GILLOT-494/+462
2024-02-08Bless/fix testsBen Kimock-790/+783
2024-01-29raw pointer metadata API: data address -> data pointerRalf Jung-4/+4
2024-01-16Auto merge of #119954 - scottmcm:option-unwrap-failed, r=WaffleLapkinbors-4/+4
Split out `option::unwrap_failed` like we have `result::unwrap_failed` ...and like `option::expect_failed`
2024-01-16Auto merge of #119672 - cjgillot:dse-sandwich, r=oli-obkbors-105/+210
Sandwich MIR optimizations between DSE. This PR reorders MIR optimization passes in an attempt to increase their efficiency. - Stop running CopyProp before GVN, it's useless as GVN will do the same thing anyway. Instead, we perform CopyProp at the end of the pipeline, to ensure we do not emit copy/move chains. - Run DSE before GVN, as it increases the probability to have single-assignment locals. - Run DSE after the final CopyProp to turn copies into moves. r? `@ghost`
2024-01-16Auto merge of #119439 - cjgillot:gvn-faster, r=oli-obkbors-0/+20
Avoid some redundant work in GVN The first 2 commits are about reducing the perf effect. Third commit avoids doing redundant work: is a local is SSA, it already has been simplified, and the resulting value is in `self.locals`. No need to call any code on it. The last commit avoids removing some storage statements. r? wg-mir-opt
2024-01-14Split out `option::unwrap_failed` like we have `result::unwrap_failed`Scott McMurray-4/+4
...and like `option::expect_failed`