Commit Graph

266 Commits

Author SHA1 Message Date
Camille GILLOT
efb468866e Use the correct place for enum variants. 2023-02-18 10:11:53 +00:00
Camille GILLOT
7213eaa1c0 Flood aggregate assignments with Top. 2023-02-18 09:57:13 +00:00
Camille GILLOT
650683756f Add mir-opt test. 2023-02-18 09:37:31 +00:00
Ben Kimock
1409cb59b2 Enable instcombine for mutable reborrows 2023-02-16 07:51:23 -05:00
bors
639377ed73 Auto merge of #107449 - saethlin:enable-copyprop, r=oli-obk
Enable CopyProp

r? `@tmiasko`

`@rustbot` label +A-mir-opt
2023-02-16 03:44:37 +00:00
bors
c5283576ec Auto merge of #108012 - compiler-errors:issue-107999, r=oli-obk
Don't ICE in `might_permit_raw_init` if reference is polymorphic

Emitting optimized MIR for a polymorphic function may require computing layout of a type that isn't (yet) known. This happens in the instcombine pass, for example. Let's fail gracefully in that condition.

cc `@saethlin`
fixes #107999
2023-02-15 20:56:07 +00:00
Dylan DPC
c78e3c735a
Rollup merge of #107411 - cjgillot:dataflow-discriminant, r=oli-obk
Handle discriminant in DataflowConstProp

cc ``@jachris``
r? ``@JakobDegen``

This PR attempts to extend the DataflowConstProp pass to handle propagation of discriminants. We handle this by adding 2 new variants to `TrackElem`: `TrackElem::Variant` for enum variants and `TrackElem::Discriminant` for the enum discriminant pseudo-place.

The difficulty is that the enum discriminant and enum variants may alias each another. This is the issue of the `Option<NonZeroUsize>` test, which is the equivalent of https://github.com/rust-lang/unsafe-code-guidelines/issues/84 with a direct write.

To handle that, we generalize the flood process to flood all the potentially aliasing places. In particular:
- any write to `(PLACE as Variant)`, either direct or through a projection, floods `(PLACE as OtherVariant)` for all other variants and `discriminant(PLACE)`;
- `SetDiscriminant(PLACE)` floods `(PLACE as Variant)` for each variant.

This implies that flooding is not hierarchical any more, and that an assignment to a non-tracked place may need to flood a tracked place. This is handled by `for_each_aliasing_place` which generalizes `preorder_invoke`.

As we deaggregate enums by putting `SetDiscriminant` last, this allows to propagate the value of the discriminant.

This refactor will allow to make https://github.com/rust-lang/rust/pull/107009 able to handle discriminants too.
2023-02-15 12:24:55 +05:30
Michael Goulet
b096f0e0f0 Make permit_uninit/zero_init fallible 2023-02-14 22:37:30 +00:00
Michael Goulet
087a0136d0 Don't ICE in might_permit_raw_init if reference is polymorphic 2023-02-14 01:03:06 +00:00
Matthias Krüger
5915309645
Rollup merge of #107971 - saethlin:mir-opt-ub, r=cjgillot
Clearly document intentional UB in mir-opt tests

All of the changed mir-opt test input files did not pass Miri. Now they do.

r? `@cjgillot` because there's a CopyProp test in here that I do not fully understand
2023-02-13 23:25:13 +01:00
Ben Kimock
614df3fd5e Clearly document intentional UB in mir-opt tests
Co-authored-by: Jakob Degen <jakob.e.degen@gmail.com>
2023-02-13 13:50:50 -05:00
Ben Kimock
d8d18aae03 Fix UB in the test case 2023-02-12 14:42:16 -05:00
Ben Kimock
640ede7b0a Enable CopyProp by default, tune the impl a bit 2023-02-12 13:23:53 -05:00
bors
585f3eef26 Auto merge of #107851 - cjgillot:sroa-const, r=oli-obk
Put deaggregated statements after original constant.

Fixes https://github.com/rust-lang/rust/issues/107818
2023-02-11 20:59:18 +00:00
bors
5a8dfd933a Auto merge of #85158 - JulianKnodt:array_const_val, r=cjgillot
Mir-Opt for copying enums with large discrepancies

