-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Revert "store ScalarPair via memset when one side is undef and the other side can be memset" #137894
Merged
Merged
Revert "store ScalarPair via memset when one side is undef and the other side can be memset" #137894
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -2,8 +2,6 @@ | |
|
||
#![crate_type = "lib"] | ||
|
||
use std::mem::MaybeUninit; | ||
|
||
// CHECK-LABEL: @zero_sized_elem | ||
#[no_mangle] | ||
pub fn zero_sized_elem() { | ||
|
@@ -78,64 +76,31 @@ pub fn u16_init_one_bytes() -> [u16; N] { | |
[const { u16::from_be_bytes([1, 1]) }; N] | ||
} | ||
|
||
// FIXME: undef bytes can just be initialized with the same value as the | ||
// defined bytes, if the defines bytes are all the same. | ||
// CHECK-LABEL: @option_none_init | ||
#[no_mangle] | ||
pub fn option_none_init() -> [Option<u8>; N] { | ||
// CHECK-NOT: select | ||
// CHECK-NOT: br | ||
// CHECK-NOT: switch | ||
// CHECK-NOT: icmp | ||
// CHECK: call void @llvm.memset.p0 | ||
[const { None }; N] | ||
} | ||
|
||
// If there is partial provenance or some bytes are initialized and some are not, | ||
// we can't really do better than initialize bytes or groups of bytes together. | ||
// CHECK-LABEL: @option_maybe_uninit_init | ||
#[no_mangle] | ||
pub fn option_maybe_uninit_init() -> [MaybeUninit<u16>; N] { | ||
// CHECK-NOT: select | ||
// CHECK: br label %repeat_loop_header{{.*}} | ||
// CHECK-NOT: switch | ||
// CHECK: icmp | ||
// CHECK-NOT: call void @llvm.memset.p0 | ||
[const { | ||
let mut val: MaybeUninit<u16> = MaybeUninit::uninit(); | ||
let ptr = val.as_mut_ptr() as *mut u8; | ||
unsafe { | ||
ptr.write(0); | ||
} | ||
val | ||
}; N] | ||
[None; N] | ||
} | ||
|
||
#[repr(packed)] | ||
struct Packed { | ||
start: u8, | ||
ptr: &'static (), | ||
rest: u16, | ||
rest2: u8, | ||
} | ||
use std::mem::MaybeUninit; | ||
|
||
// If there is partial provenance or some bytes are initialized and some are not, | ||
// we can't really do better than initialize bytes or groups of bytes together. | ||
// CHECK-LABEL: @option_maybe_uninit_provenance | ||
// FIXME: This could be optimized into a memset. | ||
// Regression test for <https://github.com/rust-lang/rust/issues/137892>. | ||
#[no_mangle] | ||
pub fn option_maybe_uninit_provenance() -> [MaybeUninit<Packed>; N] { | ||
pub fn half_uninit() -> [(u128, MaybeUninit<u128>); N] { | ||
// CHECK-NOT: select | ||
// CHECK: br label %repeat_loop_header{{.*}} | ||
// CHECK-NOT: switch | ||
// CHECK: icmp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I copied all this from above :clueless: |
||
// CHECK-NOT: call void @llvm.memset.p0 | ||
[const { | ||
let mut val: MaybeUninit<Packed> = MaybeUninit::uninit(); | ||
unsafe { | ||
let ptr = &raw mut (*val.as_mut_ptr()).ptr; | ||
static HAS_ADDR: () = (); | ||
ptr.write_unaligned(&HAS_ADDR); | ||
} | ||
val | ||
}; N] | ||
[const { (0, MaybeUninit::uninit()) }; N] | ||
} | ||
|
||
// Use an opaque function to prevent rustc from removing useless drops. | ||
|
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.
For future reference, on line 104:
The
try_init_all_same
tries to access a value that should be size u128, but since scalar pairs can be twice the size ofu128
it ends up indexing out of bounds.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.
This code will need to both check that the initialized half of the scalarpair is the same value, then emit another memset for the uninitialized part, and be a bit more careful to use the correct size of the value being passed into the function.