]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.ssa] cmd/compile: detect rewrite loops of length > 1
authorJosh Bleecher Snyder <josharian@gmail.com>
Mon, 10 Aug 2015 21:01:04 +0000 (14:01 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Mon, 10 Aug 2015 21:14:17 +0000 (21:14 +0000)
Use a version of Floyd's cycle finding algorithm,
but advance by 1 and 1/2 steps per cycle rather
than by 1 and 2. It is simpler and should be cheaper
in the normal, acyclic case.

This should fix the 386 and arm builds,
which are currently hung.

Change-Id: If8bd443011b28a5ecb004a549239991d3dfc862b
Reviewed-on: https://go-review.googlesource.com/13473
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ssa/rewrite.go

index a02f1d50b2f0fc90d9fd9820a5a28db508a4ecea..39fc48df4a5c6a832f734fcb5ba5dd52161a763e 100644 (file)
@@ -44,9 +44,18 @@ func applyRewrite(f *Func, rb func(*Block) bool, rv func(*Value, *Config) bool)
                                        }
                                        // Rewriting can generate OpCopy loops.
                                        // They are harmless (see removePredecessor),
-                                       // but take care not to loop forever.
-                                       for a.Op == OpCopy && a != a.Args[0] {
+                                       // but take care to stop if we find a cycle.
+                                       slow := a // advances every other iteration
+                                       var advance bool
+                                       for a.Op == OpCopy {
                                                a = a.Args[0]
+                                               if slow == a {
+                                                       break
+                                               }
+                                               if advance {
+                                                       slow = a
+                                               }
+                                               advance = !advance
                                        }
                                        v.Args[i] = a
                                }