-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Operand::extract_field: only cast llval if it's a pointer and replace bitcast w/ pointercast. #105583
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
Operand::extract_field: only cast llval if it's a pointer and replace bitcast w/ pointercast. #105583
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
48af94c
Operand::extract_field: only cast llval if it's a pointer and replace…
luqmana 75f3faf
Add test.
luqmana af69cc0
Make test more targeted.
luqmana 6a5ee11
Don't bitcast aggregate field.
luqmana 2942121
Update test location.
luqmana 7b1eeda
Switch test back to run-pass.
luqmana c7c042a
Address review comments.
luqmana 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// run-pass | ||
// compile-flags: -O -Zverify-llvm-ir | ||
|
||
#![feature(repr_simd)] | ||
#![feature(platform_intrinsics)] | ||
|
||
#[allow(non_camel_case_types)] | ||
#[derive(Clone, Copy)] | ||
#[repr(simd)] | ||
struct i32x4([i32; 4]); | ||
|
||
extern "platform-intrinsic" { | ||
pub(crate) fn simd_add<T>(x: T, y: T) -> T; | ||
} | ||
|
||
#[inline(always)] | ||
fn to_array(a: i32x4) -> [i32; 4] { | ||
a.0 | ||
} | ||
|
||
fn main() { | ||
let a = i32x4([1, 2, 3, 4]); | ||
let b = unsafe { simd_add(a, a) }; | ||
assert_eq!(to_array(b), [2, 4, 6, 8]); | ||
} |
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.
This removes the illegal
bitcast <4 x i32> to [4 x i32]
, which is good--but it doesn't replace that illegal conversion with a legal one, so we end up returning a value of type<4 x i32>
when extracting a field of type[4 x i32]
.The repro example happens to work anyways because the next instruction is a store, and both
store <4 x i32>
andstore [4 x i32]
have the same effect. But it won't work if we use that value by value. (This may never happen, because I don't think we ever pass LLVM array types by value, but it's technically incorrect.)To handle this fully, I think you'd have to special-case this kind of newtype field extraction (self
Abi::Vector
, fieldAbi::Aggregate
) and roundtrip the vector through memory (alloca,store <4 x i32>
,load [4 x i32]
).(I thought there might be endianness concerns, but it seems like that's only a problem for not-a-multiple-of-i8 types like i4)
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.
Good point! Split out the case for newtype of simd array