This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Set alignment to 1 for SIMD memory intrinsics
ClosedPublic

Authored by tlively on May 4 2021, 1:10 PM.

Details

Summary

The WebAssembly SIMD intrinsics in wasm_simd128.h generally try not to require
any particular alignment for memory operations to be maximally flexible. For
builtin memory access functions and their corresponding LLVM IR intrinsics,
there's no way to set the expected alignment, so the best we can do is set the
alignment to 1 in the backend. This change means that the alignment hints in the
emitted code will no longer be incorrect when users use the intrinsics to access
unaligned data.

Diff Detail

Event Timeline

tlively created this revision.May 4 2021, 1:10 PM
tlively requested review of this revision.May 4 2021, 1:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 4 2021, 1:10 PM

Sorry I'm not sure if I understand. The "expected alignment" for all those memory instructions is 1, regardless of the size of the element of the vectors? Can you elaborate on why the previous code is incorrect?

Sorry I'm not sure if I understand. The "expected alignment" for all those memory instructions is 1, regardless of the size of the element of the vectors? Can you elaborate on why the previous code is incorrect?

Users of the SIMD intrinsic header functions (and therefore the clang builtins (and therefore the LLVM intrinsics)) for these instructions should be able to pass pointers to arbitrary unaligned data. In the backend, we won't know what the alignment of the data is, so we need to conservatively say that it is 1. Previously, if users used those intrinsics with unaligned data, the alignment hint emitted into the binary would be wrong because it would be too big.

aheejin accepted this revision.May 5 2021, 12:47 AM

Thanks for the explanation!

This revision is now accepted and ready to land.May 5 2021, 12:47 AM
This revision was landed with ongoing or failed builds.May 5 2021, 11:59 AM
This revision was automatically updated to reflect the committed changes.