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

Add an assume that the index is inbounds to slice::get_unchecked #116915

Merged
merged 1 commit into from
Dec 4, 2023

Conversation

bend-n
Copy link
Contributor

@bend-n bend-n commented Oct 19, 2023

Fixes #116878

@rustbot
Copy link
Collaborator

rustbot commented Oct 19, 2023

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @m-ou-se (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-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 19, 2023
@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Oct 19, 2023

The Miri subtree was changed

cc @rust-lang/miri

@rust-log-analyzer

This comment has been minimized.

@bend-n bend-n force-pushed the unwet branch 3 times, most recently from 78efff4 to a70548d Compare October 19, 2023 02:24
@saethlin
Copy link
Member

@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 Oct 19, 2023
@bors
Copy link
Contributor

bors commented Oct 19, 2023

⌛ Trying commit a70548d with merge f9b6f93...

bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 19, 2023
Use `.get().unwrap()` in `[T]::get_unchecked`

Fixes rust-lang#116878
@bors
Copy link
Contributor

bors commented Oct 19, 2023

☀️ Try build successful - checks-actions
Build commit: f9b6f93 (f9b6f93d10d9dcce9f75a6899e8190142489c18c)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f9b6f93): comparison URL.

Overall result: ❌ regressions - 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.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

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

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.8% [0.3%, 4.5%] 14
Regressions ❌
(secondary)
0.6% [0.5%, 0.8%] 4
Improvements ✅
(primary)
-0.9% [-1.5%, -0.4%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.4% [-1.5%, 4.5%] 16

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)
7.9% [3.8%, 15.1%] 3
Regressions ❌
(secondary)
2.7% [2.7%, 2.7%] 1
Improvements ✅
(primary)
-5.6% [-9.6%, -2.3%] 4
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [-9.6%, 15.1%] 7

