Commit Graph

243 Commits

Author SHA1 Message Date
dianqk 9c029d2102 GVN: Do not unify dereferences if they are references 2026-02-04 21:55:57 +08:00
dianqk bc2bf6b544 GVN: Do not introduce new dereferences if they borrow from non-SSA locals 2026-02-04 21:55:54 +08:00
Scott McMurray 9288c208a2 Adjust Alignment to emphasize that we don't look at its field 2026-01-25 17:24:45 -08:00
Scott McMurray 929e280973 Update ptr::Alignment to go through transmuting 2026-01-25 17:19:28 -08:00
Pavel Grigorenko bc0cce1595 ptr_aligment_type: add more APIs 2026-01-20 17:15:50 +03:00
Zalathar 2df2c72d7a Ignore #[doc(hidden)] items when computing trimmed paths 2026-01-19 12:27:27 +11:00
Scott McMurray 5932078c79 Stop emitting UbChecks on every Vec→Slice
Spotted this in PR148766's test changes.  It doesn't seem like this ubcheck would catch anything useful; let's see if skipping it helps perf.
2026-01-08 17:14:02 -08:00
Deadbeef a913065d80 fix rustfmt and bless tidy/tests 2026-01-01 19:17:11 -05:00
Deadbeef 47864e80cb address review comments; fix CI 2026-01-01 19:17:11 -05:00
Waffle Lapkin 6b4f4f57e7 bless a mir-opt and a miri tests 2025-12-26 22:02:19 +01:00
Camille GILLOT f59dfc1a4a Maintain a graph of fulfilled conditions. 2025-11-16 01:38:16 +00:00
Scott McMurray e5803fceed Move into_try_type to a free function 2025-11-13 19:53:02 -08:00
Scott McMurray 86c3ba754a Implement the alternative try desugaring 2025-11-09 04:09:10 -08:00
Camille Gillot 5dfbf67f94 Replace NullOp::SizeOf and NullOp::AlignOf by lang items. 2025-10-23 00:38:28 +00:00
dianqk afff0502a6 GVN: Preserve derefs at terminators that cannot write to memory 2025-10-16 23:03:05 +08:00
dianqk a673575b24 mir-opt: Simplify trivial constants in SimplifyConstCondition 2025-10-16 21:30:06 +08:00
bors 3be68033b6 Auto merge of #145513 - beepster4096:erasedereftemps, r=saethlin,cjgillot
Validate CopyForDeref and DerefTemps better and remove them from runtime MIR

