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

Optimize scalar and scalar pair representations loaded from ByRef in llvm #111768

Merged
merged 2 commits into from
May 30, 2023

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented May 19, 2023

in #105653 I noticed that we were generating suboptimal LLVM IR if we had a ConstValue::ByRef that could be represented by a ScalarPair. Before #105653 this is probably rare, but after it, every slice will go down this suboptimal code path that requires LLVM to untangle a bunch of indirections and translate static allocations that are only used once to read a scalar pair from.

@rustbot
Copy link
Collaborator

rustbot commented May 19, 2023

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @TaKO8Ki (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 19, 2023
@rustbot
Copy link
Collaborator

rustbot commented May 19, 2023

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo

@oli-obk
Copy link
Contributor Author

oli-obk commented May 19, 2023

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 19, 2023
@bors
Copy link
Contributor

bors commented May 19, 2023

⌛ Trying commit 0fe02e65f275e3c8c042fd79a2a62d226328d57a with merge 5ee8ee5de1f637859b1e46db36149f8db2f6d377...

@bors
Copy link
Contributor

bors commented May 19, 2023

☀️ Try build successful - checks-actions
Build commit: 5ee8ee5de1f637859b1e46db36149f8db2f6d377 (5ee8ee5de1f637859b1e46db36149f8db2f6d377)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (5ee8ee5de1f637859b1e46db36149f8db2f6d377): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
4.8% [4.8%, 4.8%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.0% [-0.0%, -0.0%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.4% [-0.0%, 4.8%] 2

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.0% [-0.1%, -0.0%] 42
Improvements ✅
(secondary)
-0.0% [-0.0%, -0.0%] 4
All ❌✅ (primary) -0.0% [-0.1%, -0.0%] 42

Bootstrap: 643.295s -> 642.362s (-0.15%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 19, 2023
Copy link
Contributor

@cjgillot cjgillot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a codegen test?

compiler/rustc_codegen_llvm/src/builder.rs Outdated Show resolved Hide resolved
compiler/rustc_codegen_gcc/src/builder.rs Outdated Show resolved Hide resolved
compiler/rustc_codegen_llvm/src/builder.rs Outdated Show resolved Hide resolved
@rustbot
Copy link
Collaborator

rustbot commented May 26, 2023

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo

@oli-obk
Copy link
Contributor Author

oli-obk commented May 26, 2023

Addressed all review comments and added a codegen test (before the commit that changes things, so you can see the behaviour change to the test on the second commit)

@cjgillot
Copy link
Contributor

Thanks.

Should we eventually have a ConstValue::ScalarPair, or does that go against the design you are aiming for?

In the mean time:
@bors r+

@bors
Copy link
Contributor

bors commented May 28, 2023

📌 Commit 164d041 has been approved by cjgillot

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 28, 2023
@bors
Copy link
Contributor

bors commented May 28, 2023

⌛ Testing commit 164d041 with merge 658227491b895be301efb45e70e2844021ab7421...

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-mingw-1 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
failures:

---- [rustdoc] tests\rustdoc\inline_cross\trait-vis.rs stdout ----

error: rustdoc failed!
status: exit code: 0xc00000fd
command: PATH="C:\a\rust\rust\build\x86_64-pc-windows-gnu\stage2\bin;C:\a\rust\rust\build\x86_64-pc-windows-gnu\stage0-bootstrap-tools\x86_64-pc-windows-gnu\release\deps;C:\a\rust\rust\build\x86_64-pc-windows-gnu\stage0\bin;C:\a\rust\rust\ninja;C:\a\rust\rust\mingw64\bin;C:\hostedtoolcache\windows\Python\3.11.3\x64\Scripts;C:\hostedtoolcache\windows\Python\3.11.3\x64;C:\msys64\usr\bin;C:\a\rust\rust\sccache;C:\Program Files\MongoDB\Server\5.0\bin;C:\aliyun-cli;C:\vcpkg;C:\cf-cli;C:\Program Files (x86)\NSIS;C:\tools\zstd;C:\Program Files\Mercurial;C:\hostedtoolcache\windows\stack\2.9.3\x64;C:\cabal\bin;C:\ghcup\bin;C:\Program Files\dotnet;C:\mysql\bin;C:\Program Files\R\R-4.3.0\bin\x64;C:\SeleniumWebDrivers\GeckoDriver;C:\Program Files (x86)\sbt\bin;C:\Program Files (x86)\GitHub CLI;C:\Program Files\Git\bin;C:\Program Files (x86)\pipx_bin;C:\npm\prefix;C:\hostedtoolcache\windows\go\1.20.3\x64\bin;C:\hostedtoolcache\windows\Python\3.7.9\x64\Scripts;C:\hostedtoolcache\windows\Python\3.7.9\x64;C:\hostedtoolcache\windows\Ruby\2.5.9\x64\bin;C:\Program Files\OpenSSL\bin;C:\tools\kotlinc\bin;C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\8.0.372-7\x64\bin;C:\Program Files\ImageMagick-7.1.1-Q16-HDRI;C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin;C:\ProgramData\kind;C:\Program Files\Eclipse Foundation\jdk-8.0.302.8-hotspot\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\ProgramData\Chocolatey\bin;C:\Program Files\PowerShell\7;C:\Program Files\Microsoft\Web Platform Installer;C:\Program Files\Microsoft SQL Server\130\Tools\Binn;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\160\DTS\Binn;C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;C:\ProgramData\chocolatey\lib\pulumi\tools\Pulumi\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files\CMake\bin;C:\ProgramData\chocolatey\lib\maven\apache-maven-3.8.7\bin;C:\Program Files\Microsoft Service Fabric\bin\Fabric\Fabric.Code;C:\Program Files\Microsoft SDKs\Service Fabric\Tools\ServiceFabricLocalClusterManager;C:\Program Files\nodejs;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Program Files\GitHub CLI;C:\tools\php;C:\Program Files (x86)\sbt\bin;C:\SeleniumWebDrivers\ChromeDriver;C:\SeleniumWebDrivers\EdgeDriver;C:\Program Files\Amazon\AWSCLIV2;C:\Program Files\Amazon\SessionManagerPlugin\bin;C:\Program Files\Amazon\AWSSAMCLI\bin;C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin;C:\Program Files (x86)\Microsoft BizTalk Server;C:\Program Files\LLVM\bin;C:\Users\runneradmin\.dotnet\tools;C:\Users\runneradmin\.cargo\bin;C:\Users\runneradmin\AppData\Local\Microsoft\WindowsApps" "C:\\a\\rust\\rust\\build\\x86_64-pc-windows-gnu\\stage2\\bin\\rustdoc.exe" "-L" "C:\\a\\rust\\rust\\build\\x86_64-pc-windows-gnu\\stage2\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-L" "C:\\a\\rust\\rust\\build\\x86_64-pc-windows-gnu\\test\\rustdoc\\inline_cross\\trait-vis\\auxiliary" "-o" "C:\\a\\rust\\rust\\build\\x86_64-pc-windows-gnu\\test\\rustdoc\\inline_cross\\trait-vis" "--deny" "warnings" "C:\\a\\rust\\rust\\tests\\rustdoc\\inline_cross\\trait-vis.rs"
stdout: none
thread 'main' has overflowed its stack
------------------------------------------


---
test result: FAILED. 616 passed; 1 failed; 6 ignored; 0 measured; 0 filtered out; finished in 106.62s

Some tests failed in compiletest suite=rustdoc mode=rustdoc host=x86_64-pc-windows-gnu target=x86_64-pc-windows-gnu
Build completed unsuccessfully in 0:48:32
make: *** [Makefile:78: ci-mingw-subset-1] Error 1

@bors
Copy link
Contributor

bors commented May 28, 2023

💔 Test failed - checks-actions

@bors bors removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label May 28, 2023
@bors bors added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 28, 2023
@oli-obk
Copy link
Contributor Author

oli-obk commented May 30, 2023

Should we eventually have a ConstValue::ScalarPair, or does that go against the design you are aiming for?

I'm trying to remove that, and instead just rely on ByRef if we can get acceptable performance this way

@oli-obk
Copy link
Contributor Author

oli-obk commented May 30, 2023

@bors retry windows rustdoc stack overflow

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 30, 2023
@bors
Copy link
Contributor

bors commented May 30, 2023

⌛ Testing commit 164d041 with merge 3266c36...

@bors
Copy link
Contributor

bors commented May 30, 2023

☀️ Test successful - checks-actions
Approved by: cjgillot
Pushing 3266c36 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 30, 2023
@bors bors merged commit 3266c36 into rust-lang:master May 30, 2023
@rustbot rustbot added this to the 1.72.0 milestone May 30, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (3266c36): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.2% [2.2%, 2.2%] 1
Improvements ✅
(primary)
-0.1% [-0.1%, -0.1%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.1% [-0.1%, -0.1%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.0% [-0.1%, -0.0%] 42
Improvements ✅
(secondary)
-0.0% [-0.0%, -0.0%] 4
All ❌✅ (primary) -0.0% [-0.1%, -0.0%] 42

Bootstrap: 642.797s -> 643.826s (0.16%)

@oli-obk oli-obk deleted the pair_const_llvm branch May 30, 2023 16:03
bors added a commit to rust-lang-ci/rust that referenced this pull request May 31, 2023
Only rewrite valtree-constants to patterns and keep other constants opaque

Now that we can reliably fall back to comparing constants with `PartialEq::eq` to the match scrutinee, we can

1. eagerly try to convert constants to valtrees
2. then deeply convert the valtree to a pattern
3. if the to-valtree conversion failed, create an "opaque constant" pattern.

This PR specifically avoids any behavioral changes or major cleanups. What we can now do as follow ups is

* move the two remaining call sites to `destructure_mir_constant` off that query
* make valtree to pattern conversion infallible
    * this needs to be done after careful analysis of the effects. There may be user visible changes from that.

based on rust-lang#111768
antoyo pushed a commit to antoyo/rust that referenced this pull request Jun 19, 2023
Optimize scalar and scalar pair representations loaded from ByRef in llvm

in rust-lang#105653 I noticed that we were generating suboptimal LLVM IR if we had a `ConstValue::ByRef` that could be represented by a `ScalarPair`. Before rust-lang#105653 this is probably rare, but after it, every slice will go down this suboptimal code path that requires LLVM to untangle a bunch of indirections and translate static allocations that are only used once to read a scalar pair from.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants