Commit graph

209 commits

Author SHA1 Message Date
Camille GILLOT d0d4e0237f Iteratively replace pointers. 2023-05-10 19:22:54 +00:00
Camille GILLOT b64e9113e2 Add test. 2023-05-10 17:21:35 +00:00
Camille GILLOT bde213cfe5 Add needs-unwind. 2023-05-09 19:39:46 +00:00
Camille GILLOT 8e5910fdf2 Separate test cases into bbs. 2023-05-09 17:59:35 +00:00
Camille GILLOT 3c43b61b87 Do not consider borrowed Freeze locals as SSA. 2023-05-09 17:59:35 +00:00
Camille GILLOT 3490375570 Implement SSA-based reference propagation. 2023-05-09 17:59:34 +00:00
Dylan DPC dbd090c655
Rollup merge of #110694 - est31:builtin, r=petrochenkov
Implement builtin # syntax and use it for offset_of!(...)

Add `builtin #` syntax to the parser, as well as a generic infrastructure to support both item and expression position builtin syntaxes. The PR also uses this infrastructure for the implementation of the `offset_of!` macro, added by #106934.

cc `@petrochenkov` `@DrMeepster`

cc #110680 `builtin #` tracking issue
cc #106655 `offset_of!` tracking issue
2023-05-09 12:33:45 +05:30
bors dfe31889e1 Auto merge of #111007 - JakobDegen:nrvo, r=tmiasko
Disable nrvo mir opt

See #111005 and #110902 . The ICE can definitely be hit on stable, the miscompilation I'm not sure about. The pass makes some pretty sketchy assumptions though, and we should not have it on while that's the case.

I'm not going to work on actually fixing this, it's probably not excessively difficult though.

r? rust-lang/mir-opt
2023-05-08 18:10:26 +00:00
bors a0111af531 Auto merge of #110824 - cjgillot:const-prop-index, r=JakobDegen,oli-obk
ConstProp into PlaceElem::Index.

Noticed this while looking at keccak output MIR.

This pass aims to replace `ProjectionElem::Index` with `ProjectionElem::ConstantIndex` during ConstProp.

r? `@ghost`
2023-05-08 14:23:13 +00:00
Jakob Degen 8e2da80fc5 Disable nrvo mir opt 2023-05-08 03:55:41 -07:00
bors 04c53444df Auto merge of #111309 - saethlin:InstSimplify, r=scottmcm
Rename InstCombine to InstSimplify

```
╭ ➜ ben@archlinux:~/rust
╰ ➤ rg -i instcombine
src/doc/rustc-dev-guide/src/mir/optimizations.md
134:may have been misapplied. Examples of this are `InstCombine` and `ConstantPropagation`.

src/ci/docker/host-x86_64/disabled/dist-x86_64-haiku/llvm-config.sh
38:                    instcombine instrumentation interpreter ipo irreader lanai \

tests/codegen/slice_as_from_ptr_range.rs
4:// min-llvm-version: 15.0 (because this is a relatively new instcombine)
```

r? `@scottmcm`
2023-05-08 01:28:50 +00:00
Camille GILLOT a8988519d5 Propagate PlaceElem::Index. 2023-05-07 11:10:52 +00:00
Ben Kimock ff855547f4 Rename InstCombine to InstSimplify 2023-05-06 23:22:32 -04:00
Matthias Krüger bccd29611a
Rollup merge of #111077 - cjgillot:const-prop-unit, r=Mark-Simulacrum
Make more ConstProp tests unit.
2023-05-06 23:32:01 +02:00
est31 5eb29c7f49 Migrate offset_of from a macro to builtin # syntax 2023-05-05 21:44:13 +02:00
Dylan DPC de7e29e593
Rollup merge of #110773 - mj10021:issue-109502-fix, r=oli-obk
Reduce MIR dump file count for MIR-opt tests

As referenced in issue #109502 , mir-opt tests previously used the -Zdump-mir=all flag, which generates very large output.  This PR only dumps the passes under test, greatly reducing dump output.
2023-05-05 18:40:34 +05:30
James Dietz c19959f4c3 add passes to miroptfiles struct and passed to -zdump-mir args
blessed new test
2023-05-04 18:56:32 -04:00
Camille GILLOT 1ffe9059c3 Reject borrows of projections in ConstProp. 2023-05-04 21:51:44 +00:00
Camille GILLOT e2caebc4a6 Add tests. 2023-05-04 21:50:46 +00:00
Matthias Krüger 0ac8ebdf11
Rollup merge of #110826 - cjgillot:place-mention-use, r=JakobDegen,lcnr
Make PlaceMention a non-mutating use.

Fixes https://github.com/rust-lang/rust/issues/110781

r? `@JakobDegen`

