]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: use correct type for byteswaps on multi-byte stores
authorKeith Randall <khr@golang.org>
Sat, 1 Apr 2023 17:33:26 +0000 (10:33 -0700)
committerKeith Randall <khr@golang.org>
Fri, 7 Apr 2023 21:11:29 +0000 (21:11 +0000)
commitb3bc8620f89153fddc1a30ee17c1d93654ed4314
tree91c4be3c269f891516537236f93f049533ce104d
parent42866e566a4586d7a39758c7186fbcc4678ec97d
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 #59367

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>
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]