summary refs log tree commit diff
path: root/tests/mir-opt/pre-codegen
AgeCommit message (Collapse)AuthorLines
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-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`
2024-01-11Sandwich MIR optimizations between DSE.Camille GILLOT-105/+210
2024-01-11Auto merge of #119677 - cjgillot:early-cfg-opt, r=oli-obkbors-4/+0
Reorder early post-inlining passes. `RemoveZsts`, `RemoveUnneededDrops` and `UninhabitedEnumBranching` only depend on types, so they should be executed together early after MIR inlining introduces those types. This does not change the end-result, but this makes the pipeline a bit more consistent.
2024-01-07Merge dead bb pruning and unreachable bb deduplication.Camille GILLOT-42/+42
2024-01-07Avoid recording no-op replacements.Camille GILLOT-0/+20
2024-01-07Reorder early post-inlining passes.Camille GILLOT-4/+0
2023-12-24Replace legacy ConstProp by GVN.Camille GILLOT-153/+253
2023-12-24Enable GVN by default.Camille GILLOT-353/+266
2023-12-07also print 'immutable' flagRalf Jung-4/+4
2023-11-26Update std::simd usage and test outputsCaleb Zulawski-76/+76
2023-11-26Bless MIR testsGary Guo-128/+120
2023-11-01Rebase fallout.Camille GILLOT-10/+2
2023-11-01Make ui into mir-opt test.Camille GILLOT-0/+453