I don't agree with your statement in https://github.com/rust-lang/rust/issues/110781#issuecomment-1520841434. I suggest that we start fixing `PlaceContext` to be accurate enough for optimizations to use it. This structure is very convenient to use in visitors, and we perhaps have an opportunity to make it less of a footgun.
2023-05-04 19:18:19 +02:00
Camille GILLOT a4ef2f5fca Make ConstProp tests unit. 2023-05-02 16:46:56 +00:00
bors 5133e15459 Auto merge of #109521 - tmiasko:const-prop-validation, r=wesleywiser
Don't validate constants in const propagation

Validation is neither necessary nor desirable.

The constant validation is already omitted at mir-opt-level >= 3, so there there are not changes in MIR test output (the propagation of invalid constants is covered by an existing test in tests/mir-opt/const_prop/invalid_constant.rs).
2023-05-02 03:42:37 +00:00
bors 6db1e5e771 Auto merge of #111010 - scottmcm:mem-replace-simpler, r=WaffleLapkin
Make `mem::replace` simpler in codegen

Since they'd mentioned more intrinsics for simplifying stuff recently,
r? `@WaffleLapkin`

This is a continuation of me looking at foundational stuff that ends up with more instructions than it really needs.  Specifically I noticed this one because `Range::next` isn't MIR-inlining, and one of the largest parts of it is a `replace::<usize>` that's a good dozen instructions instead of the two it could be.

So this means that `ptr::write` with a `Copy` type no longer generates worse IR than manually dereferencing (well, at least in LLVM -- MIR still has bonus pointer casts), and in doing so means that we're finally down to just the two essential `memcpy`s when emitting `mem::replace` for a large type, rather than the bonus-`alloca` and three `memcpy`s we emitted before this ([or the 6 we currently emit in 1.69 stable](https://rust.godbolt.org/z/67W8on6nP)).  That said, LLVM does _usually_ manage to optimize the extra code away.  But it's still nice for it not to have to do as much, thanks to (for example) not going through an `alloca` when `replace`ing a primitive like a `usize`.

