Replacement of #114390: Add new intrinsic is_var_statically_known and optimize pow for powers of two#119911
Conversation
|
(rustbot has picked a reviewer for you, use r? to override) |
|
r? @oli-obk |
|
|
is_var_statically_known and optimize pow for powers of twois_var_statically_known and optimize pow for powers of two
|
@oli-obk Should I be at all concerned about GCC and Cranelift? |
|
The Miri subtree was changed cc @rust-lang/miri |
|
Converted back to draft so I can add support in GCC and a fallback in Cranelift. |
|
The other backends can just return |
Do they have to enforce correct types? For LLVM, Centri left a FIXME note essentially saying she was only allowing a finite amount of types as inputs because she had to explicitly declare each of them. I don't have that issue with Cranelift because it isn't backed by a real intrinsic anyway. Do I have to tell Cranelift to panic when it gets an argument that LLVM can't accept? Edit: they do not |
This comment has been minimized.
This comment has been minimized.
|
Force undoing that commit. |
931b069 to
cdc2f08
Compare
|
Since I don't want to put tmi in the core docs and the intrinsic is a too unstable for formal documentation, I'll try to put info about it in this PR. The rustc front-end (MIR passes) never attempts to resolve the intrinsic to true or false; it leaves it for the backend. The exception of course is in |
oli-obk
left a comment
There was a problem hiding this comment.
codegen_gcc also still needs to handle the intrinsic
509dc03 to
61faffb
Compare
3f6531c to
7f35252
Compare
|
When I next get the chance, I need to edit pow et al to better take advantage of constant propagation, then edit the codegen tests to match. After that, I will mark it as ready for review. While |
|
Now both codegen tests have |
|
@bors r+ rollup=never |
|
☀️ Test successful - checks-actions |
|
Finished benchmarking commit (039d887): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesResultsThis 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.
Binary sizeResultsThis 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.
Bootstrap: 662.082s -> 661.843s (-0.04%) |
| /// unsafe { | ||
| /// if !is_val_statically_known(0) { unreachable_unchecked(); } | ||
| /// } | ||
| /// ``` |
There was a problem hiding this comment.
Tests that have UB should be marked as no_run... this one is now tripping Miri, of course.
I'll file a PR.
…li-obk Replacement of rust-lang#114390: Add new intrinsic `is_var_statically_known` and optimize pow for powers of two This adds a new intrinsic `is_val_statically_known` that lowers to [``@llvm.is.constant.*`](https://llvm.org/docs/LangRef.html#llvm-is-constant-intrinsic).` It also applies the intrinsic in the int_pow methods to recognize and optimize the idiom `2isize.pow(x)`. See rust-lang#114390 for more discussion. While I have extended the scope of the power of two optimization from rust-lang#114390, I haven't added any new uses for the intrinsic. That can be done in later pull requests. Note: When testing or using the library, be sure to use `--stage 1` or higher. Otherwise, the intrinsic will be a noop and the doctests will be skipped. If you are trying out edits, you may be interested in [`--keep-stage 0`](https://rustc-dev-guide.rust-lang.org/building/suggested.html#faster-builds-with---keep-stage). Fixes rust-lang#47234 Resolves rust-lang#114390 `@Centri3`
…r=cuviper mark a doctest with UB as no_run rust-lang#119911 added a doctest with UB. That one shouldn't be run, or else Miri will complain.
Rollup merge of rust-lang#120366 - RalfJung:is_val_statically_known, r=cuviper mark a doctest with UB as no_run rust-lang#119911 added a doctest with UB. That one shouldn't be run, or else Miri will complain.
Revert unsound libcore changes fixes rust-lang#120537 these were introduced in rust-lang#119911
Rollup merge of rust-lang#120562 - oli-obk:revert_stuff, r=cuviper Revert unsound libcore changes fixes rust-lang#120537 these were introduced in rust-lang#119911
(cherry picked from commit 6ac035d)
|
@NCGThompson I tried using this new intrinsic with |
I think so. I'll have to look at #121001 more before I give you a precise answer, but there is a general trick for detecting a rare special case. let a: bool = evaluateCondition();
if is_val_statically_known(a) && a {
handleSpecialCase();
} else {
handleGeneralCase();
}Note that If I understand your code correctly, |
|
Thanks @NCGThompson ! It turns out i could reuse an existing function that returns |
…li-obk Replacement of rust-lang#114390: Add new intrinsic `is_var_statically_known` and optimize pow for powers of two This adds a new intrinsic `is_val_statically_known` that lowers to [``@llvm.is.constant.*`](https://llvm.org/docs/LangRef.html#llvm-is-constant-intrinsic).` It also applies the intrinsic in the int_pow methods to recognize and optimize the idiom `2isize.pow(x)`. See rust-lang#114390 for more discussion. While I have extended the scope of the power of two optimization from rust-lang#114390, I haven't added any new uses for the intrinsic. That can be done in later pull requests. Note: When testing or using the library, be sure to use `--stage 1` or higher. Otherwise, the intrinsic will be a noop and the doctests will be skipped. If you are trying out edits, you may be interested in [`--keep-stage 0`](https://rustc-dev-guide.rust-lang.org/building/suggested.html#faster-builds-with---keep-stage). Fixes rust-lang#47234 Resolves rust-lang#114390 `@Centri3`
This adds a new intrinsic
is_val_statically_knownthat lowers to@llvm.is.constant.*. It also applies the intrinsic in the int_pow methods to recognize and optimize the idiom2isize.pow(x). See #114390 for more discussion.While I have extended the scope of the power of two optimization from #114390, I haven't added any new uses for the intrinsic. That can be done in later pull requests.
Note: When testing or using the library, be sure to use
--stage 1or higher. Otherwise, the intrinsic will be a noop and the doctests will be skipped. If you are trying out edits, you may be interested in--keep-stage 0.Fixes #47234
Resolves #114390
@Centri3