Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Optimize integral pattern matching #65089
Conversation
This reduces the number of call sites for `constructor_intersects_pattern()` from two to one, which the next commit will take advantage of.
This is a 2% instruction count win on `unicode_normalization-check-clean`.
This commit moves a lot of code around but doesn't change functionality at all. The main goal was for `from_pat()` to no longer call `from_ctor()`. The increase in inlining resulted in less function call overhead, for a 3% instruction count win on `unicode_normalization-check-clean`.
The `if let Some(val) = value.try_eval_bits(...)` branch in `from_const()` is very hot for the `unicode_normalization` benchmark. This commit introduces a special-case alternative for scalars that avoids `try_eval_bits()` and all the functions it calls (`Const::eval()`, `ConstValue::try_to_bits()`, `ConstValue::try_to_scalar()`, and `Scalar::to_bits()`), instead extracting the result immediately. The type and value checking done by `Scalar::to_bits()` is replicated by moving it into a new function `Scalar::check_raw()` and using that new function in the special case. PR #64673 introduced some special-case handling of scalar types in `Const::try_eval_bits()`. This handling is now moved out of that function into the new `IntRange::integral_size_and_signed_bias` function. This commit reduces the instruction count for `unicode_normalization-check-clean` by about 10%.
`filter_map()` is less general, but more efficient, and has the same effect in this case. This commit reduces the instruction count for `unicode_normalization-check-clean` by about 2%.
|
Changes look good to me; they're all just shuffling code around so we can probably land this without additional review, but cc @oli-obk |
|
r? @varkor |
|
oops; r? @Mark-Simulacrum but cc @varkor :) |
|
@bors r+ rollup=never since perf |
|
|
…, r=Mark-Simulacrum Optimize integral pattern matching Various improvements to integral pattern matching. Together they reduce instruction counts for `unicode_normalization-check-clean` by about 16%. r? @Mark-Simulacrum
|
|
This reverses changes from rust-lang#65089, but I need this temporarily for rebase to be tractable.
This reverses changes from rust-lang#65089, but I need this temporarily for rebase to be tractable.
| Integer::from_attr(&tcx, UnsignedInt(uty)).size() | ||
| } | ||
| _ => tcx.layout_of(param_env.with_reveal_all().and(ty)).ok()?.size, | ||
| }; |
RalfJung
Oct 12, 2019
•
Member
A quick grep shows a few more sites that call layout_of just to get the size or alignment (and there's likely more but split across multiple lines). So it might still be worth having size_and_align_of(Ty<'tcx>) somewhere with an optimization like this -- maybe?
A quick grep shows a few more sites that call layout_of just to get the size or alignment (and there's likely more but split across multiple lines). So it might still be worth having size_and_align_of(Ty<'tcx>) somewhere with an optimization like this -- maybe?
oli-obk
Oct 18, 2019
Contributor
yea, this could just be a method on TyCtxt
yea, this could just be a method on TyCtxt
This reverses changes from rust-lang#65089, but I need this temporarily for rebase to be tractable.
This reverses changes from rust-lang#65089, but I need this temporarily for rebase to be tractable.
Various improvements to integral pattern matching. Together they reduce instruction counts for
unicode_normalization-check-cleanby about 16%.r? @Mark-Simulacrum