]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile: make loop guard+rotate conditional on GOEXPERIMENT
authorDavid Chase <drchase@google.com>
Wed, 21 Jun 2017 21:19:24 +0000 (17:19 -0400)
committerDavid Chase <drchase@google.com>
Wed, 21 Jun 2017 22:07:33 +0000 (22:07 +0000)
Loops of the form "for i,e := range" needed to have their
condition rotated to the "bottom" for the preemptible loops
GOEXPERIMENT, but this caused a performance regression
because it degraded bounds check removal.  For now, make
the loop rotation/guarding conditional on the experiment.

Fixes #20711.
Updates #10958.

Change-Id: Icfba14cb3b13a910c349df8f84838cf4d9d20cf6
Reviewed-on: https://go-review.googlesource.com/46410
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/range.go
test/loopbce.go

index 963c26824d2a29c1ad9dbe6204917210abec00d2..032601ca3dfd212da80ae6336eb789e2f50dd8ac 100644 (file)
@@ -6,6 +6,7 @@ package gc
 
 import (
        "cmd/compile/internal/types"
+       "cmd/internal/objabi"
        "unicode/utf8"
 )
 
@@ -211,9 +212,13 @@ func walkrange(n *Node) *Node {
                } else if v2 == nil {
                        body = []*Node{nod(OAS, v1, hv1)}
                } else { // for i,a := range thing { body }
-                       ifGuard = nod(OIF, nil, nil)
-                       ifGuard.Left = nod(OLT, hv1, hn)
-                       translatedLoopOp = OFORUNTIL
+                       if objabi.Preemptibleloops_enabled != 0 {
+                               // Doing this transformation makes a bounds check removal less trivial; see #20711
+                               // TODO enhance the preemption check insertion so that this transformation is not necessary.
+                               ifGuard = nod(OIF, nil, nil)
+                               ifGuard.Left = nod(OLT, hv1, hn)
+                               translatedLoopOp = OFORUNTIL
+                       }
 
                        a := nod(OAS2, nil, nil)
                        a.List.Set2(v1, v2)
index 63bb4bae58ae948ed3d0b2c663daa10fffaa694e..857cf2442b64ee026301b13b51178e95be4fe923 100644 (file)
@@ -31,7 +31,7 @@ func f0c(a []int) int {
 
 func f1(a []int) int {
        x := 0
-       for _, i := range a { // Change to "for i,e := range array/slice" hides IV report.
+       for _, i := range a { // ERROR "Induction variable with minimum 0 and increment 1"
                x += i
        }
        return x