Skip to content
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

x64: Ensure that constants are always 16 bytes for XmmMem #4790

Merged
merged 6 commits into from
Aug 26, 2022

Conversation

elliottt
Copy link
Member

Ensure that constants generated for the memory case of XmmMem values are always 16 bytes, ensuring that we don't accidantally perform an unaligned load.

Fixes #4761

@elliottt elliottt marked this pull request as ready for review August 26, 2022 19:01
Copy link
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

cranelift/codegen/src/isa/x64/lower/isle.rs Outdated Show resolved Hide resolved
cranelift/codegen/src/machinst/isle.rs Outdated Show resolved Hide resolved
cranelift/codegen/src/machinst/isle.rs Outdated Show resolved Hide resolved
@@ -0,0 +1,17 @@
test run
set enable_llvm_abi_extensions
target x86_64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just run this on all architectures as well as the interpreter? The bug was x64-specific but the test should work everywhere and it would be nice to know if it didn't.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a further suggestion, we can also remove the set enable_llvm_abi_extensions since we no longer have i128's in this new minimized test case.

cranelift/codegen/src/isa/x64/lower/isle.rs Outdated Show resolved Hide resolved
@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift:area:x64 Issues related to x64 codegen isle Related to the ISLE domain-specific language labels Aug 26, 2022
@github-actions
Copy link

Subscribe to Label Action

cc @cfallin, @fitzgen

This issue or pull request has been labeled: "cranelift", "cranelift:area:machinst", "cranelift:area:x64", "isle"

Thus the following users have been cc'd because of the following labels:

  • cfallin: isle
  • fitzgen: isle

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@elliottt elliottt requested a review from cfallin August 26, 2022 19:10
@@ -806,7 +806,7 @@ macro_rules! isle_prelude_methods {

#[inline]
fn emit_u128_le_const(&mut self, value: u128) -> VCodeConstant {
let data = VCodeConstantData::Generated(value.to_le_bytes().iter().cloned().collect());
let data = VCodeConstantData::Generated(value.to_le_bytes().iter().copied().collect());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, after Chris' suggestion, now you can simplify this to value.to_le_bytes().into(), I think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess ConstantData doesn't have a From implementation for arrays, but .as_slice().into() ought to work at least.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we're stuck with my verbose monstrosity:

809 |             let data = VCodeConstantData::Generated(value.to_le_bytes().iter().into());
    |                                                                                ^^^^ the trait `From<core::slice::Iter<'_, u8>>` is not implemented for `ConstantData`

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem there is the .iter().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I get a similar error without it. I had been experimenting :)

809 |             let data = VCodeConstantData::Generated(value.to_le_bytes().into());
    |                                                                         ^^^^ the trait `From<[u8; 16]>` is not implemented for `ConstantData`

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd figured out that just .into() wouldn't work after I posted my first comment. Did you try my second suggestion, of .as_slice().into()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Totally missed your second comment, that works 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hooray! It'd probably be nice if ConstantData actually had a From<[T; n]> implementation too, but I didn't want to suggest doing that in this PR. 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift:area:x64 Issues related to x64 codegen cranelift Issues related to the Cranelift code generator isle Related to the ISLE domain-specific language
Projects
None yet
4 participants