Commit Graph

845 Commits

Author SHA1 Message Date
bors 0ffbddd09e Auto merge of #127087 - cjgillot:small-map, r=oli-obk
Only track mentioned places for jump threading

This PR aims to reduce the state space size in jump threading and dataflow const-prop opts.

The current implementation walks the types of all locals, and creates a place for each possible projection. This can easily lead to a large number of places and tracked values, most being useless to the actual pass.

With this PR, we instead collect places that appear syntactically in the MIR (first commit). However, this is not sufficient (second commit), and we miss places that we could track in aggregate assignments. The third commit tracks such assignments to mirror place projections, see the inline comment.

This is complementary to https://github.com/rust-lang/rust/pull/127036

r? `@oli-obk`
2024-07-14 08:01:21 +00:00
Jubilee 4c493db0d9
Rollup merge of #122300 - CastilloDel:master, r=cjgillot
Add FileCheck annotations to mir-opt/dest-prop tests

Part of https://github.com/rust-lang/rust/issues/116971, adds FileCheck annotations to MIR-opt tests in tests/mir-opt/dest-prop.

I would like some feedback. Also, I don't know how to approach `union.rs`.  I couldn't figure out what it is testing.

r? cjgillot
2024-07-13 20:19:45 -07:00
Camille GILLOT 7ac7f135e3 Propagate places through assignments. 2024-07-13 12:02:10 +00:00
Camille GILLOT af876626b0 Add test for copying aggregates. 2024-07-13 11:54:30 +00:00
Camille GILLOT 76f5bc6a9f Create mapped places upon seeing them in the body. 2024-07-13 11:54:25 +00:00
Jubilee 5d56572f06
Rollup merge of #126502 - cuviper:dump-mir-exclude-alloc-bytes, r=estebank
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-12 13:47:05 -07:00
Nadrieril 3e030b38ef Return the `otherwise_block` instead of passing it as argument
This saves a few blocks and matches the common `unpack!` paradigm.
2024-07-09 22:47:35 +02:00
Nadrieril 8a222ffd6b Don't try to save an extra block
This is preparation for the next commit.
2024-07-09 22:47:35 +02:00
bors 9dcaa7f92c Auto merge of #127028 - Nadrieril:fix-or-pat-expansion, r=matthewjasper
Fix regression in the MIR lowering of or-patterns

In https://github.com/rust-lang/rust/pull/126553 I made a silly indexing mistake and regressed the MIR lowering of or-patterns. This fixes it.

r? `@compiler-errors` because I'd like this to be merged quickly 🙏
2024-07-09 16:33:59 +00:00
DrMeepster 4187cdc013 Properly handle drops for tail calls 2024-07-07 17:11:05 +02:00
Matthias Krüger 3cf567e3c0
Rollup merge of #127136 - compiler-errors:coroutine-closure-env-shim, r=oli-obk
Fix `FnMut::call_mut`/`Fn::call` shim for async closures that capture references

I adjusted async closures to be able to implement `Fn` and `FnMut` *even if* they capture references, as long as those references did not need to borrow data from the closure captures themselves. See #125259.

However, when I did this, I didn't actually relax an assertion in the `build_construct_coroutine_by_move_shim` shim code, which builds the `Fn`/`FnMut`/`FnOnce` implementations for async closures. Therefore, if we actually tried to *call* `FnMut`/`Fn` on async closures, it would ICE.

This PR adjusts this assertion to ensure that we only capture immutable references in closures if they implement `Fn`/`FnMut`. It also adds a bunch of tests and makes more of the async-closure tests into `build-pass` since we often care about these tests actually generating the right closure shims and stuff. I think it might be excessive to *always* use build-pass here, but 🤷 it's not that big of a deal.

Fixes #127019
Fixes #127012

r? oli-obk
2024-07-02 17:47:46 +02:00
Scott McMurray 23c8ed14c9 Avoid MIR bloat in inlining
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-07-01 05:17:13 -07:00
Matthias Krüger 6938b4b640
Rollup merge of #127105 - scottmcm:issue-127089, r=cjgillot
Only update `Eq` operands in GVN if it can update both sides