I have been meaning to make this for quite a while, based off of this [hackmd](https://hackmd.io/`@ft4bxUsFT5CEUBmRKYHr7w/rJM8BBPzD).`

I'm not sure where to put this opt now that I've made it, so I'd appreciate suggestions on that!
It's also one long chain of statements, not sure if there's a more friendly format to make it.

r? `@tmiasko`
I would `r` oli but he's on leave so he suggested I `r` tmiasko or wesleywiser.
2023-02-10 21:49:31 +00:00
Camille GILLOT
221ea3080d Put deaggregated statements after original constant. 2023-02-09 17:27:31 +00:00
kadmin
15d4728cda Add de-init to destination place 2023-02-08 02:04:07 +00:00
Matthias Krüger
306dbaf574
Rollup merge of #107662 - cjgillot:copy-projection, r=oli-obk
Turn projections into copies in CopyProp.

The current implementation can leave behind projections that are moved out several times.

This PR widens the check to turn such moves into copies: a move out of a projection of a copy is equivalent to a copy of the original projection.
2023-02-07 17:57:15 +01:00
kadmin
15f4eec7a9 Leave FIXME for wasm layout difference.
There is a distinction between running this on wasm and i686, even though they should be
identical. This technically is not _incorrect_, it's just an unexpected difference, which is
worth investigating, but not for correctness.
2023-02-07 09:37:55 +00:00
kadmin
610e1a1e05 Add tag for ignoring wasm 2023-02-07 09:37:55 +00:00
kadmin
5d9f5145ac Rm allocation in candidate
Instead of storing an extra array for discriminant values, create an allocation there and store
those in an allocation immediately.
2023-02-07 09:37:55 +00:00
Camille GILLOT
9a6c04f5d0 Handle discriminants in dataflow-const-prop. 2023-02-06 21:51:47 +00:00
Camille GILLOT
51ef82d19b Bless 32bit tests. 2023-02-05 13:51:37 +00:00
Camille GILLOT
8e05ab04e5 Run SROA to fixpoint. 2023-02-05 12:08:42 +00:00
Camille GILLOT
42c9514629 Simplify construction of replacement map. 2023-02-05 11:44:18 +00:00
Camille GILLOT
dc4fe8e295 Make SROA expand assignments. 2023-02-05 11:42:11 +00:00
Camille GILLOT
0843acbea6 Fix SROA without deaggregation. 2023-02-05 08:37:03 +00:00
Camille GILLOT
5c1cb5bbc6 Turn projections into copies in CopyProp. 2023-02-04 23:33:33 +00:00
Camille GILLOT
5c39ba2027 Bless 32bit. 2023-02-02 23:26:34 +00:00
Camille GILLOT
83173c68f5 Add partial propagation test. 2023-02-02 23:26:29 +00:00
Camille GILLOT
10ec94930b Bless tests. 2023-02-02 23:26:26 +00:00
Camille GILLOT
6a0b218161 Stop deaggregating enums in MIR. 2023-02-02 23:20:27 +00:00
Camille GILLOT
feccf469fb Interpret aggregates. 2023-02-02 23:09:51 +00:00
Matthias Krüger
6917040cf0
Rollup merge of #107524 - cjgillot:both-storage, r=RalfJung
Remove both StorageLive and StorageDead in CopyProp.

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

https://github.com/rust-lang/rust/pull/106908 removed StorageDead without the accompanying StorageLive. In loops, execution would see repeated StorageLive, without any StorageDead, which is UB.

So when removing storage statements, we have to remove both StorageLive and StorageDead.

~I also added a MIR validation pass for StorageLive. It may be a bit overzealous.~
2023-02-02 17:14:06 +01:00
Léo Lanteri Thauvin
b379d216ee Stabilize #![feature(target_feature_11)] 2023-02-01 08:53:02 +01:00
Camille GILLOT
e8ac0404bd Remove assignment. 2023-01-31 18:07:57 +00:00
Camille GILLOT
3c10cf088a Remove both StorageLive and StorageDead in CopyProp. 2023-01-31 17:50:04 +00:00
Camille GILLOT
05ee406cc8 Add test. 2023-01-31 17:49:57 +00:00
Camille GILLOT
a9aed861ac Reimplement NormalizeArrayLen. 2023-01-29 21:19:02 +00:00
bors
2a4b00beaa Auto merge of #106908 - cjgillot:copyprop-ssa, r=oli-obk
Implement simple CopyPropagation based on SSA analysis

This PR extracts the "copy propagation" logic from https://github.com/rust-lang/rust/pull/106285.

MIR may produce chains of assignment between locals, like `_x = move? _y`.
This PR attempts to remove such chains by unifying locals.

The current implementation is a bit overzealous in turning moves into copies, and in removing storage statements.
2023-01-29 13:01:06 +00:00
Camille GILLOT
d3d626920a Bless mir-opt tests. 2023-01-27 22:01:47 +00:00
Camille GILLOT
e2387ad484 Remember where a type was kept in MIR. 2023-01-27 18:59:32 +00:00
Camille GILLOT
d29dc057ba Do not merge locals that have their address taken. 2023-01-27 18:22:45 +00:00
Camille GILLOT
8f1dbe54ea Discard raw pointers from SSA locals. 2023-01-27 18:22:45 +00:00
Camille GILLOT
d45815eb4a Only consider a local to be SSA if assignment dominates all uses. 2023-01-27 18:22:45 +00:00
Camille GILLOT
38b55dc684 Add tests. 2023-01-27 18:22:45 +00:00
Camille GILLOT
6ed9f8f62e Implement SSA CopyProp pass. 2023-01-27 18:22:45 +00:00
Camille GILLOT
8f7e441a54 Add mir-opt test. 2023-01-27 18:22:44 +00:00
Camille GILLOT
8ba0cd6c9e Make tests unit. 2023-01-27 18:22:44 +00:00
Jakob Degen
d7f59e91e0 Custom mir: Add support for some remaining, easy to support constructs 2023-01-26 03:29:28 -08:00
bors
e187f8871e Auto merge of #107314 - matthiaskrgr:rollup-j40lnlj, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - #106407 (Improve proc macro attribute diagnostics)
 - #106960 (Teach parser to understand fake anonymous enum syntax)
 - #107085 (Custom MIR: Support binary and unary operations)
 - #107086 (Print PID holding bootstrap build lock on Linux)
 - #107175 (Fix escaping inference var ICE in `point_at_expr_source_of_inferred_type`)
 - #107204 (suggest qualifying bare associated constants)
 - #107248 (abi: add AddressSpace field to Primitive::Pointer )
 - #107272 (Implement ObjectSafe and WF in the new solver)
 - #107285 (Implement `Generator` and `Future` in the new solver)
 - #107286 (ICE in new solver if we see an inference variable)
 - #107313 (Add Style Team Triagebot config)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-26 06:23:14 +00:00
Matthias Krüger
f3644ca64d
Rollup merge of #107085 - tmiasko:custom-mir-operators, r=oli-obk
Custom MIR: Support binary and unary operations

Lower binary and unary operations directly to corresponding unchecked MIR
operations. Ultimately this might not be syntax we want, but it allows for
experimentation in the meantime.

r? ````@oli-obk```` ````@JakobDegen````
2023-01-26 06:15:24 +01:00
bors
885bf62887 Auto merge of #105582 - saethlin:instcombine-assert-inhabited, r=cjgillot
InstCombine away intrinsic validity assertions

This optimization (currently) fires 246 times on the standard library. It seems to fire hardly at all on the big crates in the benchmark suite. Interesting.
2023-01-26 03:10:52 +00:00
Jakob Degen
ad7393668f Delete SimplifyArmIdentity and SimplifyBranchSame mir opts 2023-01-24 04:13:52 -08:00
Matthias Krüger
66a9006759
Rollup merge of #107067 - tmiasko:custom-mir-storage-statements, r=oli-obk
Custom MIR: Support storage statements

r? `@oli-obk` `@JakobDegen`
2023-01-20 07:16:11 +01:00
Tomasz Miąsko
d3cfe97a8a Custom MIR: Support binary and unary operations 2023-01-19 22:00:33 +01:00
Tomasz Miąsko
ca3d55e32d Custom MIR: Support storage statements 2023-01-19 11:53:33 +01:00
Arpad Borsos
96931a787a
Transform async ResumeTy in generator transform
- Eliminates all the `get_context` calls that async lowering created.
- Replace all `Local` `ResumeTy` types with `&mut Context<'_>`.

The `Local`s that have their types replaced are:
- The `resume` argument itself.
- The argument to `get_context`.
- The yielded value of a `yield`.

The `ResumeTy` hides a `&mut Context<'_>` behind an unsafe raw pointer, and the
`get_context` function is being used to convert that back to a `&mut Context<'_>`.

Ideally the async lowering would not use the `ResumeTy`/`get_context` indirection,
but rather directly use `&mut Context<'_>`, however that would currently
lead to higher-kinded lifetime errors.
See <https://github.com/rust-lang/rust/issues/105501>.

The async lowering step and the type / lifetime inference / checking are
still using the `ResumeTy` indirection for the time being, and that indirection
is removed here. After this transform, the generator body only knows about `&mut Context<'_>`.
2023-01-19 09:03:05 +01:00
Boxy
1171fe5c45 i am free 2023-01-18 04:45:43 +00:00
bors
af669c2684 Auto merge of #106850 - cjgillot:issue-106141, r=oli-obk
Make the inlining destination a Local.

Fixes https://github.com/rust-lang/rust/issues/106141
2023-01-16 12:30:49 +00:00
Ben Kimock
662199f125 InstCombine away intrinsic validity assertions 2023-01-15 16:51:42 -05:00
Camille GILLOT
de9a5b076a Make the inlining destination a Local. 2023-01-14 12:09:06 +00:00
Camille GILLOT
1c327e1133 Add test. 2023-01-14 11:41:22 +00:00
Ulrich Weigand
6885733c41 Fix mir-opt tests for big-endian platforms
The test cases src/test/mir-opt/building/custom/consts.rs and
src/test/mir-opt/const_prop/mutable_variable_no_prop.rs are
currently failing on big-endian platforms as the binary encoding
of some constants is hard-coded in the MIR test files.  Fix this
by choosing constant values that have the same encoding on big-
and little-endian platforms.

The test case src/test/mir-opt/issues/issue_75439.rs is failing
as well, but since the purpose of the test is to validate handling
of big-endian integer encodings on a little-endian platform, it does
not make much sense to run it on big-endian platforms in the first
place - we can just ignore it there.

Fixed part of https://github.com/rust-lang/rust/issues/105383.
2023-01-12 18:05:30 +01:00
Albert Larsan
40ba0e84d5
Change src/test to tests in source files, fix tidy and tests 2023-01-11 09:32:13 +00:00
Albert Larsan
cf2dff2b1e
Move /src/test to /tests 2023-01-11 09:32:08 +00:00