Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mir-opt] asking `?`s in a more optimized fashion #66282

Merged
merged 1 commit into from Nov 22, 2019

Conversation

@Centril
Copy link
Member

Centril commented Nov 11, 2019

This PR works towards #66234 by providing two optimization passes meant to run in sequence:

  • SimplifyArmIdentity which transforms something like:

    _LOCAL_TMP = ((_LOCAL_1 as Variant ).FIELD: TY );
    ((_LOCAL_0 as Variant).FIELD: TY) = move _LOCAL_TMP;
    discriminant(_LOCAL_0) = VAR_IDX;

    into:

    _LOCAL_0 = move _LOCAL_1
  • SimplifyBranchSame which transforms SwitchInts to identical basic blocks into a goto to the first reachable target.

Together, these are meant to simplify the following into just res:

match res {
    Ok(x) => Ok(x),
    Err(x) => Err(x),
}

It should be noted however that the desugaring of ? includes a function call and so the first pass in this PR relies on inlining to substitute that function call for identity on x. Inlining requires mir-opt-level=2 so this might not have any effect in perf-bot but let's find out.

r? @oli-obk -- This is WIP, but I'd appreciate feedback. :)

@Centril

This comment has been minimized.

Copy link
Member Author

Centril commented Nov 11, 2019

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

Copy link

rust-timer commented Nov 11, 2019

Awaiting bors try build completion

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Nov 11, 2019

⌛️ Trying commit 91e5a0e with merge fb1a35e...

bors added a commit that referenced this pull request Nov 11, 2019
[WIP] [mir-opt] asking `?`s in a more optimized fashion

This PR works towards #66234 by providing two optimization passes meant to run in sequence:

- `SimplifyArmIdentity` which transforms something like:
  ```rust
  _LOCAL_TMP = ((_LOCAL_1 as Variant ).FIELD: TY );
  ((_LOCAL_0 as Variant).FIELD: TY) = move _LOCAL_TMP;
  discriminant(_LOCAL_0) = VAR_IDX;
  ```

  into:

  ```rust
  _LOCAL_0 = move _LOCAL_1
  ```

- `SimplifyBranchSame` which transforms `SwitchInt`s to identical basic blocks into a `goto` to the first reachable target.

Together, these are meant to simplify the following into just `res`:
```rust
match res {
    Ok(x) => Ok(x),
    Err(x) => Err(x),
}
```

It should be noted however that the desugaring of `?` includes a function call and so the first pass in this PR relies on inlining to substitute that function call for identity on `x`. Inlining requires `mir-opt-level=2` so this might not have any effect in perf-bot but let's find out.

r? @oli-obk -- This is WIP, but I'd appreciate feedback. :)
@Centril

This comment has been minimized.

Copy link
Member Author

Centril commented Nov 11, 2019

@bors retry

@Centril

This comment has been minimized.

Copy link
Member Author

Centril commented Nov 11, 2019

@bors retry try

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Nov 11, 2019

⌛️ Trying commit 657c945 with merge 0113342...

bors added a commit that referenced this pull request Nov 11, 2019
[WIP] [mir-opt] asking `?`s in a more optimized fashion

This PR works towards #66234 by providing two optimization passes meant to run in sequence:

- `SimplifyArmIdentity` which transforms something like:
  ```rust
  _LOCAL_TMP = ((_LOCAL_1 as Variant ).FIELD: TY );
  ((_LOCAL_0 as Variant).FIELD: TY) = move _LOCAL_TMP;
  discriminant(_LOCAL_0) = VAR_IDX;
  ```

  into:

  ```rust
  _LOCAL_0 = move _LOCAL_1
  ```

- `SimplifyBranchSame` which transforms `SwitchInt`s to identical basic blocks into a `goto` to the first reachable target.

Together, these are meant to simplify the following into just `res`:
```rust
match res {
    Ok(x) => Ok(x),
    Err(x) => Err(x),
}
```

It should be noted however that the desugaring of `?` includes a function call and so the first pass in this PR relies on inlining to substitute that function call for identity on `x`. Inlining requires `mir-opt-level=2` so this might not have any effect in perf-bot but let's find out.

r? @oli-obk -- This is WIP, but I'd appreciate feedback. :)
// scope 6 {
// }
// bb0: {
// _2 = discriminant(_1);

This comment has been minimized.

Copy link
@Centril

Centril Nov 11, 2019

Author Member

This is a tad unfortunate that _2 isn't optimized out.

This comment has been minimized.

Copy link
@oli-obk

oli-obk Nov 11, 2019

Contributor

I thought we had some sort of DCE. If not, open an issue so we create it

This comment has been minimized.

Copy link
@wesleywiser

wesleywiser Nov 11, 2019

Member

I think this will be easy to fix. I'll open a PR tonight with that.

This comment has been minimized.

Copy link
@oli-obk

oli-obk Nov 12, 2019

Contributor

There are some ppl at rustfest working on it

This comment has been minimized.

Copy link
@Centril

