-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add unchecked_disjoint_bitor
per ACP373
#135760
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f230253
Add `unchecked_disjoint_bitor` with fallback intrinsic implementation
scottmcm 4ee1602
Override `disjoint_or` in the LLVM backend
scottmcm 61150a8
PR feedback
scottmcm 5e6ae8b
More PR feedback
scottmcm f46e6be
Handle the case where the `or disjoint` folds immediately to a constant
scottmcm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#![feature(core_intrinsics)] | ||
fn main() { | ||
// one bit in common | ||
unsafe { std::intrinsics::disjoint_bitor(0b01101001_u8, 0b10001110) }; //~ ERROR: Undefined Behavior | ||
} |
15 changes: 15 additions & 0 deletions
15
src/tools/miri/tests/fail/intrinsics/disjoint_bitor.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error: Undefined Behavior: `assume` called with `false` | ||
--> tests/fail/intrinsics/disjoint_bitor.rs:LL:CC | ||
| | ||
LL | unsafe { std::intrinsics::disjoint_bitor(0b01101001_u8, 0b10001110) }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `assume` called with `false` | ||
| | ||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior | ||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information | ||
= note: BACKTRACE: | ||
= note: inside `main` at tests/fail/intrinsics/disjoint_bitor.rs:LL:CC | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to 1 previous error | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//@ compile-flags: -C opt-level=3 | ||
|
||
#![crate_type = "lib"] | ||
#![feature(bigint_helper_methods)] | ||
|
||
// CHECK-LABEL: @u32_carrying_add | ||
#[no_mangle] | ||
pub fn u32_carrying_add(a: u32, b: u32, c: bool) -> (u32, bool) { | ||
// CHECK: @llvm.uadd.with.overflow.i32 | ||
// CHECK: @llvm.uadd.with.overflow.i32 | ||
// CHECK: or disjoint i1 | ||
u32::carrying_add(a, b, c) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//@ compile-flags: -C no-prepopulate-passes -Z mir-opt-level=0 | ||
|
||
#![crate_type = "lib"] | ||
#![feature(core_intrinsics)] | ||
|
||
use std::intrinsics::disjoint_bitor; | ||
|
||
// CHECK-LABEL: @disjoint_bitor_signed | ||
#[no_mangle] | ||
pub unsafe fn disjoint_bitor_signed(x: i32, y: i32) -> i32 { | ||
// CHECK: or disjoint i32 %x, %y | ||
disjoint_bitor(x, y) | ||
} | ||
|
||
// CHECK-LABEL: @disjoint_bitor_unsigned | ||
#[no_mangle] | ||
pub unsafe fn disjoint_bitor_unsigned(x: u64, y: u64) -> u64 { | ||
// CHECK: or disjoint i64 %x, %y | ||
disjoint_bitor(x, y) | ||
} | ||
|
||
// CHECK-LABEL: @disjoint_bitor_literal | ||
#[no_mangle] | ||
pub unsafe fn disjoint_bitor_literal() -> u8 { | ||
// This is a separate check because even without any passes, | ||
// LLVM will fold so it's not an instruction, which can assert in LLVM. | ||
|
||
// CHECK: store i8 3 | ||
disjoint_bitor(1, 2) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this a method and not just a normal intrinsic? Why does this have 2 default implementations? (fallback in
core
and default impl here)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that other places in cg_ssa can use it if it's helpful.
The fallback one in core is for clif and ctfe, whereas the one here is for gcc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kinda annoying that we need 2 fallbacks :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this what we do for all intrinsics that can't be implemented in cg_ssa? Isn't there some place where cg_llvm matches on the intrinsic name to provide its own impls before falling back to the cg_ssa one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could do that, it just feels like a worse fit here.
This isn't like these intrinsics
rust/compiler/rustc_codegen_llvm/src/intrinsic.rs
Lines 29 to 154 in a30f915
where we're lowering it to some call, or the ones depending on LLVM-only integer types, or whatever.
It's far more like
add nuw
, where we haveadd
,unchecked_sadd
, andunchecked_uadd
onBuilderMethods
, because it's an instruction in the IR and something that we can use in other places in MIR-to-Backend lowering. (For example, we could use it in emitting rotates since we might as well and it's no less safe than the shifts that are also unchecked in the builder.)And sure, those two unchecked examples don't have defaults today, but they should, because cg_gcc is just emitting
self.gcc_add(a, b)
for all three anyway, and if we want cg_ssa to be useful it shouldn't require implementing these when there's perfectly fine -- albeit potentially suboptimal -- provided implementations.