]> Cypherpunks.ru repositories - gostls13.git/commit
[release-branch.go1.20] 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:44:00 +0000 (13:44 +0000)
commit0684cecad5b9c22e7a5a44fbe93c35e56144946c
tree2afb76f5cc1d854f869f4b805c2e61508d77e03e
parentecf7e00db8b8f5fff622f232bd8c515814c2ecc6
[release-branch.go1.20] 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 #59374

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>
(cherry picked from commit b3bc8620f89153fddc1a30ee17c1d93654ed4314)
Reviewed-on: https://go-review.googlesource.com/c/go/+/483176
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]