Centril Nov 12, 2019

Author Member

Does that refer to #66329 ? -- That won't help in this case since this is an unused, but reachable, local.

This comment has been minimized.

Copy link
@oli-obk

oli-obk Nov 12, 2019

Contributor

No, different optimization, not sure on what repo it's being developed

@rust-highfive

This comment was marked as outdated.

Copy link
Collaborator

rust-highfive commented Nov 11, 2019

The job dist-x86_64-linux-alt of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-11-11T04:30:25.1341610Z [RUSTC-TIMING] rustc_traits test:false 65.160
2019-11-11T04:30:25.1342123Z    Compiling rustc_passes v0.0.0 (/checkout/src/librustc_passes)
2019-11-11T04:31:08.6176939Z [RUSTC-TIMING] rustc_passes test:false 43.476
2019-11-11T04:31:08.6231708Z    Compiling rustc_mir v0.0.0 (/checkout/src/librustc_mir)
2019-11-11T04:31:23.8394662Z error[E0382]: use of moved value: `vf_s0`
2019-11-11T04:31:23.8395143Z   --> src/librustc_mir/transform/simplify_try.rs:54:35
2019-11-11T04:31:23.8395434Z    |
2019-11-11T04:31:23.8396607Z 45 |             let (local_tmp_s0, local_1, vf_s0) = match match_get_variant_field(s0) {
2019-11-11T04:31:23.8397180Z    |                                         ----- move occurs because `vf_s0` has type `transform::simplify_try::VarField<'_>`, which does not implement the `Copy` trait
2019-11-11T04:31:23.8397656Z ...
2019-11-11T04:31:23.8398144Z 53 |             if (local_tmp_s0, vf_s0) != (local_tmp_s1, vf_s1)
2019-11-11T04:31:23.8398573Z    |                               ----- value moved here
2019-11-11T04:31:23.8399031Z 54 |                 || Some((local_0, vf_s0.var_idx)) != match_set_discr(s2)
2019-11-11T04:31:23.8399508Z    |                                   ^^^^^^^^^^^^^ value used here after move
2019-11-11T04:31:27.2401323Z error: aborting due to previous error
2019-11-11T04:31:27.2405768Z 
2019-11-11T04:31:27.2416558Z For more information about this error, try `rustc --explain E0382`.
2019-11-11T04:31:27.3742025Z [RUSTC-TIMING] rustc_mir test:false 18.745
---
2019-11-11T04:32:48.4672990Z   local time: Mon Nov 11 04:32:48 UTC 2019
2019-11-11T04:32:48.7846213Z   network time: Mon, 11 Nov 2019 04:32:48 GMT
2019-11-11T04:32:48.7847517Z == end clock drift check ==
2019-11-11T04:32:51.6983858Z 
2019-11-11T04:32:51.7095887Z ##[error]Bash exited with code '1'.
2019-11-11T04:32:51.7135441Z ##[section]Starting: Checkout
2019-11-11T04:32:51.7137620Z ==============================================================================
2019-11-11T04:32:51.7137736Z Task         : Get sources
2019-11-11T04:32:51.7137852Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

rust-highfive commented Nov 11, 2019

The job x86_64-gnu-llvm-6.0 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-11-11T04:05:18.4634736Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-11-11T04:05:18.4824983Z ##[command]git config gc.auto 0
2019-11-11T04:05:18.4904942Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-11-11T04:05:18.4964558Z ##[command]git config --get-all http.proxy
2019-11-11T04:05:18.5108718Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/66282/merge:refs/remotes/pull/66282/merge
---
2019-11-11T05:04:00.7890563Z .................................................................................................... 1400/9227
2019-11-11T05:04:07.1747955Z .................................................................................................... 1500/9227
2019-11-11T05:04:13.2698505Z .................................................................................................... 1600/9227
2019-11-11T05:04:22.5020119Z .................................................................................................... 1700/9227
2019-11-11T05:04:30.8971540Z ..i................................................................................................. 1800/9227
2019-11-11T05:04:37.7082616Z ......................................................................................iiiii......... 1900/9227
2019-11-11T05:04:58.9044766Z .................................................................................................... 2100/9227
2019-11-11T05:05:01.3583095Z .................................................................................................... 2200/9227
2019-11-11T05:05:03.9124670Z .................................................................................................... 2300/9227
2019-11-11T05:05:13.4960353Z .................................................................................................... 2400/9227
---
2019-11-11T05:08:05.7606566Z ..................................................................................i...............i. 4700/9227
2019-11-11T05:08:12.8329815Z .................................................................................................... 4800/9227
2019-11-11T05:08:21.9631265Z .................................................................................................... 4900/9227
2019-11-11T05:08:27.2114287Z .................................................................................................... 5000/9227
2019-11-11T05:08:38.4190631Z ....................................................................................ii.ii........... 5100/9227
2019-11-11T05:08:42.2901894Z i................................................................................................... 5200/9227
2019-11-11T05:08:57.0755168Z .................................................................................................... 5400/9227
2019-11-11T05:09:04.0494353Z ..................................................................i................................. 5500/9227
2019-11-11T05:09:12.1834079Z .................................................................................................... 5600/9227
2019-11-11T05:09:20.3521104Z .................................................................................................... 5700/9227
2019-11-11T05:09:20.3521104Z .................................................................................................... 5700/9227
2019-11-11T05:09:28.9561883Z ...................................................ii...i..ii...........i........................... 5800/9227
2019-11-11T05:09:51.6819754Z .................................................................................................... 6000/9227
2019-11-11T05:10:00.1589920Z .................................................................................................... 6100/9227
2019-11-11T05:10:00.1589920Z .................................................................................................... 6100/9227
2019-11-11T05:10:10.4098804Z ......................................................................i..ii......................... 6200/9227
2019-11-11T05:10:40.5355090Z .................................................................................................... 6400/9227
2019-11-11T05:10:42.7380818Z ......................................i............................................................. 6500/9227
2019-11-11T05:10:45.0201568Z .................................................................................................... 6600/9227
2019-11-11T05:10:47.4145733Z .......................i............................................................................ 6700/9227
---
2019-11-11T05:15:58.7979422Z  finished in 5.869
2019-11-11T05:15:58.8163757Z Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-11T05:15:59.0039343Z 
2019-11-11T05:15:59.0039626Z running 156 tests
2019-11-11T05:16:01.9371088Z iiii....iii......iii..iiii...i.............................i..i..................iF...i...........ii 100/156
2019-11-11T05:16:04.6807167Z .i.i..iiii..............i.........iii.i.........ii......
2019-11-11T05:16:04.6817243Z 
2019-11-11T05:16:04.6818448Z ---- [codegen] codegen/match.rs stdout ----
2019-11-11T05:16:04.6818854Z 
2019-11-11T05:16:04.6818854Z 
2019-11-11T05:16:04.6819343Z error: verification with 'FileCheck' failed
2019-11-11T05:16:04.6819577Z status: exit code: 1
2019-11-11T05:16:04.6821283Z command: "/usr/lib/llvm-6.0/bin/FileCheck" "--input-file" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen/match/match.ll" "/checkout/src/test/codegen/match.rs"
2019-11-11T05:16:04.6822216Z ------------------------------------------
2019-11-11T05:16:04.6822793Z 
2019-11-11T05:16:04.6823294Z ------------------------------------------
2019-11-11T05:16:04.6823537Z stderr:
2019-11-11T05:16:04.6823537Z stderr:
2019-11-11T05:16:04.6823918Z ------------------------------------------
2019-11-11T05:16:04.6824132Z /checkout/src/test/codegen/match.rs:13:11: error: expected string not found in input
2019-11-11T05:16:04.6824813Z // CHECK: switch{{.*}}, label %[[OTHERWISE:[a-zA-Z0-9_]+]] [
2019-11-11T05:16:04.6825138Z           ^
2019-11-11T05:16:04.6825661Z /checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen/match/match.ll:7:30: note: scanning from here
2019-11-11T05:16:04.6826006Z define void @exhaustive_match(i1 zeroext) unnamed_addr #0 {
2019-11-11T05:16:04.6826482Z                              ^
2019-11-11T05:16:04.6827032Z /checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen/match/match.ll:11:13: note: possible intended match here
2019-11-11T05:16:04.6827254Z  store i8 %1, i8* %e, align 1
2019-11-11T05:16:04.6827536Z 
2019-11-11T05:16:04.6828032Z ------------------------------------------
2019-11-11T05:16:04.6828248Z 
2019-11-11T05:16:04.6828372Z 
---
2019-11-11T05:16:04.6830317Z thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:537:22
2019-11-11T05:16:04.6830689Z note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
2019-11-11T05:16:04.6830916Z 
2019-11-11T05:16:04.6831028Z 
2019-11-11T05:16:04.6832938Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/codegen" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "codegen" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-6.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "6.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
2019-11-11T05:16:04.6833445Z 
2019-11-11T05:16:04.6833585Z 
2019-11-11T05:16:04.6833727Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
2019-11-11T05:16:04.6833869Z Build completed unsuccessfully in 1:04:12
2019-11-11T05:16:04.6833869Z Build completed unsuccessfully in 1:04:12
2019-11-11T05:16:04.6834029Z == clock drift check ==
2019-11-11T05:16:04.6834165Z   local time: Mon Nov 11 05:16:03 UTC 2019
2019-11-11T05:16:04.6834319Z   network time: Mon, 11 Nov 2019 05:16:03 GMT
2019-11-11T05:16:04.6834455Z == end clock drift check ==
2019-11-11T05:16:08.2521115Z 
2019-11-11T05:16:08.2620458Z ##[error]Bash exited with code '1'.
2019-11-11T05:16:08.2658395Z ##[section]Starting: Checkout
2019-11-11T05:16:08.2660347Z ==============================================================================
2019-11-11T05:16:08.2660411Z Task         : Get sources
2019-11-11T05:16:08.2660452Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Nov 11, 2019

☀️ Try build successful - checks-azure
Build commit: 0113342 (0113342691c2ecbb2b7fd1d083fd0631f136b1dd)

@rust-timer

This comment has been minimized.

Copy link

rust-timer commented Nov 11, 2019

Queued 0113342 with parent e2fa952, future comparison URL.

@rust-timer

This comment has been minimized.

Copy link

rust-timer commented Nov 11, 2019

Finished benchmarking try commit 0113342, comparison URL.

@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

rust-highfive commented Nov 12, 2019

The job x86_64-gnu-llvm-6.0 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-11-12T09:58:08.7449969Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-11-12T09:58:08.7469901Z ##[command]git config gc.auto 0
2019-11-12T09:58:08.7472048Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-11-12T09:58:08.7473824Z ##[command]git config --get-all http.proxy
2019-11-12T09:58:08.7477600Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/66282/merge:refs/remotes/pull/66282/merge
---
2019-11-12T10:58:44.4467909Z .................................................................................................... 1400/9231
2019-11-12T10:58:51.0180404Z .................................................................................................... 1500/9231
2019-11-12T10:58:57.3861025Z .................................................................................................... 1600/9231
2019-11-12T10:59:07.0690486Z .................................................................................................... 1700/9231
2019-11-12T10:59:15.9130887Z ..i................................................................................................. 1800/9231
2019-11-12T10:59:22.9995859Z ......................................................................................iiiii......... 1900/9231
2019-11-12T10:59:45.3831654Z .................................................................................................... 2100/9231
2019-11-12T10:59:47.9291607Z .................................................................................................... 2200/9231
2019-11-12T10:59:50.5334209Z .................................................................................................... 2300/9231
2019-11-12T11:00:00.5237723Z .................................................................................................... 2400/9231
---
2019-11-12T11:03:01.2890719Z ..................................................................................i...............i. 4700/9231
2019-11-12T11:03:08.6602816Z .................................................................................................... 4800/9231
2019-11-12T11:03:18.3228370Z .................................................................................................... 4900/9231
2019-11-12T11:03:23.8782378Z .................................................................................................... 5000/9231
2019-11-12T11:03:35.9462867Z .....................................................................................ii.ii.......... 5100/9231
2019-11-12T11:03:39.9199628Z .i.................................................................................................. 5200/9231
2019-11-12T11:03:55.1276593Z .................................................................................................... 5400/9231
2019-11-12T11:04:02.5236450Z ...................................................................i................................ 5500/9231
2019-11-12T11:04:10.2134422Z .................................................................................................... 5600/9231
2019-11-12T11:04:18.4989027Z .................................................................................................... 5700/9231
2019-11-12T11:04:18.4989027Z .................................................................................................... 5700/9231
2019-11-12T11:04:27.9772630Z ....................................................ii...i..ii...........i.......................... 5800/9231
2019-11-12T11:04:51.7340015Z .................................................................................................... 6000/9231
2019-11-12T11:05:00.3577000Z .................................................................................................... 6100/9231
2019-11-12T11:05:00.3577000Z .................................................................................................... 6100/9231
2019-11-12T11:05:08.2372074Z .......................................................................i..ii........................ 6200/9231
2019-11-12T11:05:38.6274215Z .................................................................................................... 6400/9231
2019-11-12T11:05:40.9449537Z .......................................i............................................................ 6500/9231
2019-11-12T11:05:43.2794877Z .................................................................................................... 6600/9231
2019-11-12T11:05:45.7077369Z .......................i............................................................................ 6700/9231
---
2019-11-12T11:11:15.6860171Z  finished in 6.075
2019-11-12T11:11:15.7061370Z Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-12T11:11:15.9079521Z 
2019-11-12T11:11:15.9088724Z running 156 tests
2019-11-12T11:11:18.9331223Z iiii....iii......iii..iiii...i.............................i..i..................iF...i...........ii 100/156
2019-11-12T11:11:20.9184634Z .i.i..iiii..............i.........iii.i.........ii......
2019-11-12T11:11:21.4772220Z 
2019-11-12T11:11:21.4773095Z ---- [codegen] codegen/match.rs stdout ----
2019-11-12T11:11:21.4773293Z 
2019-11-12T11:11:21.4773293Z 
2019-11-12T11:11:21.4773800Z error: verification with 'FileCheck' failed
2019-11-12T11:11:21.4773979Z status: exit code: 1
2019-11-12T11:11:21.4774600Z command: "/usr/lib/llvm-6.0/bin/FileCheck" "--input-file" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen/match/match.ll" "/checkout/src/test/codegen/match.rs"
2019-11-12T11:11:21.4776023Z ------------------------------------------
2019-11-12T11:11:21.4776203Z 
2019-11-12T11:11:21.4776543Z ------------------------------------------
2019-11-12T11:11:21.4777032Z stderr:
2019-11-12T11:11:21.4777032Z stderr:
2019-11-12T11:11:21.4778005Z ------------------------------------------
2019-11-12T11:11:21.4778233Z /checkout/src/test/codegen/match.rs:13:11: error: expected string not found in input
2019-11-12T11:11:21.4778832Z // CHECK: switch{{.*}}, label %[[OTHERWISE:[a-zA-Z0-9_]+]] [
2019-11-12T11:11:21.4779119Z           ^
2019-11-12T11:11:21.4779621Z /checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen/match/match.ll:7:30: note: scanning from here
2019-11-12T11:11:21.4779814Z define void @exhaustive_match(i1 zeroext) unnamed_addr #0 {
2019-11-12T11:11:21.4779977Z                              ^
2019-11-12T11:11:21.4780475Z /checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen/match/match.ll:11:13: note: possible intended match here
2019-11-12T11:11:21.4780867Z  store i8 %1, i8* %e, align 1
2019-11-12T11:11:21.4781473Z 
2019-11-12T11:11:21.4781770Z ------------------------------------------
2019-11-12T11:11:21.4781901Z 
2019-11-12T11:11:21.4782004Z 
---
2019-11-12T11:11:21.4783430Z thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:537:22
2019-11-12T11:11:21.4783599Z note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
2019-11-12T11:11:21.4783704Z 
2019-11-12T11:11:21.4783801Z 
2019-11-12T11:11:21.4786604Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/codegen" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "codegen" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-6.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "6.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
2019-11-12T11:11:21.4787633Z 
2019-11-12T11:11:21.4787757Z 
2019-11-12T11:11:21.4787908Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
2019-11-12T11:11:21.4788080Z Build completed unsuccessfully in 1:06:50
2019-11-12T11:11:21.4788080Z Build completed unsuccessfully in 1:06:50
2019-11-12T11:11:21.4788222Z == clock drift check ==
2019-11-12T11:11:21.4788366Z   local time: Tue Nov 12 11:11:20 UTC 2019
2019-11-12T11:11:21.4788531Z   network time: Tue, 12 Nov 2019 11:11:21 GMT
2019-11-12T11:11:21.4788670Z == end clock drift check ==
2019-11-12T11:11:25.1920975Z 
2019-11-12T11:11:25.2033657Z ##[error]Bash exited with code '1'.
2019-11-12T11:11:25.2113471Z ##[section]Starting: Checkout
2019-11-12T11:11:25.2115252Z ==============================================================================
2019-11-12T11:11:25.2115309Z Task         : Get sources
2019-11-12T11:11:25.2115356Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@Centril Centril force-pushed the Centril:simplify-try branch from 219d24f to f026031 Nov 12, 2019
@Centril Centril changed the title [WIP] [mir-opt] asking `?`s in a more optimized fashion [mir-opt] asking `?`s in a more optimized fashion Nov 12, 2019
@Centril

This comment has been minimized.

Copy link
Member Author

Centril commented Nov 12, 2019

Adjusted the existing match.rs codegen test and introduced a new one which demonstrates that the MIR optimizations introduced produce better LLVM IR as compared to before.


Me and Oliver have been discussing some generalizations to these optimizations (for follow ups). In particular, we can generalize the second one into two passes:

  1. DedupBlocks -- This one looks for identical basic blocks, collects a substitution map, and then substitutes all references to BasicBlock for the key in the map. If we want, this could be run to a fixed point, but we could start it off as a one-shot pass.

  2. SwitchToSamePlace -- This does (could be split up but maybe not depending on complexity):
    a. Filters BBs that are unreachable
    b. Merges identical targets
    c. If one target is left ==> goto
    d. If no targets are left ==> unreachable

    -- a. & d. sorta want to be run to a fixed point but we should probably start off as one-shot instead.

Finally, the SimplifyArmIdentity could be generalized to also recognize e.g. Var(a, b, c) => Var(a, b, c) and not just Var(a) => Var(a).

@Centril

This comment has been minimized.

Copy link
Member Author

Centril commented Nov 12, 2019

Actually, looking at CfgSimplifier::simplify_branch it looks like SwitchToSamePlace is a generalization of that logic. simplify_branch requires all targets to end up in the same place whereas the generalization would first do a filter and simplify e.g. -> [bb2, bb3, otherwise: bb2] to -> [bb2, otherwise: bb3]. We can perhaps add the logic there instead.

@Centril

This comment has been minimized.

Copy link
Member Author

Centril commented Nov 12, 2019

This should be ready now :)

