mirror of
https://github.com/golang/go
synced 2024-11-27 05:31:31 -07:00
3f04db41a8
If we have y = <int16> (MOVBQSX x) z = <int32> (MOVWQSX y) We used to use this rewrite rule: (MOVWQSX x:(MOVBQSX _)) -> x But that resulted in replacing z with a value whose type is only int16. Then if z is spilled and restored, it gets zero extended instead of sign extended. Instead use the rule (MOVWQSX (MOVBQSX x)) -> (MOVBQSX x) The result is has the correct type, so it can be spilled and restored correctly. It might mean that a few more extension ops might not be eliminated, but that's the price for correctness. Fixes #21963 Change-Id: I6ec82c3d2dbe43cc1fee6fb2bd6b3a72fca3af00 Reviewed-on: https://go-review.googlesource.com/65290 Reviewed-by: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
28 lines
483 B
Go
28 lines
483 B
Go
// run
|
|
|
|
// Copyright 2017 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime"
|
|
)
|
|
|
|
//go:noinline
|
|
func f(x []int32, y *int8) int32 {
|
|
c := int32(int16(*y))
|
|
runtime.GC()
|
|
return x[0] * c
|
|
}
|
|
|
|
func main() {
|
|
var x = [1]int32{5}
|
|
var y int8 = -1
|
|
if got, want := f(x[:], &y), int32(-5); got != want {
|
|
panic(fmt.Sprintf("wanted %d, got %d", want, got))
|
|
}
|
|
}
|