(This is a new intrinsic, but one that's immediately lowered to existing MIR constructs, so not anything that MIRI or the codegen backends or MIR semantics needs to do work to handle.)
2023-05-01 14:29:15 +00:00
Scott McMurray 5292d48b85 Codegen fewer instructions in mem::replace 2023-04-30 22:33:04 -07:00
Matthias Krüger 1b262b8b56
Rollup merge of #110823 - compiler-errors:tweak-await-span, r=b-naber
Tweak await span to not contain dot

Fixes a discrepancy between method calls and await expressions where the latter are desugared to have a span that *contains* the dot (i.e. `.await`) but method call identifiers don't contain the dot. This leads to weird suggestions suggestions in borrowck -- see linked issue.

Fixes #110761

This mostly touches a bunch of tests to tighten their `await` span.
2023-05-01 01:09:47 +02:00
Scott McMurray ca3f742ff6 MIR pre-codegen test for mem::replace 2023-04-30 11:59:24 -07:00
Matthias Krüger eae208eef6
Rollup merge of #110732 - cjgillot:unit-const-prop, r=tmiasko
Make ConstProp some tests unit.

Part of the effort to tidy up mir-opt test suite.
2023-04-30 16:25:47 +02:00
Camille GILLOT 9325a254f0 Make PlaceMention a non-mutating use. 2023-04-29 16:14:33 +00:00
Camille GILLOT 77dac91d4f Add test. 2023-04-29 16:14:32 +00:00
Dylan DPC 7721c7319d
Rollup merge of #110962 - cjgillot:no-hash-drops, r=compiler-errors
Make drop_flags an IndexVec.

Fixes https://github.com/rust-lang/rust/issues/91943
2023-04-29 11:27:56 +05:30
Camille GILLOT 7f26191aed Make drop_flags an IndexVec. 2023-04-28 20:12:45 +00:00
Pietro Albini a7bb8c7851 handle cfg(bootstrap) 2023-04-28 08:47:55 -07:00
bors 43a78029b4 Auto merge of #110837 - scottmcm:offset-for-add, r=compiler-errors
Use MIR's `Offset` for pointer `add` too

~~Status: draft while waiting for #110822 to land, since this is built atop that.~~
~~r? `@ghost~~`

Canonical Rust code has mostly moved to `add`/`sub` on pointers, which take `usize`, instead of `offset` which takes `isize`.  (And, relatedly, when `sub_ptr` was added it turned out it replaced every single in-tree use of `offset_from`, because `usize` is just so much more useful than `isize` in Rust.)

Unfortunately, `intrinsics::offset` could only accept `*const` and `isize`, so there's a *huge* amount of type conversions back and forth being done.  They're identity conversions in the backend, but still end up producing quite a lot of unhelpful MIR.

This PR changes `intrinsics::offset` to accept `*const` *and* `*mut` along with `isize` *and* `usize`.  Conveniently, the backends and CTFE already handle this, since MIR's `BinOp::Offset` [already supports all four combinations](adaac6b166/compiler/rustc_const_eval/src/transform/validate.rs (L523-L528)).

To demonstrate the difference, I added some `mir-opt/pre-codegen/` tests around slice indexing.  Here's the difference to `[T]::get_mut`, since it uses `<*mut _>::add` internally:
```diff
`@@` -79,30 +70,21 `@@` fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> {
         StorageLive(_12);                // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL
         StorageLive(_9);                 // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL
         _9 = _8 as *mut u32 (PtrToPtr);  // scope 11 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        StorageLive(_13);                // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        _13 = _2 as isize (IntToInt);    // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        StorageLive(_14);                // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        StorageLive(_15);                // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        _15 = _9 as *const u32 (Pointer(MutToConstPointer)); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        _14 = Offset(move _15, _13);     // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        StorageDead(_15);                // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        _7 = move _14 as *mut u32 (PtrToPtr); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        StorageDead(_14);                // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        StorageDead(_13);                // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
+        _7 = Offset(_9, _2);             // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
         StorageDead(_9);                 // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL
         StorageDead(_12);                // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL
         StorageDead(_11);                // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL
```
1c1c8e442a (diff-a841b6a4538657add3f39bc895744331453d0625e7aace128b1f604f0b63c8fdR80)
2023-04-28 09:26:59 +00:00
Scott McMurray e1da77c76d Also use mir::Offset for pointer add 2023-04-27 22:44:42 -07:00
Matthias Krüger cf911ac757
Rollup merge of #110766 - m-ou-se:fmt-rt, r=jyn514
More core::fmt::rt cleanup.

- Removes the `V1` suffix from the `Argument` and `Flag` types.

- Moves more of the format_args lang items into the `core::fmt::rt` module. (The only remaining lang item in `core::fmt` is `Arguments` itself, which is a public type.)

Part of https://github.com/rust-lang/rust/issues/99012

Follow-up to https://github.com/rust-lang/rust/pull/110616
2023-04-28 07:34:02 +02:00
Michael Goulet 6d6c904431 Make async removal span more resilient to macro expansions 2023-04-27 18:25:07 +00:00
Michael Goulet f0fc4f9acf Tweak await span 2023-04-27 17:18:11 +00:00
Matthias Krüger 563eb04c5d
Rollup merge of #110864 - compiler-errors:into-future-stable, r=jackh726
`IntoFuture::into_future` is no longer unstable

We don't need to gate the `IntoFuture::into_future` call in `.await` lowering anymore.

``@bors`` rollup
2023-04-27 15:10:55 +02:00
Tomasz Miąsko d1bd1be668 Use EMIT_MIR_FOR_EACH_BIT_WIDTH in transmute mir-opt test 2023-04-27 00:00:00 +00:00
Michael Goulet c18e7b765f IntoFuture::into_future is no longer unstable 2023-04-26 22:44:18 +00:00
Tomasz Miąsko 4adb8fbda0 Remove workaround for CastKind::Transmute from const prop
Since constants are no longer validated before propagation the
workaround is obsolete. Remove it.
2023-04-27 00:33:52 +02:00
Scott McMurray 8bcfc0e597 Add some MIR pre-codegen tests for slice indexing 2023-04-26 14:43:36 -07:00
bors 9c044d77a3 Auto merge of #110822 - scottmcm:lower-offset-to-mir, r=compiler-errors
Lower `intrinsics::offset` to `mir::BinOp::Offset`

They're [semantically the same](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/enum.Rvalue.html#variant.BinaryOp), so this means the backends don't need to handle the intrinsic and means fewer MIR basic blocks in pointer arithmetic code.
2023-04-26 15:52:33 +00:00
Scott McMurray 05a665f21a Lower intrinsics::offset to mir::BinOp::Offset
They're semantically the same, so this means the backends don't need to handle the intrinsic and means fewer MIR basic blocks in pointer arithmetic code.
2023-04-25 19:23:45 -07:00
Michael Goulet bb99cdc7cd vars are ? 2023-04-25 19:53:09 +00:00
bors 253b727f46 Auto merge of #110713 - cjgillot:track-mir-opt, r=scottmcm
Add mir-opt tests to track MIR quality.

cc `@scottmcm` `@saethlin`

If you have other ideas, please say so.
2023-04-24 17:01:02 +00:00
Mara Bos 9cc5949f9f Update tests. 2023-04-24 16:16:14 +02:00
Camille GILLOT baa13123ef Make some tests unit. 2023-04-23 17:13:18 +00:00
Camille GILLOT 332b7f51d6 Add mir-opt tests to track MIR quality. 2023-04-23 17:10:53 +00:00
bors 915aa06700 Auto merge of #110705 - saethlin:ignore-locals-cost, r=cjgillot
Remove the size of locals heuristic in MIR inlining

This heuristic doesn't necessarily correlate to complexity of the MIR Body. In particular, a lot of straight-line code in MIR tends to never reuse a local, even though any optimizer would effectively reuse the storage or just put everything in registers. So it doesn't even necessarily make sense that this would be a stack size heuristic.

So... what happens if we just delete the heuristic? The benchmark suite improves significantly. Less heuristics better?

r? `@cjgillot`
2023-04-23 15:41:45 +00:00