@bors

This comment was marked as resolved.

Copy link
Contributor

bors commented Nov 21, 2019

🔒 Merge conflict

This pull request and the master branch diverged in a way that cannot be automatically merged. Please rebase on top of the latest master branch, and let the reviewer approve again.

How do I rebase?

Assuming self is your fork and upstream is this repository, you can resolve the conflict following these steps:

  1. git checkout simplify-try (switch to your branch)
  2. git fetch upstream master (retrieve the latest master)
  3. git rebase upstream/master -p (rebase on top of it)
  4. Follow the on-screen instruction to resolve conflicts (check git status if you got lost).
  5. git push self simplify-try --force-with-lease (update this PR)

You may also read Git Rebasing to Resolve Conflicts by Drew Blessing for a short tutorial.

Please avoid the "Resolve conflicts" button on GitHub. It uses git merge instead of git rebase which makes the PR commit history more difficult to read.

Sometimes step 4 will complete without asking for resolution. This is usually due to difference between how Cargo.lock conflict is handled during merge and rebase. This is normal, and you should still perform step 5 to update this PR.

Error message
Auto-merging src/librustc_mir/lib.rs
CONFLICT (content): Merge conflict in src/librustc_mir/lib.rs
Auto-merging src/librustc/mir/mod.rs
Auto-merging src/librustc/hir/mod.rs
CONFLICT (content): Merge conflict in src/librustc/hir/mod.rs
Automatic merge failed; fix conflicts and then commit the result.

