mirror of
https://github.com/golang/go
synced 2024-11-22 04:24:39 -07:00
cmd/compile: improve unneeded zeroing removal
After newobject, we don't need to write zeroes to initialize the object. It has already been zeroed by the allocator. This is already handled in most cases, but because we run builtin decomposition after the opt pass, we don't handle cases where the zero of a compound builtin is being written. Improve the zero detector to handle those cases. Fixes #68845 Change-Id: If3dde2e304a05e5a6a6723565191d5444b334bcc Reviewed-on: https://go-review.googlesource.com/c/go/+/605255 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Auto-Submit: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org>
This commit is contained in:
parent
8b32ce586d
commit
b2cdaf7346
@ -1221,6 +1221,12 @@ func isConstZero(v *Value) bool {
|
||||
return true
|
||||
case OpConst64, OpConst32, OpConst16, OpConst8, OpConstBool, OpConst32F, OpConst64F:
|
||||
return v.AuxInt == 0
|
||||
case OpStringMake, OpIMake, OpComplexMake:
|
||||
return isConstZero(v.Args[0]) && isConstZero(v.Args[1])
|
||||
case OpSliceMake:
|
||||
return isConstZero(v.Args[0]) && isConstZero(v.Args[1]) && isConstZero(v.Args[2])
|
||||
case OpStringPtr, OpStringLen, OpSlicePtr, OpSliceLen, OpSliceCap, OpITab, OpIData, OpComplexReal, OpComplexImag:
|
||||
return isConstZero(v.Args[0])
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
52
test/codegen/issue68845.go
Normal file
52
test/codegen/issue68845.go
Normal file
@ -0,0 +1,52 @@
|
||||
// asmcheck
|
||||
|
||||
// Copyright 2024 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 codegen
|
||||
|
||||
type T1 struct {
|
||||
x string
|
||||
}
|
||||
|
||||
func f1() *T1 {
|
||||
// amd64:-`MOVQ\s[$]0`,-`MOVUPS\sX15`
|
||||
return &T1{}
|
||||
}
|
||||
|
||||
type T2 struct {
|
||||
x, y string
|
||||
}
|
||||
|
||||
func f2() *T2 {
|
||||
// amd64:-`MOVQ\s[$]0`,-`MOVUPS\sX15`
|
||||
return &T2{}
|
||||
}
|
||||
|
||||
type T3 struct {
|
||||
x complex128
|
||||
}
|
||||
|
||||
func f3() *T3 {
|
||||
// amd64:-`MOVQ\s[$]0`,-`MOVUPS\sX15`
|
||||
return &T3{}
|
||||
}
|
||||
|
||||
type T4 struct {
|
||||
x []byte
|
||||
}
|
||||
|
||||
func f4() *T4 {
|
||||
// amd64:-`MOVQ\s[$]0`,-`MOVUPS\sX15`
|
||||
return &T4{}
|
||||
}
|
||||
|
||||
type T5 struct {
|
||||
x any
|
||||
}
|
||||
|
||||
func f5() *T5 {
|
||||
// amd64:-`MOVQ\s[$]0`,-`MOVUPS\sX15`
|
||||
return &T5{}
|
||||
}
|
Loading…
Reference in New Issue
Block a user