Otherwise the types might not match

Fixes #127089

r? mir-opt
2024-07-01 08:53:06 +02:00
Scott McMurray f6942112eb Add a GVN test for 127089 that doesn't optimize to a constant 2024-06-30 11:30:54 -07:00
Michael Goulet 90143b0be8 Fix FnMut/Fn shim for coroutine-closures that capture references 2024-06-29 17:38:02 -04:00
Matthias Krüger 806c5c1971
Rollup merge of #126835 - Nadrieril:reify-decision-tree, r=matthewjasper
Simplifications in match lowering

A series of small simplifications and deduplications in the MIR lowering of patterns.

r? ````@matthewjasper````
2024-06-29 09:14:56 +02:00
Scott McMurray c9f36f8cd7 Only update `Eq` operands in GVN if you can update both sides
Otherwise the types might not match

Fixes 127089
2024-06-28 19:05:01 -07:00
Nadrieril 834f043a08 Fix expansion of or-patterns 2024-06-27 11:26:34 +02:00
Nadrieril 5df6f72057 Add test 2024-06-27 11:26:34 +02:00
Josh Stone 7c3673ff6f Bless mir-opt for excluded alloc bytes 2024-06-26 15:30:47 -07:00
Josh Stone 1a05cb2d93 Use `-Zdump-mir-exclude-alloc-bytes` in some mir-opt tests 2024-06-26 15:05:01 -07:00
CastilloDel 2d5a4832f3 Acknowledge comments 2024-06-26 19:39:37 +02:00
bors d7c59370ce Auto merge of #126844 - scottmcm:more-ptr-cast-gvn, r=saethlin
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-26 14:22:31 +00:00
Scott McMurray ec9e35618d Also get `add nuw` from `uN::checked_add` 2024-06-23 13:29:06 -07:00
Scott McMurray dd545e148c Make MIR inlining costs in build-std independent of config.toml 2024-06-23 01:48:41 -07:00
Scott McMurray 9088cd95a3 GVN away PtrToPtr-then-Transmute when possible 2024-06-22 20:34:09 -07:00
Scott McMurray dd1e19e7c2 GVN away PtrToPtr before comparisons
Notably this happens in `NonNull::eq` :/
2024-06-22 20:27:08 -07:00
Scott McMurray a76e1d9b09 Add a `pointee_metadata_ty_or_projection` helper 2024-06-22 20:27:08 -07:00
Scott McMurray 9140c9ad5b Add a mir test for `slice::Iter::is_empty` 2024-06-22 20:27:07 -07:00
Nadrieril 7b150a161e Don't use fake wildcards when we can get the failure block directly
This commit too was obtained by repeatedly inlining and simplifying.
2024-06-22 19:05:48 +02:00
Scott McMurray 55d13379ac [GVN] Add tests for generic pointees with PtrMetadata 2024-06-20 22:16:59 -07:00
Scott McMurray b611b6bbb8 Replace `NormalizeArrayLen` with `GVN`
GVN is actually on in release, and covers all the same things (or more), with `LowerSliceLen` changed to produce `PtrMetadata`.
2024-06-20 22:16:59 -07:00
Scott McMurray 4a7b6c0e6c More GVN for PtrMetadata
`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-20 22:16:59 -07:00
bors 7a08f84627 Auto merge of #126578 - scottmcm:inlining-bonuses-too, r=davidtwco
Account for things that optimize out in inlining costs

This updates the MIR inlining `CostChecker` to have both bonuses and penalties, rather than just penalties.

That lets us add bonuses for some things where we want to encourage inlining without risking wrapping into a gigantic cost.  For example, `switchInt(const …)` we give an inlining bonus because codegen will actually eliminate the branch (and associated dead blocks) once it's monomorphized, so measuring both sides of the branch gives an unrealistically-high cost to it.  Similarly, an `unreachable` terminator gets a small bonus, because whatever branch leads there doesn't actually exist post-codegen.
2024-06-21 02:06:27 +00:00
Matthias Krüger ef2e8bfcbf
Rollup merge of #126717 - nnethercote:rustfmt-use-pre-cleanups, r=jieyouxu
Clean up some comments near `use` declarations

#125443 will reformat all `use` declarations in the repository. There are a few edge cases involving comments on `use` declarations that require care. This PR cleans up some clumsy comment cases, taking us a step closer to #125443 being able to merge.

r? ``@lqd``
2024-06-20 14:07:04 +02:00
Scott McMurray 4236da52af Give inlining bonuses to things that optimize out 2024-06-19 21:35:37 -07:00
Nicholas Nethercote b5a5647ee0 Move an `EMIT_MIR` comment.
This belongs on a function, not a `use` declaration.
2024-06-20 09:23:20 +10:00
Scott McMurray 4630d1b23b Ban `ArrayToPointer` and `MutToConstPointer` from runtime MIR
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-19 10:44:01 -07:00
Nadrieril 7b764be9f1 Expand or-candidates mixed with candidates above
We can't mix them with candidates below them, but we can mix them with
candidates above.
2024-06-16 18:39:50 +02:00
Nadrieril 6b84d7566e Add tests 2024-06-16 18:23:48 +02:00
Scott McMurray 33c4817d98 Redo SliceIndex implementations 2024-06-15 17:39:25 -07:00
Scott McMurray 17a9d3498b Add ub-checks to slice_index MIR-opt test 2024-06-14 23:18:19 -07:00
Guillaume Gomez 7a4f55bea2
Rollup merge of #126294 - Zalathar:spans-refiner, r=oli-obk
coverage: Replace the old span refiner with a single function

As more and more of the span refiner's functionality has been pulled out into separate early passes, it has finally reached the point where we can remove the rest of the old `SpansRefiner` code, and replace it with a single modestly-sized function.

~~There should be no change to the resulting coverage mappings, as demonstrated by the lack of changes to test output.~~

There is *almost* no change to the resulting coverage mappings. There are some minor changes to `loop` that on inspection appear to be neutral in terms of accuracy, with the old behaviour being a slightly-horrifying implementation detail of the old code, so I think they're acceptable.

Previous work in this direction includes:
- #125921
- #121019
- #119208
2024-06-12 15:45:00 +02:00
Zalathar 2fa78f3a2a coverage: Replace the old span refiner with a single function
As more and more of the span refiner's functionality has been pulled out into
separate early passes, it has finally reached the point where we can remove the
rest of the old `SpansRefiner` code, and replace it with a single
modestly-sized function.
2024-06-12 22:59:24 +10:00
Michael Goulet 0fc18e3a17 Remove DebugWithInfcx 2024-06-11 22:13:04 -04:00
Scott McMurray 8fbab183d7 Delete `ConstDebugInfo` pass 2024-06-10 00:06:02 -07:00
Scott McMurray a4d0fc39ba Add `SingleUseConsts` mir-opt pass 2024-06-10 00:06:02 -07:00
许杰友 Jieyou Xu (Joe) f000b428bd
Rollup merge of #125041 - scottmcm:gvn-for-from-raw-parts, r=cjgillot
Enable GVN for `AggregateKind::RawPtr`

Looks like I was worried for nothing; this seems like it's much easier than I was originally thinking it would be.
r? `@cjgillot`

This should be useful for `x[..4]`-like things, should those start inlining enough to expose the lengths.
2024-06-09 19:16:19 +01:00
Oli Scherer cbee17d502 Revert "Create const block DefIds in typeck instead of ast lowering"
This reverts commit ddc5f9b6c1.
2024-06-07 08:33:58 +00:00
Scott McMurray 021ccf6c4e Enable GVN for `AggregateKind::RawPtr` & `UnOp::PtrMetadata` 2024-06-06 00:25:58 -07:00