]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.19] cmd/compile: use correct type for byteswaps on multi-byte...
authorKeith Randall <khr@golang.org>
Sat, 1 Apr 2023 17:33:26 +0000 (10:33 -0700)
committerGopher Robot <gobot@golang.org>
Mon, 24 Apr 2023 13:43:33 +0000 (13:43 +0000)
commitca9947db78f4dd37052e163850ed23e8c47d7e21
tree5a522a6f37be6cd6d88fabe092db5d890e3bec8c
parent130a7f8e8d5d3ecb7f17a741cc18e96f134fc38a
[release-branch.go1.19] cmd/compile: use correct type for byteswaps on multi-byte stores

Use the type of the store for the byteswap, not the type of the
store's value argument.

Normally when we're storing a 16-bit value, the value being stored is
also typed as 16 bits. But sometimes it is typed as something smaller,
usually because it is the result of an upcast from a smaller value,
and that upcast needs no instructions.

If the type of the store's arg is thinner than the type being stored,
and the byteswap'd value uses that thinner type, and the byteswap'd
value needs to be spilled & restored, that spill/restore happens using
the thinner type, which causes us to lose some of the top bits of the
value.

Fixes #59373

Change-Id: If6ce1e8a76f18bf8e9d79871b6caa438bc3cce4d
Reviewed-on: https://go-review.googlesource.com/c/go/+/481395
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-on: https://go-review.googlesource.com/c/go/+/483177
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
src/cmd/compile/internal/ssa/gen/AMD64.rules
src/cmd/compile/internal/ssa/gen/ARM64.rules
src/cmd/compile/internal/ssa/rewriteAMD64.go
src/cmd/compile/internal/ssa/rewriteARM64.go
test/fixedbugs/issue59367.go [new file with mode: 0644]