Repository navigation
Move ub_checks() inside the const_eval_select branch. - #166136
Conversation
This looks like it shouldn't change anything, but it is a small speedup for CTFE that goes through this macro. Presumably by avoiding the MIR for the early-out `&&` entirely, it can go a little faster.
|
Any special-casing of Miri in the standard library requires review. cc @rust-lang/miri |
|
Thanks for the pull request, and welcome! The Rust Project has assigned @JohnTitor (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks. Please see the contribution instructions and our LLM policy for more information. Why was this reviewer chosen?The reviewer was selected based on:
|
|
For additional context: #t-libs > Worth having a compiler benchmark for isqrt? |
|
Odd that skipping the dead code would make a difference. Can you add a few more details about your benchmark setup and results, so that if someone has to dig through this in the future they have something to look at? |
|
[package]
name = "test_bench"
version = "0.1.0"
edition = "2024"
[profile.dev]
debug = 0
const CONST_ITERS: usize = 0x20000;
const ARR_SIZE: usize = 0x2000; // Fit in L1 cache
const MASK: usize = ARR_SIZE - 1;
pub const fn isqrt_bench(iters: usize) -> [u32; ARR_SIZE] {
let mut res: [u32; ARR_SIZE] = [1; ARR_SIZE]; // I'm changing this to force compiles
let mut n = 0;
loop {
res[n & MASK] = 0; //(n as u64).isqrt() as u32;
n += 1;
unsafe {
assert_unchecked(n > 0);
assert_unchecked(n > 0);
assert_unchecked(n > 0);
assert_unchecked(n > 0);
}
if n >= iters {
break;
}
}
res
}
#[allow(long_running_const_eval)]
pub const BENCH_ARR: [u32; ARR_SIZE] = isqrt_bench(CONST_ITERS);
It's small, but I'm pretty sure it's real - I can get the minimum of a larger number of runs if you really want to be sure. And AFAICT there's no reason not to change this - it's pretty much the same in terms of readability etc. |
Yeah I just wanted to make sure that if someone looks back at this in the future they have a better idea of what we did here. :) Thanks, LGTM! |
Move ub_checks() inside the const_eval_select branch. This looks like it shouldn't change anything, but it is a small (but measurable) speedup for CTFE that goes through this macro. Presumably by avoiding the MIR for the early-out `&&` entirely, it can go a little faster.
Move ub_checks() inside the const_eval_select branch. This looks like it shouldn't change anything, but it is a small (but measurable) speedup for CTFE that goes through this macro. Presumably by avoiding the MIR for the early-out `&&` entirely, it can go a little faster.
Move ub_checks() inside the const_eval_select branch. This looks like it shouldn't change anything, but it is a small (but measurable) speedup for CTFE that goes through this macro. Presumably by avoiding the MIR for the early-out `&&` entirely, it can go a little faster.
…uwer Rollup of 13 pull requests Successful merges: - #157721 (compiletest: Add testing for lint machinery at runtime) - #165934 (Avoid using Terminator:None in simplify_cfg) - #166117 (Remove ebadf handling from stdio) - #165094 (reflection: doc attributes from adts, fields, and variants) - #165216 (Clearer diagnostics when `&FnOnce` was provided when `FnOnce` was expected) - #165694 (view-types: make sure view types are !Sized) - #165883 (Report a recursion limit error instead of delaying a bug in RPITIT collector) - #165971 (fix: non-deterministic temporary object paths in linker maps) - #166136 (Move ub_checks() inside the const_eval_select branch.) - #166166 (Don't recover if not allowed in `parse_seq_to_before_tokens`) - #166176 (compiletest: Move all code out of the crate root) - #166185 (simd-test: Fix cfg syntax in the test macro) - #166194 (std: Unstably constify `std::process::abort`) Failed merges: - #166150 (Reflection: refactor Type and TypeKind) - #166160 (refactor CTFE-specific intrinsics to different file)
Move ub_checks() inside the const_eval_select branch. This looks like it shouldn't change anything, but it is a small (but measurable) speedup for CTFE that goes through this macro. Presumably by avoiding the MIR for the early-out `&&` entirely, it can go a little faster.
…uwer Rollup of 16 pull requests Successful merges: - #166078 (rustc_type_ir: Optimize `sub_root_lookup_table` by using `SsoHashMap`, not `HashMap`) - #165934 (Avoid using Terminator:None in simplify_cfg) - #166050 (Use attribute parser for lang attributes in `LateResolutionVisitor`) - #166117 (Remove ebadf handling from stdio) - #166119 (Avoid an ICE on re-exports of private imports without a DefId) - #165094 (reflection: doc attributes from adts, fields, and variants) - #165216 (Clearer diagnostics when `&FnOnce` was provided when `FnOnce` was expected) - #165694 (view-types: make sure view types are !Sized) - #165883 (Report a recursion limit error instead of delaying a bug in RPITIT collector) - #165971 (fix: non-deterministic temporary object paths in linker maps) - #166064 (Add const generic transmute min support) - #166136 (Move ub_checks() inside the const_eval_select branch.) - #166166 (Don't recover if not allowed in `parse_seq_to_before_tokens`) - #166176 (compiletest: Move all code out of the crate root) - #166185 (simd-test: Fix cfg syntax in the test macro) - #166194 (std: Unstably constify `std::process::abort`) Failed merges: - #166150 (Reflection: refactor Type and TypeKind) - #166160 (refactor CTFE-specific intrinsics to different file)
Move ub_checks() inside the const_eval_select branch. This looks like it shouldn't change anything, but it is a small (but measurable) speedup for CTFE that goes through this macro. Presumably by avoiding the MIR for the early-out `&&` entirely, it can go a little faster.
Rollup of 21 pull requests Successful merges: - #165707 (bootstrap: Make low priority the default) - #165716 (Refactor split_block in check_pointers to avoid Terminator: None) - #165934 (Avoid using Terminator:None in simplify_cfg) - #166050 (Use attribute parser for lang attributes in `LateResolutionVisitor`) - #166069 (bootstrap: fix keep-stage-std) - #166117 (Remove ebadf handling from stdio) - #166119 (Avoid an ICE on re-exports of private imports without a DefId) - #165094 (reflection: doc attributes from adts, fields, and variants) - #165216 (Clearer diagnostics when `&FnOnce` was provided when `FnOnce` was expected) - #165694 (view-types: make sure view types are !Sized) - #165802 (Add CI workflow to publish backtrace after a push to main) - #165883 (Report a recursion limit error instead of delaying a bug in RPITIT collector) - #165906 (fix ICE when a forced keyword follows a parameter pattern) - #166064 (Add const generic transmute min support) - #166136 (Move ub_checks() inside the const_eval_select branch.) - #166158 (bump some tools' `toml` dependency) - #166166 (Don't recover if not allowed in `parse_seq_to_before_tokens`) - #166176 (compiletest: Move all code out of the crate root) - #166185 (simd-test: Fix cfg syntax in the test macro) - #166194 (std: Unstably constify `std::process::abort`) - #166210 (Avoid terminator: None in insert_direct_enum_check) Failed merges: - #166150 (Reflection: refactor Type and TypeKind) - #166160 (refactor CTFE-specific intrinsics to different file)
Rollup of 20 pull requests Successful merges: - #165716 (Refactor split_block in check_pointers to avoid Terminator: None) - #165934 (Avoid using Terminator:None in simplify_cfg) - #166050 (Use attribute parser for lang attributes in `LateResolutionVisitor`) - #166069 (bootstrap: fix keep-stage-std) - #166117 (Remove ebadf handling from stdio) - #166119 (Avoid an ICE on re-exports of private imports without a DefId) - #165094 (reflection: doc attributes from adts, fields, and variants) - #165216 (Clearer diagnostics when `&FnOnce` was provided when `FnOnce` was expected) - #165694 (view-types: make sure view types are !Sized) - #165802 (Add CI workflow to publish backtrace after a push to main) - #165883 (Report a recursion limit error instead of delaying a bug in RPITIT collector) - #165906 (fix ICE when a forced keyword follows a parameter pattern) - #166064 (Add const generic transmute min support) - #166136 (Move ub_checks() inside the const_eval_select branch.) - #166158 (bump some tools' `toml` dependency) - #166166 (Don't recover if not allowed in `parse_seq_to_before_tokens`) - #166176 (compiletest: Move all code out of the crate root) - #166185 (simd-test: Fix cfg syntax in the test macro) - #166194 (std: Unstably constify `std::process::abort`) - #166210 (Avoid terminator: None in insert_direct_enum_check) Failed merges: - #166150 (Reflection: refactor Type and TypeKind) - #166160 (refactor CTFE-specific intrinsics to different file)
Rollup merge of #166136 - d0sboots:assert_ub, r=RalfJung Move ub_checks() inside the const_eval_select branch. This looks like it shouldn't change anything, but it is a small (but measurable) speedup for CTFE that goes through this macro. Presumably by avoiding the MIR for the early-out `&&` entirely, it can go a little faster.
Rollup of 20 pull requests Successful merges: - rust-lang/rust#165716 (Refactor split_block in check_pointers to avoid Terminator: None) - rust-lang/rust#165934 (Avoid using Terminator:None in simplify_cfg) - rust-lang/rust#166050 (Use attribute parser for lang attributes in `LateResolutionVisitor`) - rust-lang/rust#166069 (bootstrap: fix keep-stage-std) - rust-lang/rust#166117 (Remove ebadf handling from stdio) - rust-lang/rust#166119 (Avoid an ICE on re-exports of private imports without a DefId) - rust-lang/rust#165094 (reflection: doc attributes from adts, fields, and variants) - rust-lang/rust#165216 (Clearer diagnostics when `&FnOnce` was provided when `FnOnce` was expected) - rust-lang/rust#165694 (view-types: make sure view types are !Sized) - rust-lang/rust#165802 (Add CI workflow to publish backtrace after a push to main) - rust-lang/rust#165883 (Report a recursion limit error instead of delaying a bug in RPITIT collector) - rust-lang/rust#165906 (fix ICE when a forced keyword follows a parameter pattern) - rust-lang/rust#166064 (Add const generic transmute min support) - rust-lang/rust#166136 (Move ub_checks() inside the const_eval_select branch.) - rust-lang/rust#166158 (bump some tools' `toml` dependency) - rust-lang/rust#166166 (Don't recover if not allowed in `parse_seq_to_before_tokens`) - rust-lang/rust#166176 (compiletest: Move all code out of the crate root) - rust-lang/rust#166185 (simd-test: Fix cfg syntax in the test macro) - rust-lang/rust#166194 (std: Unstably constify `std::process::abort`) - rust-lang/rust#166210 (Avoid terminator: None in insert_direct_enum_check) Failed merges: - rust-lang/rust#166150 (Reflection: refactor Type and TypeKind) - rust-lang/rust#166160 (refactor CTFE-specific intrinsics to different file)
This looks like it shouldn't change anything, but it is a small (but measurable) speedup for CTFE that goes through this macro. Presumably by avoiding the MIR for the early-out
&&entirely, it can go a little faster.