@bors

This comment was marked as resolved.

Copy link
Contributor

bors commented Nov 21, 2019

☔️ The latest upstream changes (presumably #66607) made this pull request unmergeable. Please resolve the merge conflicts.

This optimization depends on inlining for the identity
conversions introduced by the lowering of the `?`.
To take advantage of `SimplifyArmIdentity`, `-Z mir-opt-level=2`
is required because that triggers the inlining MIR optimization.
@Centril Centril force-pushed the Centril:simplify-try branch from eeba2ec to 2f00e86 Nov 21, 2019
@Centril

This comment has been minimized.

Copy link
Member Author

Centril commented Nov 21, 2019

@bors r=oli-obk

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Nov 21, 2019

📌 Commit 2f00e86 has been approved by oli-obk

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Nov 22, 2019

⌛️ Testing commit 2f00e86 with merge ae731e6...

bors added a commit that referenced this pull request Nov 22, 2019
[mir-opt] asking `?`s in a more optimized fashion

This PR works towards #66234 by providing two optimization passes meant to run in sequence:

- `SimplifyArmIdentity` which transforms something like:
  ```rust
  _LOCAL_TMP = ((_LOCAL_1 as Variant ).FIELD: TY );
  ((_LOCAL_0 as Variant).FIELD: TY) = move _LOCAL_TMP;
  discriminant(_LOCAL_0) = VAR_IDX;
  ```

  into:

  ```rust
  _LOCAL_0 = move _LOCAL_1
  ```

- `SimplifyBranchSame` which transforms `SwitchInt`s to identical basic blocks into a `goto` to the first reachable target.

Together, these are meant to simplify the following into just `res`:
```rust
match res {
    Ok(x) => Ok(x),
    Err(x) => Err(x),
}
```

It should be noted however that the desugaring of `?` includes a function call and so the first pass in this PR relies on inlining to substitute that function call for identity on `x`. Inlining requires `mir-opt-level=2` so this might not have any effect in perf-bot but let's find out.

r? @oli-obk -- This is WIP, but I'd appreciate feedback. :)
@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Nov 22, 2019

Your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-11-22T00:10:43.0377317Z do so (now or later) by using -b with the checkout command again. Example:
2019-11-22T00:10:43.0378736Z 
2019-11-22T00:10:43.0378832Z   git checkout -b <new-branch-name>
2019-11-22T00:10:43.0378867Z 
2019-11-22T00:10:43.0378942Z HEAD is now at ae731e69b Auto merge of #66282 - Centril:simplify-try, r=oli-obk
2019-11-22T00:10:43.0769463Z ##[section]Starting: Decide whether to run this job
2019-11-22T00:10:43.0870334Z ==============================================================================
2019-11-22T00:10:43.0870455Z Task         : Bash
2019-11-22T00:10:43.0870535Z Description  : Run a Bash script on macOS, Linux, or Windows
---
2019-11-22T00:10:44.1732643Z 
2019-11-22T00:10:44.1732668Z 
2019-11-22T00:10:44.1732692Z 
2019-11-22T00:10:44.1732733Z 
2019-11-22T00:10:44.1732799Z     Err(x) => Err(x),
2019-11-22T00:10:44.1732868Z     Ok(x) => Ok(x),
2019-11-22T00:10:44.1732929Z   ((_LOCAL_0 as Variant).FIELD: TY) = move _LOCAL_TMP;
2019-11-22T00:10:44.1733006Z   _LOCAL_0 = move _LOCAL_1
2019-11-22T00:10:44.1733069Z   _LOCAL_TMP = ((_LOCAL_1 as Variant ).FIELD: TY );
2019-11-22T00:10:44.1733140Z   ```
2019-11-22T00:10:44.1733182Z   ```
2019-11-22T00:10:44.1733241Z   ```rust
2019-11-22T00:10:44.1733326Z   ```rust
2019-11-22T00:10:44.1733373Z   discriminant(_LOCAL_0) = VAR_IDX;
2019-11-22T00:10:44.1733598Z   into:
2019-11-22T00:10:44.1733653Z - `SimplifyArmIdentity` which transforms something like:
2019-11-22T00:10:44.1733752Z - `SimplifyBranchSame` which transforms `SwitchInt`s to identical basic blocks into a `goto` to the first reachable target.
2019-11-22T00:10:44.1733902Z AGENT_DISABLELOGPLUGIN_TESTFILEPUBLISHERPLUGIN=true
2019-11-22T00:10:44.1733982Z AGENT_DISABLELOGPLUGIN_TESTRESULTLOGPLUGIN=true
2019-11-22T00:10:44.1734038Z AGENT_HOMEDIRECTORY=C:\agents\2.160.1
2019-11-22T00:10:44.1734106Z AGENT_ID=520
---
2019-11-22T00:10:44.1741938Z BUILD_SOURCEBRANCHNAME=auto
2019-11-22T00:10:44.1742005Z BUILD_SOURCESDIRECTORY=D:\a\1\s
2019-11-22T00:10:44.1742068Z BUILD_SOURCEVERSION=ae731e69b0e519dbf73d4a870a82224b778808de
2019-11-22T00:10:44.1742142Z BUILD_SOURCEVERSIONAUTHOR=bors
2019-11-22T00:10:44.1742230Z BUILD_SOURCEVERSIONMESSAGE=Auto merge of #66282 - Centril:simplify-try, r=oli-obk
2019-11-22T00:10:44.1742473Z CI_JOB_NAME=x86_64-msvc-cargo
2019-11-22T00:10:44.1742526Z COBERTURA_HOME=C:\cobertura-2.1.1
2019-11-22T00:10:44.1742657Z COMMONPROGRAMFILES=C:\Program Files\Common Files
2019-11-22T00:10:44.1742722Z COMMON_TESTRESULTSDIRECTORY=D:\a\1\TestResults
---
2019-11-22T00:10:44.1746232Z HOMEPATH=\Users\VssAdministrator
2019-11-22T00:10:44.1746312Z IEWebDriver=C:\SeleniumWebDrivers\IEDriver
2019-11-22T00:10:44.1746369Z INPUT_ARGUMENTS=
2019-11-22T00:10:44.1748921Z ImageVersion=20191028.1
2019-11-22T00:10:44.1749288Z It should be noted however that the desugaring of `?` includes a function call and so the first pass in this PR relies on inlining to substitute that function call for identity on `x`. Inlining requires `mir-opt-level=2` so this might not have any effect in perf-bot but let's find out.
2019-11-22T00:10:44.1749792Z JAVA_HOME_11_X64=C:\Program Files\Java\zulu-11-azure-jdk_11.33.15-11.0.4-win_x64
2019-11-22T00:10:44.1749876Z JAVA_HOME_7_X64=C:\Program Files\Java\zulu-7-azure-jdk_7.31.0.5-7.0.232-win_x64
2019-11-22T00:10:44.1749972Z JAVA_HOME_8_X64=C:\Program Files\Java\zulu-8-azure-jdk_8.40.0.25-8.0.222-win_x64
2019-11-22T00:10:44.1750060Z LOCALAPPDATA=C:\Users\VssAdministrator\AppData\Local
---
2019-11-22T00:10:44.1790457Z TMP=/tmp
2019-11-22T00:10:44.1790526Z TOOLSTATE_ISSUES_API_URL=https://api.github.com/repos/rust-lang/rust/issues
2019-11-22T00:10:44.1790601Z TOOLSTATE_PUBLISH=1
2019-11-22T00:10:44.1790664Z TOOLSTATE_REPO=https://github.com/rust-lang-nursery/rust-toolstate
2019-11-22T00:10:44.1790759Z This PR works towards https://github.com/rust-lang/rust/issues/66234 by providing two optimization passes meant to run in sequence:
2019-11-22T00:10:44.1790845Z Together, these are meant to simplify the following into just `res`:
2019-11-22T00:10:44.1791153Z USERDOMAIN=fv-az665
2019-11-22T00:10:44.1791225Z USERDOMAIN_ROAMINGPROFILE=fv-az665
2019-11-22T00:10:44.1791297Z USERNAME=VssAdministrator
2019-11-22T00:10:44.1791353Z USERPROFILE=C:\Users\VssAdministrator
2019-11-22T00:10:44.1791353Z USERPROFILE=C:\Users\VssAdministrator
2019-11-22T00:10:44.1791431Z VCPKG_INSTALLATION_ROOT=C:\vcpkg
2019-11-22T00:10:44.1791487Z VCVARS_BAT=vcvars64.bat
2019-11-22T00:10:44.1791566Z VS140COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\
2019-11-22T00:10:44.1791634Z VSTS_AGENT_PERFLOG=c:\vsts\perflog
2019-11-22T00:10:44.1791717Z VSTS_PROCESS_LOOKUP_ID=vsts_2d5c59f1-62fe-4ead-a819-c4591a3bcde2
2019-11-22T00:10:44.1791794Z WINDIR=C:\windows
2019-11-22T00:10:44.1791852Z WIX=C:\Program Files (x86)\WiX Toolset v3.11\
2019-11-22T00:10:44.1791934Z [mir-opt] asking `?`s in a more optimized fashion
2019-11-22T00:10:44.1792059Z ```
2019-11-22T00:10:44.1792104Z ```rust
2019-11-22T00:10:44.1792166Z agent.jobstatus=Succeeded
2019-11-22T00:10:44.1792219Z match res {
2019-11-22T00:10:44.1792219Z match res {
2019-11-22T00:10:44.1792301Z r? @oli-obk -- This is WIP, but I'd appreciate feedback. :)
2019-11-22T00:10:44.1792438Z 
2019-11-22T00:10:44.1796114Z disk usage:
2019-11-22T00:10:44.2281915Z Filesystem            Size  Used Avail Use% Mounted on
2019-11-22T00:10:44.2282059Z C:/Program Files/Git  256G  140G  116G  55% /
---
2019-11-22T00:10:55.3411300Z  30  480M   30  146M    0     0  22.1M      0  0:00:21  0:00:06  0:00:15 22.3M
2019-11-22T00:10:56.7898963Z  36  480M   36  173M    0     0  22.7M      0  0:00:21  0:00:07  0:00:14 23.3M
2019-11-22T00:10:56.8221928Z  38  480M   38  186M    0     0  20.6M      0  0:00:23  0:00:09  0:00:14 20.1M
2019-11-22T00:10:56.8249797Z  39  480M   39  187M    0     0  20.6M      0  0:00:23  0:00:09  0:00:14 20.0M
2019-11-22T00:10:56.8250879Z curl: (56) OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054
2019-11-22T00:10:56.8271581Z 
2019-11-22T00:10:56.8271869Z gzip: stdin: unexpected end of file
2019-11-22T00:10:56.8277445Z tar: Unexpected EOF in archive
2019-11-22T00:10:56.8277542Z tar: Unexpected EOF in archive
2019-11-22T00:10:56.8277621Z tar: Error is not recoverable: exiting now
2019-11-22T00:10:56.8334979Z 
2019-11-22T00:10:56.8412459Z ##[error]Bash exited with code '2'.
2019-11-22T00:10:56.8597332Z ##[section]Starting: Checkout
2019-11-22T00:10:56.8693690Z ==============================================================================
2019-11-22T00:10:56.8693798Z Task         : Get sources
2019-11-22T00:10:56.8693864Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Nov 22, 2019

💔 Test failed - checks-azure

@Centril

This comment has been minimized.

Copy link
Member Author

Centril commented Nov 22, 2019

@bors retry spurious

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Nov 22, 2019

⌛️ Testing commit 2f00e86 with merge abd6955...

bors added a commit that referenced this pull request Nov 22, 2019
[mir-opt] asking `?`s in a more optimized fashion

This PR works towards #66234 by providing two optimization passes meant to run in sequence:

- `SimplifyArmIdentity` which transforms something like:
  ```rust
  _LOCAL_TMP = ((_LOCAL_1 as Variant ).FIELD: TY );
  ((_LOCAL_0 as Variant).FIELD: TY) = move _LOCAL_TMP;
  discriminant(_LOCAL_0) = VAR_IDX;
  ```

  into:

  ```rust
  _LOCAL_0 = move _LOCAL_1
  ```

- `SimplifyBranchSame` which transforms `SwitchInt`s to identical basic blocks into a `goto` to the first reachable target.

Together, these are meant to simplify the following into just `res`:
```rust
match res {
    Ok(x) => Ok(x),
    Err(x) => Err(x),
}
```

It should be noted however that the desugaring of `?` includes a function call and so the first pass in this PR relies on inlining to substitute that function call for identity on `x`. Inlining requires `mir-opt-level=2` so this might not have any effect in perf-bot but let's find out.

r? @oli-obk -- This is WIP, but I'd appreciate feedback. :)
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Nov 22, 2019

☀️ Test successful - checks-azure
Approved by: oli-obk
Pushing abd6955 to master...

@bors bors added the merged-by-bors label Nov 22, 2019
@bors bors merged commit 2f00e86 into rust-lang:master Nov 22, 2019
5 checks passed
5 checks passed
homu Test successful
Details
pr #20191121.35 succeeded
Details
pr (Linux mingw-check) Linux mingw-check succeeded
Details
pr (Linux x86_64-gnu-llvm-6.0) Linux x86_64-gnu-llvm-6.0 succeeded
Details
pr (Linux x86_64-gnu-tools) Linux x86_64-gnu-tools succeeded
Details
@Centril Centril deleted the Centril:simplify-try branch Nov 22, 2019
@Dylan-DPC

This comment has been minimized.

Copy link
Member

Dylan-DPC commented Nov 28, 2019

@oli-obk sorry wrong pr 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants
You can’t perform that action at this time.