Commit Graph

1531 Commits

Author SHA1 Message Date
Scott McMurray 05bf42bfa9 PR feedback: better comments and debug asserts 2023-05-21 17:48:37 -07:00
Scott McMurray 977ac5b4dd MIR: opt-in normalization of BasicBlock and Local numbering 2023-05-21 17:48:36 -07:00
Jakob Degen 60cc72cf7b Don't inline functions with unsized args 2023-05-20 17:45:50 -07:00
Dylan DPC 1397827f25 Rollup merge of #111619 - cjgillot:profile-pass, r=WaffleLapkin
Add timings for MIR passes to profiling report

This will help identify which pass is responsible for a regression.
2023-05-20 12:20:59 +05:30
Jason Newcomb eaddc37075 Take MIR dataflow analyses by mutable reference. 2023-05-18 17:46:39 -04:00
bors e9e1bbc7a8 Auto merge of #111568 - scottmcm:undo-opt, r=WaffleLapkin
Stop turning transmutes into discriminant reads in mir-opt

Partially reverts #109612, as after #109993 these aren't actually equivalent any more, and I'm no longer confident this was ever an improvement in the first place.

Having this "simplification" meant that similar-looking code actually did somewhat different things.  For example,
```rust
pub unsafe fn demo1(x: std::cmp::Ordering) -> u8 {
    std::mem::transmute(x)
}
pub unsafe fn demo2(x: std::cmp::Ordering) -> i8 {
    std::mem::transmute(x)
}
```
in nightly today is generating <https://rust.godbolt.org/z/dPK58zW18>
```llvm
define noundef i8 `@_ZN7example5demo117h341ef313673d2ee6E(i8` noundef %x) unnamed_addr #0 {
  %0 = icmp uge i8 %x, -1
  %1 = icmp ule i8 %x, 1
  %2 = or i1 %0, %1
  call void `@llvm.assume(i1` %2)
  ret i8 %x
}

define noundef i8 `@_ZN7example5demo217h5ad29f361a3f5700E(i8` noundef %0) unnamed_addr #0 {
  %x = alloca i8, align 1
  store i8 %0, ptr %x, align 1
  %1 = load i8, ptr %x, align 1, !range !2, !noundef !3
  ret i8 %1
}
```

Which feels too different when the original code is essentially identical.

---

Aside: that example is different *after* optimizations too:
```llvm
define noundef i8 `@_ZN7example5demo117h341ef313673d2ee6E(i8` noundef returned %x) unnamed_addr #0 {
  %0 = add i8 %x, 1
  %1 = icmp ult i8 %0, 3
  tail call void `@llvm.assume(i1` %1)
  ret i8 %x
}

define noundef i8 `@_ZN7example5demo217h5ad29f361a3f5700E(i8` noundef returned %0) unnamed_addr #1 {
  ret i8 %0
}
```
so turning the `Transmute` into a `Discriminant` was arguably just making things worse, so leaving it alone instead -- and thus having less code in rustc -- seems clearly better.
2023-05-17 18:53:26 +00:00
Dylan DPC 828caa80a9 Rollup merge of #110930 - b-naber:normalize-elaborate-drops, r=cjgillot
Don't expect normalization to succeed in elaborate_drops

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

This was exposed through the changes in https://github.com/rust-lang/rust/pull/109247, which causes more things to be inlined. Inlining can happen before monomorphization, so we can't expect normalization to succeed. In the elaborate_drops analysis we currently have [this call](https://github.com/rust-lang/rust/blob/033aa092ab23ba14cdad27073c5e37ba0eddb428/compiler/rustc_mir_dataflow/src/elaborate_drops.rs#L278) to `normalize_erasing_regions`, which ICEs when normalization fails. The types are used to infer [whether the type needs a drop](https://github.com/rust-lang/rust/blob/033aa092ab23ba14cdad27073c5e37ba0eddb428/compiler/rustc_mir_dataflow/src/elaborate_drops.rs#L374), where `needs_drop` itself [uses `try_normalize_erasing_regions`](https://github.com/rust-lang/rust/blob/033aa092ab23ba14cdad27073c5e37ba0eddb428/compiler/rustc_middle/src/ty/util.rs#L1121).

~[`instance_mir`](https://doc.rust-lang.org/stable/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.instance_mir) isn't explicit about whether it expects the instances corresponding to the `InstanceDef`s to be monomorphized (though I think in all other contexts the function is used post-monomorphization), so the use of `instance_mir` in inlining doesn't necessarily seem wrong to me.~
2023-05-17 19:11:53 +05:30
Camille GILLOT 8c2c695c9e Simplify back-edge logic. 2023-05-17 12:18:55 +00:00
Camille GILLOT ada7f1c2c4 Do not clone dominator tree for SSA analysis. 2023-05-17 12:17:33 +00:00
Maybe Waffle f542778533 Drive-by cleanup: debug::term_type => TerminatorKind::name 2023-05-17 11:27:37 +00:00
Camille GILLOT fa8598cb50 Merge DominatorTree and Dominators. 2023-05-17 10:37:29 +00:00
Camille GILLOT 6f271dc49c Cache dominators. 2023-05-17 09:36:12 +00:00
Tomasz Miąsko aa1267f630 Preprocess dominator tree to answer queries in O(1) 2023-05-17 09:36:12 +00:00
bors 5c3a3362f8 Auto merge of #111556 - cjgillot:copy-prop-nrvo, r=oli-obk
Merge return place with other locals in CopyProp.

This reintroduces a limited form of NRVO.

r? wg-mir-opt
2023-05-16 22:27:08 +00:00
Matthias Krüger 426dbcdf92 Rollup merge of #111533 - clubby789:drop-tracking-error, r=oli-obk
Handle error body in generator layout

Fixes #111468

I feel like making this query return `Option<GeneratorLayout>` might be better but had some issues with that approach
2023-05-16 20:12:16 +02:00
Camille GILLOT addc72799a Profile MIR passes. 2023-05-15 20:27:12 +00:00
John Kåre Alsaker fff20a703d Move expansion of query macros in rustc_middle to rustc_middle::query 2023-05-15 08:49:13 +02:00
Scott McMurray 363c202581 Stop turning transmutes into discriminants in mir-opt
Partially reverts 109612, as after 109993 these aren't actually equivalent any more, and I'm no longer confident this was ever an improvement in the first place.
2023-05-14 11:46:07 -07:00
Camille GILLOT adfffc7e12 Simplify implementation. 2023-05-14 12:10:24 +00:00
Camille GILLOT f40f235879 Merge return place with other locals in CopyProp. 2023-05-14 12:06:34 +00:00
bors 3603a84a3d Auto merge of #111517 - lukas-code:addr-of-mutate, r=tmiasko
allow mutating function args through `&raw const`

Fixes https://github.com/rust-lang/rust/issues/111502 by "turning off the sketchy optimization while we figure out if this is ok", like `@JakobDegen` said.

The first commit in this PR removes some suspicious looking logic from the same method, but should have no functional changes, since it doesn't modify the `context` outside of the method. Best reviewed commit by commit.

r? opsem
2023-05-14 10:45:39 +00:00
clubby789 f77971e221 Handle error body when in generator layout 2023-05-13 16:45:19 +01:00
Camille GILLOT 13fb0794ac Do not ICE on deeply nested borrows. 2023-05-13 10:29:05 +00:00
Camille GILLOT 19652377c3 Iterate ReferencePropagation to fixpoint. 2023-05-13 10:17:28 +00:00
Camille GILLOT 2ec0071913 Implement references VarDebugInfo. 2023-05-13 10:12:14 +00:00
Lukas Markeffsky 9c418e5170 allow mutating function args through &raw const 2023-05-13 00:00:51 +02:00
Lukas Markeffsky 97ed808322 remove no-op logic 2023-05-12 23:14:31 +02:00
Matthias Krüger ab18da61f4 Rollup merge of #111441 - cjgillot:issue-111422, r=JakobDegen
Verify copies of mutable pointers in 2 stages in ReferencePropagation

Fixes #111422

In the first stage, we mark the copies as reborrows, to be checked later.
In the second stage, we walk the reborrow chains to verify that all stages are fully replacable.

The replacement itself mirrors the check, and iterates through the reborrow chain.

r? ``````@RalfJung``````
cc ``````@JakobDegen``````
2023-05-12 07:11:13 +02:00
Matthias Krüger 968911dbc0 Rollup merge of #111432 - cjgillot:issue-111426, r=oli-obk
Use visit_assign to detect SSA locals.

I screwed up the logic in 3c43b61b87.

Fixes https://github.com/rust-lang/rust/issues/111426
2023-05-11 07:05:29 +02:00
bors 9a767b6b9e Auto merge of #110820 - cjgillot:faster-dcp, r=oli-obk
Optimize dataflow-const-prop place-tracking infra

Optimization opportunities found while investigating https://github.com/rust-lang/rust/pull/110719

Computing places breadth-first ensures that we create short projections before deep projections, since the former are more likely to be propagated.

The most relevant is the pre-computation of flooded places. Callgrind showed `flood_*` methods and especially `preorder_preinvoke` were especially hot. This PR attempts to pre-compute the set of `ValueIndex` that `preorder_invoke` would visit.

Using this information, we make some `PlaceIndex` inaccessible when they contain no `ValueIndex`, allowing to skip computations for those places.

cc `@jachris` as original author
2023-05-10 20:54:31 +00:00
Camille GILLOT 9fb1c73a73 Avoid shadowing. 2023-05-10 19:23:01 +00:00
Camille GILLOT aeac555578 Do not see through copies of mutable pointers. 2023-05-10 19:22:57 +00:00
Camille GILLOT d0d4e0237f Iteratively replace pointers. 2023-05-10 19:22:54 +00:00
b-naber e7a2f52ba1 don't inline polymorphic adt instances whose fields contain projections
in DropGlue.
2023-05-10 16:03:52 +00:00
Camille GILLOT 6ad0497cc0 Use visit_assign to detect SSA locals. 2023-05-10 15:26:51 +00:00
Camille GILLOT c17e878fb8 Correct StorageLive comment. 2023-05-09 17:59:35 +00:00
Camille GILLOT a67bf08ed7 Only check storage liveness for direct projections. 2023-05-09 17:59:35 +00:00
Camille GILLOT 3b4e1fe104 Do not check StorageLive dominates address-taking. 2023-05-09 17:59:35 +00:00
Camille GILLOT 3268f2e61d Only check that StorageLive dominates address-taking. 2023-05-09 17:59:35 +00:00
Camille GILLOT 0bd9bd6b8a Explicit performance concern. 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
Camille GILLOT add5124dce Extract handle_set_discriminant. 2023-05-09 17:27:58 +00:00
Camille GILLOT 71138e9933 Make HasTop and HasBottom consts. 2023-05-09 17:27:58 +00:00
bors 2f2c438dce Auto merge of #111358 - compiler-errors:rollup-yv27vrp, r=compiler-errors
Rollup of 6 pull requests

Successful merges:

 - #104070 (Prevent aborting guard from aborting the process in a forced unwind)
 - #109410 (Introduce `AliasKind::Inherent` for inherent associated types)
 - #111004 (Migrate `mir_transform` to translatable diagnostics)
 - #111118 (Suggest struct when we get colon in fileds in enum)
 - #111170 (Diagnostic args are still args if they're documented)
 - #111354 (Fix miscompilation when calling default methods on `Future`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-08 21:00:50 +00:00
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
Michael Goulet 68594142b1 Rollup merge of #111004 - clubby789:migrate-mir-transform, r=oli-obk
Migrate `mir_transform` to translatable diagnostics

cc #100717
2023-05-08 09:30:22 -07: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
Dylan DPC 71a1ac2c9a Rollup merge of #110297 - kylematsuda:earlybinder_tcx_subst, r=BoxyUwU
Make `(try_)subst_and_normalize_erasing_regions` take `EarlyBinder`

Changes `subst_and_normalize_erasing_regions` and `try_subst_and_normalize_erasing_regions` to take  `EarlyBinder<T>` instead of `T`.

(related to #105779)

This was suggested by `@BoxyUwU` in https://github.com/rust-lang/rust/pull/107753#discussion_r1105828139. After changing `type_of` to return `EarlyBinder`, there were several places where the binder was immediately skipped to call `tcx.subst_and_normalize_erasing_regions`, only for the binder to be reconstructed inside of that method.

r? `@BoxyUwU`
2023-05-08 11:39:20 +05:30