]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/gc: handle arith ops in samesafeexpr
authorIskander Sharipov <iskander.sharipov@intel.com>
Mon, 17 Sep 2018 18:37:30 +0000 (21:37 +0300)
committerIskander Sharipov <iskander.sharipov@intel.com>
Wed, 19 Sep 2018 12:03:58 +0000 (12:03 +0000)
Teach samesafeexpr to handle arithmetic unary and binary ops.

It makes map lookup optimization possible in

m[k+1] = append(m[k+1], ...)
m[-k] = append(m[-k], ...)
... etc

Does not cover "+" for strings (concatenation).

Change-Id: Ibbb16ac3faf176958da344be1471b06d7cf33a6c
Reviewed-on: https://go-review.googlesource.com/135795
Run-TryBot: Iskander Sharipov <iskander.sharipov@intel.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/typecheck.go
test/codegen/mapaccess.go

index c2b84541852b5afabd3182e9f4c68acb95c9455e..69dced00ac729fd461f72dca5e7e615c02b77602 100644 (file)
@@ -3298,7 +3298,8 @@ func samesafeexpr(l *Node, r *Node) bool {
        case ODOT, ODOTPTR:
                return l.Sym != nil && r.Sym != nil && l.Sym == r.Sym && samesafeexpr(l.Left, r.Left)
 
-       case OIND, OCONVNOP:
+       case OIND, OCONVNOP,
+               ONOT, OCOM, OPLUS, OMINUS:
                return samesafeexpr(l.Left, r.Left)
 
        case OCONV:
@@ -3306,7 +3307,8 @@ func samesafeexpr(l *Node, r *Node) bool {
                // Allow only numeric-ish types. This is a bit conservative.
                return issimple[l.Type.Etype] && samesafeexpr(l.Left, r.Left)
 
-       case OINDEX, OINDEXMAP:
+       case OINDEX, OINDEXMAP,
+               OADD, OSUB, OOR, OXOR, OMUL, OLSH, ORSH, OAND, OANDNOT, ODIV, OMOD:
                return samesafeexpr(l.Left, r.Left) && samesafeexpr(l.Right, r.Right)
 
        case OLITERAL:
index 35620e741cedbaa07c4980a0e833cb0c9df9cd65..a914a0c766ece0c5c17a50c1ff361231413c596c 100644 (file)
@@ -304,6 +304,18 @@ func mapAppendAssignmentInt32() {
        // arm64:-".*mapaccess"
        m[k] = append(m[k], a...)
 
+       // 386:-".*mapaccess"
+       // amd64:-".*mapaccess"
+       // arm:-".*mapaccess"
+       // arm64:-".*mapaccess"
+       m[k+1] = append(m[k+1], a...)
+
+       // 386:-".*mapaccess"
+       // amd64:-".*mapaccess"
+       // arm:-".*mapaccess"
+       // arm64:-".*mapaccess"
+       m[-k] = append(m[-k], a...)
+
        // Exceptions
 
        // 386:".*mapaccess"
@@ -349,6 +361,18 @@ func mapAppendAssignmentInt64() {
        // arm64:-".*mapaccess"
        m[k] = append(m[k], a...)
 
+       // 386:-".*mapaccess"
+       // amd64:-".*mapaccess"
+       // arm:-".*mapaccess"
+       // arm64:-".*mapaccess"
+       m[k+1] = append(m[k+1], a...)
+
+       // 386:-".*mapaccess"
+       // amd64:-".*mapaccess"
+       // arm:-".*mapaccess"
+       // arm64:-".*mapaccess"
+       m[-k] = append(m[-k], a...)
+
        // Exceptions
 
        // 386:".*mapaccess"