Cycles

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)
2.3% [0.6%, 3.7%] 8
Regressions ❌
(secondary)
1.4% [0.8%, 2.0%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.3% [0.6%, 3.7%] 8

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.2% [0.0%, 1.1%] 39
Regressions ❌
(secondary)
0.4% [0.4%, 0.6%] 3
Improvements ✅
(primary)
-0.2% [-0.6%, -0.0%] 8
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [-0.6%, 1.1%] 47

Bootstrap: 628.777s -> 629.685s (0.14%)
Artifact size: 304.01 MiB -> 303.95 MiB (-0.02%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Oct 19, 2023
@oli-obk
Copy link
Contributor

oli-obk commented Oct 19, 2023

looks like the large regression is in LLVM, probably due to more optimizations triggering?

@Noratrieb
Copy link
Member

probably due to more optimizations triggering?

could also just be the additional work of the extra abstractions

@saethlin
Copy link
Member

saethlin commented Oct 19, 2023

The increased complexity of the optimized MIR backs up that conclusion: https://godbolt.org/z/Kned9hxx6

I strongly suspect an implementation with assume would look better in perf and produce the same optimizations, because LLVM eventually manages to optimzie the .get().unwrap_unchecked() into an assume: https://godbolt.org/z/WTPnrcejs

@bend-n
Copy link
Contributor Author

bend-n commented Oct 19, 2023

Im trying it with the unwrap_unchecked in SliceIndex<usize>::get_unchecked, then we can try a assume? Just to have more to compare with?

@saethlin
Copy link
Member

There's no harm in trying all the ideas, especially when the perf queue isn't very busy :)

@saethlin
Copy link
Member

@bors try @rust-timer queue

@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 Dec 3, 2023
@bors
Copy link
Contributor

bors commented Dec 4, 2023

⌛ Testing commit 73afc00 with merge f6794ae...

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 4, 2023
Add an assume that the index is inbounds to slice::get_unchecked

Fixes rust-lang#116878
@rust-log-analyzer
Copy link
Collaborator

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

Click to see the possible cause of the failure (guessed by this bot)
To only update this specific test, also pass `--test-args panics\default-backtrace-ice.rs`

error: 1 errors occurred comparing output.
status: exit code: 101
command: PATH="C:\a\rust\rust\build\i686-pc-windows-gnu\stage2\bin;C:\a\rust\rust\build\i686-pc-windows-gnu\stage0-bootstrap-tools\i686-pc-windows-gnu\release\deps;C:\a\rust\rust\build\i686-pc-windows-gnu\stage0\bin;C:\a\rust\rust\ninja;C:\a\rust\rust\mingw32\bin;C:\hostedtoolcache\windows\Python\3.12.0\x64\Scripts;C:\hostedtoolcache\windows\Python\3.12.0\x64;C:\msys64\usr\bin;C:\a\rust\rust\sccache;C:\PROGRA~1\MongoDB\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.13.1\x64;C:\cabal\bin;C:\ghcup\bin;C:\mingw64\bin;C:\Program Files\dotnet;C:\Program Files\MySQL\MySQL Server 5.7\bin;C:\Program Files\R\R-4.3.2\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.11\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.392-8\x64\bin;C:\Program Files\ImageMagick-7.1.1-Q16-HDRI;C:\Program Files\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\\i686-pc-windows-gnu\\stage2\\bin\\rustc.exe" "C:\\a\\rust\\rust\\tests\\ui\\panics\\default-backtrace-ice.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=C:\\Users\\runneradmin\\.cargo" "--sysroot" "C:\\a\\rust\\rust\\build\\i686-pc-windows-gnu\\stage2" "--target=i686-pc-windows-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "C:\\a\\rust\\rust\\build\\i686-pc-windows-gnu\\test\\ui\\panics\\default-backtrace-ice" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=C:\\a\\rust\\rust\\build\\i686-pc-windows-gnu\\native\\rust-test-helpers" "-L" "C:\\a\\rust\\rust\\build\\i686-pc-windows-gnu\\test\\ui\\panics\\default-backtrace-ice\\auxiliary" "-Z" "treat-err-as-bug=1"
--- stderr -------------------------------
error[E0425]: cannot find value `missing_ident` in this scope
##[error]  --> C:\a\rust\rust\tests\ui\panics\default-backtrace-ice.rs:21:13
   |
   |
LL | fn main() { missing_ident; }

thread 'rustc' panicked at compiler\rustc_errors\src\lib.rs:1730:30:
thread 'rustc' panicked at compiler\rustc_errors\src\lib.rs:1730:30:
aborting due to `-Z treat-err-as-bug=1`
   0: 0x663b5410 - core::fmt::write::he46a474224f67d7f
   1: 0x663561a4 - std::io::Write::write_fmt::hcc64fb856ccde36f
   2: 0x6635f700 - std::sys_common::backtrace::print::h7c9624195f1e6d30
   3: 0x66362a17 - std::panicking::default_hook::{{closure}}::h890019c097577bd6
   3: 0x66362a17 - std::panicking::default_hook::{{closure}}::h890019c097577bd6
   4: 0x66362728 - std::panicking::default_hook::hbaa41e7c1211b32a
   5: 0x66d983eb - <std[926929f0519811c2]::panicking::default_hook as core[28778fbd931658f5]::ops::function::Fn<(&core[28778fbd931658f5]::panic::panic_info::PanicInfo,)>>::call
   6: 0x66d9587c - std[926929f0519811c2]::panicking::update_hook::<alloc[2c4bed620ca4f1f8]::boxed::Box<rustc_driver_impl[f6a0976a4cadf1f6]::install_ice_hook::{closure#0}>>::{closure#0}
   8: 0x66362fd8 - std::panicking::begin_panic_handler::{{closure}}::ha6d81991e8846646
   9: 0x663605d8 - std::sys_common::backtrace::__rust_end_short_backtrace::h092da2069f308371
  10: 0x66362d6a - _rust_begin_unwind
  11: 0x663b155f - core::panicking::panic_fmt::hc16a3e8321a69ae9
  11: 0x663b155f - core::panicking::panic_fmt::hc16a3e8321a69ae9
  12: 0x6a1b12d7 - <rustc_errors[aa0364c77b758c9a]::HandlerInner>::panic_if_treat_err_as_bug
  13: 0x6a1b0230 - <rustc_errors[aa0364c77b758c9a]::HandlerInner>::emit_diagnostic::{closure#2}
  14: 0x66fe9d9c - rustc_interface[33430d5200e04826]::callbacks::track_diagnostic
  15: 0x6a1af5a8 - <rustc_errors[aa0364c77b758c9a]::HandlerInner>::emit_diagnostic
  16: 0x6a1ae39b - <rustc_errors[aa0364c77b758c9a]::Handler>::emit_diagnostic
  17: 0x6a20cd95 - <rustc_span[b2143aff58e6fda6]::ErrorGuaranteed as rustc_errors[aa0364c77b758c9a]::diagnostic_builder::EmissionGuarantee>::diagnostic_builder_emit_producing_guarantee
  18: 0x68036dc5 - <rustc_resolve[9182386d567aa601]::Resolver>::report_errors
  19: 0x68178def - <rustc_session[fde8ec27dde01124]::session::Session>::time::<(), <rustc_resolve[9182386d567aa601]::Resolver>::resolve_crate::{closure#0}>
  20: 0x6806b991 - <rustc_resolve[9182386d567aa601]::Resolver>::resolve_crate
  21: 0x66fb8cf0 - rustc_interface[33430d5200e04826]::passes::resolver_for_lowering
  22: 0x6899b8f5 - rustc_query_impl[95a39b312168677d]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[95a39b312168677d]::query_impl::resolver_for_lowering::dynamic_query::{closure#2}::{closure#0}, rustc_middle[10b026d73847a4fb]::query::erase::Erased<[u8; 4usize]>>
  23: 0x68c42cc2 - <rustc_query_impl[95a39b312168677d]::query_impl::resolver_for_lowering::dynamic_query::{closure#2} as core[28778fbd931658f5]::ops::function::FnOnce<(rustc_middle[10b026d73847a4fb]::ty::context::TyCtxt, ())>>::call_once
  24: 0x68d6f761 - rustc_query_system[aa1e0c93a45da258]::query::plumbing::try_execute_query::<rustc_query_impl[95a39b312168677d]::DynamicConfig<rustc_query_system[aa1e0c93a45da258]::query::caches::SingleCache<rustc_middle[10b026d73847a4fb]::query::erase::Erased<[u8; 4usize]>>, false, false, false>, rustc_query_impl[95a39b312168677d]::plumbing::QueryCtxt, false>
  25: 0x68b1406b - rustc_query_impl[95a39b312168677d]::query_impl::resolver_for_lowering::get_query_non_incr::__rust_end_short_backtrace
  26: 0x66cfe85c - <rustc_middle[10b026d73847a4fb]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[f6a0976a4cadf1f6]::run_compiler::{closure#0}::{closure#0}::{closure#2}, &rustc_data_structures[1374b8256b20595e]::steal::Steal<(rustc_middle[10b026d73847a4fb]::ty::ResolverAstLowering, alloc[2c4bed620ca4f1f8]::sync::Arc<rustc_ast[c0655c41cd0f375d]::ast::Crate>)>>
  27: 0x66cf0d45 - <rustc_interface[33430d5200e04826]::queries::QueryResult<&rustc_middle[10b026d73847a4fb]::ty::context::GlobalCtxt>>::enter::<&rustc_data_structures[1374b8256b20595e]::steal::Steal<(rustc_middle[10b026d73847a4fb]::ty::ResolverAstLowering, alloc[2c4bed620ca4f1f8]::sync::Arc<rustc_ast[c0655c41cd0f375d]::ast::Crate>)>, rustc_driver_impl[f6a0976a4cadf1f6]::run_compiler::{closure#0}::{closure#0}::{closure#2}>
  28: 0x66d4ed46 - <rustc_interface[33430d5200e04826]::interface::Compiler>::enter::<rustc_driver_impl[f6a0976a4cadf1f6]::run_compiler::{closure#0}::{closure#0}, core[28778fbd931658f5]::result::Result<core[28778fbd931658f5]::option::Option<rustc_interface[33430d5200e04826]::queries::Linker>, rustc_span[b2143aff58e6fda6]::ErrorGuaranteed>>
  29: 0x66d88fa7 - rustc_span[b2143aff58e6fda6]::set_source_map::<core[28778fbd931658f5]::result::Result<(), rustc_span[b2143aff58e6fda6]::ErrorGuaranteed>, rustc_interface[33430d5200e04826]::interface::run_compiler<core[28778fbd931658f5]::result::Result<(), rustc_span[b2143aff58e6fda6]::ErrorGuaranteed>, rustc_driver_impl[f6a0976a4cadf1f6]::run_compiler::{closure#0}>::{closure#0}::{closure#0}>
  30: 0x66d6f89e - <scoped_tls[e12af43c358f6dc]::ScopedKey<rustc_span[b2143aff58e6fda6]::SessionGlobals>>::set::<rustc_interface[33430d5200e04826]::util::run_in_thread_pool_with_globals<rustc_interface[33430d5200e04826]::interface::run_compiler<core[28778fbd931658f5]::result::Result<(), rustc_span[b2143aff58e6fda6]::ErrorGuaranteed>, rustc_driver_impl[f6a0976a4cadf1f6]::run_compiler::{closure#0}>::{closure#0}, core[28778fbd931658f5]::result::Result<(), rustc_span[b2143aff58e6fda6]::ErrorGuaranteed>>::{closure#0}, core[28778fbd931658f5]::result::Result<(), rustc_span[b2143aff58e6fda6]::ErrorGuaranteed>>
  31:   0x1750c8 - <unknown>
  32: 0x66d78d59 - <<std[926929f0519811c2]::thread::Builder>::spawn_unchecked_<rustc_interface[33430d5200e04826]::util::run_in_thread_with_globals<rustc_interface[33430d5200e04826]::util::run_in_thread_pool_with_globals<rustc_interface[33430d5200e04826]::interface::run_compiler<core[28778fbd931658f5]::result::Result<(), rustc_span[b2143aff58e6fda6]::ErrorGuaranteed>, rustc_driver_impl[f6a0976a4cadf1f6]::run_compiler::{closure#0}>::{closure#0}, core[28778fbd931658f5]::result::Result<(), rustc_span[b2143aff58e6fda6]::ErrorGuaranteed>>::{closure#0}, core[28778fbd931658f5]::result::Result<(), rustc_span[b2143aff58e6fda6]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[28778fbd931658f5]::result::Result<(), rustc_span[b2143aff58e6fda6]::ErrorGuaranteed>>::{closure#1} as core[28778fbd931658f5]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  33: 0x663755dd - __ZN3std3sys7windows6thread6Thread3new12thread_start17ha0bd64702895dc62E@4
  34: 0x767b05c9 - <unknown>
  35: 0x77eb78bd - <unknown>
  36: 0x77eb788d - <unknown>
error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md


note: rustc 1.76.0-nightly (f6794aebb 2023-12-04) running on i686-pc-windows-gnu

note: compiler flags: -Z threads=1 -Z simulate-remapped-rust-src-base=/rustc/FAKE_PREFIX -Z translate-remapped-path-to-local-path=no -Z ignore-directory-in-diagnostics-source-blocks=C:\Users\runneradmin\.cargo -C codegen-units=1 -Z ui-testing -Z deduplicate-diagnostics=no -Z write-long-types-to-disk=no -C strip=debuginfo -C prefer-dynamic -C rpath -C debuginfo=0 -Z treat-err-as-bug=1
query stack during panic:
#0 [resolver_for_lowering] getting the resolver for lowering
end of query stack
------------------------------------------

@bors
Copy link
Contributor

bors commented Dec 4, 2023

💔 Test failed - checks-actions

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

saethlin commented Dec 4, 2023

#116759
@bors retry

@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 Dec 4, 2023
@bors
Copy link
Contributor

bors commented Dec 4, 2023

⌛ Testing commit 73afc00 with merge 85a4bd8...

@bors
Copy link
Contributor

bors commented Dec 4, 2023

☀️ Test successful - checks-actions
Approved by: saethlin
Pushing 85a4bd8 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 4, 2023
@bors bors merged commit 85a4bd8 into rust-lang:master Dec 4, 2023
12 checks passed
@rustbot rustbot added this to the 1.76.0 milestone Dec 4, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (85a4bd8): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.5% [0.3%, 4.5%] 10
Regressions ❌
(secondary)
0.4% [0.3%, 0.6%] 3
Improvements ✅
(primary)
-0.5% [-0.5%, -0.5%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.2% [-0.5%, 4.5%] 11

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.2% [0.2%, 14.1%] 8
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-3.3% [-3.7%, -2.3%] 4
Improvements ✅
(secondary)
-2.4% [-3.5%, -0.6%] 3
All ❌✅ (primary) 1.7% [-3.7%, 14.1%] 12

Cycles

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)
2.6% [0.8%, 4.2%] 9
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.8% [-1.8%, -1.8%] 1
All ❌✅ (primary) 2.6% [0.8%, 4.2%] 9

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.1% [0.0%, 0.4%] 41
Regressions ❌
(secondary)
0.1% [0.1%, 0.1%] 3
Improvements ✅
(primary)
-0.2% [-0.5%, -0.0%] 8
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [-0.5%, 0.4%] 49

Bootstrap: 672.824s -> 673.692s (0.13%)
Artifact size: 314.12 MiB -> 314.13 MiB (0.00%)

@bend-n bend-n deleted the unwet branch December 4, 2023 07:10
@nnethercote
Copy link
Contributor

@saethlin: are the binary size regression expected? They seem surprising to me, given that this change was intended to produce more streamlined code :/

@bend-n
Copy link
Contributor Author

bend-n commented Dec 4, 2023

Presumably more optimized code.

@saethlin
Copy link
Member

saethlin commented Dec 5, 2023

The fact that ripgrep leads the linked_artifact regressions and that the largest icount regressions are in regex makes me think that whatever happened, regex is a good example.

The top of the cachegrind diff for regex opt-full is:

196,187,152  ???:llvm::ScalarEvolution::isLoopBackedgeGuardedByCond(llvm::Loop const*, llvm::CmpInst::Predicate, llvm::SCEV const*, llvm::SCEV const*) 
177,396,685  ???:llvm::ScalarEvolution::isBasicBlockEntryGuardedByCond(llvm::BasicBlock const*, llvm::CmpInst::Predicate, llvm::SCEV const*, llvm::SCEV const*) 
144,664,351  ???:llvm::computeKnownBitsFromAssume(llvm::Value const*, llvm::KnownBits&, unsigned int, llvm::SimplifyQuery const&)
101,443,164  ???:llvm::ScalarEvolution::isImpliedCond(llvm::CmpInst::Predicate, llvm::SCEV const*, llvm::SCEV const*, llvm::Value const*, bool, llvm::Instruction const*) 

Which at least suggests that some of the increased icount in LLVM is processing the assumes. Whether it's helping is less clear.

Just doing an rg panic_bounds_check target/release/deps/ --count on builds of regex-1.10.2 (latest release) before and after this PR indicates that we went from:

target/release/deps/memchr-d2bb6823209e6c4b.ll:66
target/release/deps/aho_corasick-dee4e7528de2347a.ll:888
target/release/deps/regex_syntax-cbe8289811e12031.ll:98
target/release/deps/regex_automata-16ffd8f27578710f.ll:1420

To

target/release/deps/memchr-d2bb6823209e6c4b.ll:66
target/release/deps/aho_corasick-dee4e7528de2347a.ll:888
target/release/deps/regex_syntax-cbe8289811e12031.ll:98
target/release/deps/regex_automata-16ffd8f27578710f.ll:1404

Hardly a massive win, but the change does suggest we optimized out some panics that used to be in there.

But grepping for call or invoke suggests that there were a lot of changes. Those numbers are much larger and change in both directions.

So I have two guesses:

  1. LLVM has done some optimization using the assume and that induced further inlining.
  2. MIR inlining doesn't ignore assumes in its cost estimation. I don't think it can fully ignore them, because the cost of adding an assume is not just the assume itself, but whatever statements are required to produce its predicate. Maybe with SSA you easily back out what statements were used to compute the predicate and ignore those but MIR does not make this easy so I'm going to try just ignoring assumes in MIR inlining and see what happens to perf: Ignore intrinsics::assume in MIR inlining cost estimation #118626. If we get the inverse of the perf reports here that would be interesting, but my most realistic expectation is that we get nothing.

@rylev
Copy link
Member

rylev commented Dec 5, 2023

@bend-n @saethlin do we have proof that this optimization actually makes a positive impact on compiled code? The impact on regex is large enough that it makes me wonder if we should revert and figure out a path forward before moving forward with this. Thoughts?

@saethlin
Copy link
Member

saethlin commented Dec 5, 2023

We have a codegen test in this PR that verifies that it helps

celinval added a commit to tautschnig/kani that referenced this pull request Dec 8, 2023
- Use internal to go around is_foreign_item() issue
- Update tests after an issue:
  rust-lang/rust#116915
- Update the toolchain
celinval added a commit to model-checking/kani that referenced this pull request Dec 8, 2023
Changes required due to:
- rust-lang/rust@99ac405b96 Move MetadataLoader{,Dyn} to rustc_metadata.
- rust-lang/rust@c997c6d822 Add more information to stable Instance
- rust-lang/rust#116915

This also fixes an issue in the `simd_shuffle` implementation that was exposed by the update.

Resolves #2911

---------

Co-authored-by: Celina G. Val <[email protected]>
Co-authored-by: Adrian Palacios <[email protected]>
@@ -233,7 +233,10 @@ unsafe impl<T> SliceIndex<[T]> for usize {
// cannot be longer than `isize::MAX`. They also guarantee that
// `self` is in bounds of `slice` so `self` cannot overflow an `isize`,
// so the call to `add` is safe.
unsafe { slice.as_ptr().add(self) }
unsafe {
crate::intrinsics::assume(self < slice.len());
Copy link
Member

Choose a reason for hiding this comment

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

Something I just noticed here: why is there an assume in get_unchecked, but not in get_unchecked_mut below?

Copy link
Member

Choose a reason for hiding this comment

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

I couldn't figure out how to justify the compile-time regression: #120762

Copy link
Member

Choose a reason for hiding this comment

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

Actually it seems there's a pretty robust effect on the size of libstd.so that I just didn't notice before. Hunh.

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. perf-regression Performance regression. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missed optimization with slice::get_unchecked followed by <slice as Index>::index at a lower index