(split from my WIP rust-lang/rust#145344)

This PR:
- Removes `Rvalue::CopyForDeref` and `LocalInfo::DerefTemp` from runtime MIR
    - Using a new mir pass `EraseDerefTemps`
    - `CopyForDeref(x)` is turned into `Use(Copy(x))`
    - `DerefTemp` is turned into `Boring`
        - Not sure if this part is actually necessary, it made more sense in rust-lang/rust#145344 with `DerefTemp` storing actual data that I wanted to keep from having to be kept in sync with the rest of the body in runtime MIR
- Checks in validation that `CopyForDeref` and `DerefTemp` are only used together
- Removes special handling for `CopyForDeref` from many places
- Removes `CopyForDeref` from `custom_mir` reverting rust-lang/rust#111587
    - In runtime MIR simple copies can be used instead
    - In post cleanup analysis MIR it was already wrong to use due to the lack of support for creating `DerefTemp` locals
    - Possibly this should be its own PR?
 - Adds an argument to `deref_finder` to avoid creating new `DerefTemp`s and `CopyForDeref` in runtime MIR.
     - Ideally we would just avoid making intermediate derefs instead of fixing it at the end of a pass / during shim building
 - Removes some usages of `deref_finder` that I found out don't actually do anything

r? oli-obk
2025-10-12 02:34:20 +00:00
beepster4096 33cc7787bf trivial test blessings 2025-10-10 18:40:00 -07:00
dianqk 486fae11ca Rollup merge of #145651 - borsakv:139093, r=cjgillot
Regression test for const promotion with Option<Ordering>

https://rust.godbolt.org/z/EjxqE8WcT

Fixes rust-lang/rust#139093

Add a regression test to ensure that comparing `Option<Ordering>` to
`Some(Ordering::Equal)` does not trigger unnecessary const promotion
in MIR.

Previously, inlined constants like `Some(Ordering::Equal)` would get
promoted, leading to more complex MIR and redundant LLVM IR checks.
This test verifies that both the direct form and the `let`-binding form
now generate equivalent, simplified MIR.

r? cjgillot
2025-10-11 07:05:53 +08:00
Vitali Borsak c86474ca07 Adding a regression test (const promotion with Option<Ordering>) 2025-10-10 12:23:45 +00:00
dianqk 8da04285cf mir-opt: Eliminate dead statements even if they are used by debuginfos 2025-10-02 14:58:59 +08:00
dianqk 85b2f70693 mir-opt: Eliminate trivial unnecessary storage annotations 2025-10-02 14:55:51 +08:00
dianqk 571412f819 mir-opt: Eliminate dead ref statements 2025-10-02 14:55:50 +08:00
Camille GILLOT 44c1a00a2f Enable DestinationPropagation by default. 2025-09-16 22:08:02 +00:00
Camille Gillot 99f6bcf380 Unify a source with all possible destinations. 2025-09-07 16:45:00 +00:00
Jacob Pratt bc4a6431eb Rollup merge of #142185 - saethlin:refprop-moves, r=cjgillot
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-22 22:00:46 -04:00
Karl Meakin 377a0c88a9 Consolidate panicking functions in slice/index.rs
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-21 11:07:25 +01:00
Ben Kimock 9aa8cfaf2f Convert moves of references to copies in RefProp 2025-08-11 23:10:56 -04:00
Stuart Cook fe644eb01c Rollup merge of #144875 - scottmcm:more-mir-tests, r=cjgillot
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-04 14:58:09 +10:00
Scott McMurray e1a38ec2ab Add a debug-mode MIR pre-codegen test for ?-on-Option 2025-08-03 17:30:40 -07:00
Scott McMurray c441640f0e Add a mir-opt test for *debug* MIR from derive(PartialOrd, Ord)
Because the follow-up commits will affect it, and the goal is to show how.
2025-08-03 17:30:40 -07:00
Scott McMurray 4220587c22 AlignmentEnum should just be repr(usize) now
Since it's cfg'd instead of type-aliased
2025-07-30 00:09:01 -07:00
Scott McMurray 8ef9233339 Simplify align_of_val::<[T]>(…)align_of::<T>() 2025-07-28 23:19:06 -07:00
Scott McMurray 950a3b34ea Add a mir-opt pre-codegen test for dropping a Box<[impl Copy]> 2025-07-28 23:15:58 -07:00
Matthias Krüger c9541a2bf8 Rollup merge of #144331 - 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-26 15:27:58 +02:00
Jonas Platte 25ed28823a Update mir-opt expected output for matches! macro 2025-07-25 22:34:55 +02:00
Camille GILLOT 9ff071219b Give an AllocId to ConstValue::Slice. 2025-07-23 23:54:37 +00:00
Matthias Krüger b252014673 Rollup merge of #143271 - cjgillot:gvn-types, r=oli-obk
Store the type of each GVN value

MIR is fully typed, so type information is an integral part of what defines a value. GVN currently tries to circumvent storing types, which creates all sorts of complexities.

This PR stores the type along with the enum `Value` when defining a value index. This allows to simplify a lot of code.

Fixes rust-lang/rust#128094
Fixes rust-lang/rust#135128

r? ``````@ghost`````` for perf
2025-07-18 04:27:50 +02:00
fuder.eth 19fccacd4a Update SUMMARY.md
Update README.md
2025-07-14 12:01:41 +03:00
Tomasz Miąsko 9681786409 Propagate from borrowed locals in CopyProp 2025-07-10 09:36:20 +02:00
Camille GILLOT bab9c752e8 Do not unify borrowed locals in CopyProp. 2025-07-06 10:14:07 +00:00
Camille GILLOT 4750dff54e Remove extraneous types. 2025-07-01 11:40:44 +00:00
Ralf Jung 62418f4c56 intrinsics: rename min_align_of to align_of 2025-06-12 17:50:25 +02:00
Scott McMurray 4668124cc7 slice.get(i) should use a slice projection in MIR, like slice[i] does 2025-05-30 12:04:41 -07:00
Ben Kimock e36dc78edd Add some track_caller info to precondition panics 2025-05-21 09:10:06 -04:00
dianqk 5881b7c68b mir-opt: execute MatchBranchSimplification after GVN
This can provide more opportunities for MatchBranchSimplification.
2025-04-21 21:46:44 +08:00
Camille GILLOT 109edab245 Allow GVN to produce places and not just locals. 2025-04-04 10:55:36 +00:00
bors 00095b3da4 Auto merge of #132527 - DianQK:gvn-stmt-iter, r=oli-obk
gvn: Invalid dereferences for all non-local mutations

Fixes #132353.

This PR removes the computation value by traversing SSA locals through `for_each_assignment_mut`.

Because the `for_each_assignment_mut` traversal skips statements which have side effects, such as dereference assignments, the computation may be unsound. Instead of `for_each_assignment_mut`, we compute values by traversing in reverse postorder.

Because we compute and use the symbolic representation of values on the fly, I invalidate all old values when encountering a dereference assignment. The current approach does not prevent the optimization of a clone to a copy.

In the future, we may add an alias model, or dominance information for dereference assignments, or SSA form to help GVN.

r? cjgillot

cc `@jieyouxu` #132356
cc `@RalfJung` #133474
2025-04-03 19:17:33 +00:00
dianqk ac7dd7a1b3 Remove unsound-mir-opts for simplify_aggregate_to_copy 2025-04-03 21:59:43 +08:00
Daniel Bloom 20417a9522 Make slice iterator constructors unstably const 2025-04-02 10:39:14 -07:00