-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Fix wrong constant folding for bswap16 #67726
Conversation
The semantics of bswap16 is currently to swap the lower 2 bytes and leave the upper bytes alone. We need to keep the same behavior when constant folding or we can quickly end up discarding necessary casts. Fix dotnet#67723
Hmm, in fact on ARM64 we emit |
Tagging subscribers to this area: @JulieLeeMSFT Issue DetailsThe semantics of bswap16 is currently to swap the lower 2 bytes and Fix #67723 cc @dotnet/jit-contrib @aromaa
|
I've pushed a commit that disables constant folding for |
Small number of diffs. There are a few occurrences, but many of the diffs are duplicates of the same functions. |
A few other solutions come to mind if we want to continue to be able to constant fold:
|
Currently the JIT's constant folding (gtFoldExprConst and VNs EvalOpSpecialized) assumes that BSWAP16 zero extends into the upper 16 bits. This was not the case, and in fact the behavior of BSWAP16 depended on platform. Normally this would not be a problem since we always insert normalizing casts when creating BSWAP16 nodes, however VN was smart enough to remove this cast in some cases (see the test). Change the semantics of BSWAP16 nodes to zero extend into the upper 16 bits to match constant folding, and add a small peephole to avoid inserting this normalization in the common case where it is not necessary. Fixes dotnet#67723 Subsumes dotnet#67726
Subsumed by #67903 which implements bullet 3 above instead. |
Currently the JIT's constant folding (gtFoldExprConst and VNs EvalOpSpecialized) assumes that BSWAP16 zero extends into the upper 16 bits. This was not the case, and in fact the behavior of BSWAP16 depended on platform. Normally this would not be a problem since we always insert normalizing casts when creating BSWAP16 nodes, however VN was smart enough to remove this cast in some cases (see the test). Change the semantics of BSWAP16 nodes to zero extend into the upper 16 bits to match constant folding, and add a small peephole to avoid inserting this normalization in the common case where it is not necessary. Fixes #67723 Subsumes #67726
Currently the JIT's constant folding (gtFoldExprConst and VNs EvalOpSpecialized) assumes that BSWAP16 zero extends into the upper 16 bits. This was not the case, and in fact the behavior of BSWAP16 depended on platform. Normally this would not be a problem since we always insert normalizing casts when creating BSWAP16 nodes, however VN was smart enough to remove this cast in some cases (see the test). Change the semantics of BSWAP16 nodes to zero extend into the upper 16 bits to match constant folding, and add a small peephole to avoid inserting this normalization in the common case where it is not necessary. Fixes dotnet#67723 Subsumes dotnet#67726
bswap16
currently usesrev16
on ARM architectures andror <16 bit reg>, 8
on xarch. The behavior of these are not the same so consider the upper 16 bits to be undefined and disable constant folding of these.Fix #67723
cc @dotnet/jit-contrib @aromaa