Fatalf("walkrange")
case TARRAY, TSLICE:
- if memclrrange(n, v1, v2, a) {
+ if arrayClear(n, v1, v2, a) {
lineno = lno
return n
}
// in which the evaluation of a is side-effect-free.
//
// Parameters are as in walkrange: "for v1, v2 = range a".
-func memclrrange(n, v1, v2, a *Node) bool {
+func arrayClear(n, v1, v2, a *Node) bool {
if Debug['N'] != 0 || instrumenting {
return false
}
+
if v1 == nil || v2 != nil {
return false
}
- if n.Nbody.Len() == 0 || n.Nbody.First() == nil || n.Nbody.Len() > 1 {
+
+ if n.Nbody.Len() != 1 || n.Nbody.First() == nil {
return false
}
+
stmt := n.Nbody.First() // only stmt in body
if stmt.Op != OAS || stmt.Left.Op != OINDEX {
return false
}
+
if !samesafeexpr(stmt.Left.Left, a) || !samesafeexpr(stmt.Left.Right, v1) {
return false
}
+
elemsize := n.Type.Elem().Width
if elemsize <= 0 || !isZero(stmt.Right) {
return false
--- /dev/null
+// asmcheck
+
+// Copyright 2018 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
+
+// This file contains code generation tests related to the handling of
+// slice types.
+
+// ------------------ //
+// Clear //
+// ------------------ //
+
+// Issue #5373 optimize memset idiom
+
+func SliceClear(s []int) []int {
+ // amd64:`.*memclrNoHeapPointers`
+ for i := range s {
+ s[i] = 0
+ }
+ return s
+}
+
+func SliceClearPointers(s []*int) []*int {
+ // amd64:`.*memclrHasPointers`
+ for i := range s {
+ s[i] = nil
+ }
+ return s
+}