Skip to content

Commit

Permalink
cmd/compile/internal/ssa: fix endless compile loop on AMD64
Browse files Browse the repository at this point in the history
We currently rewrite
(TESTQ (MOVQconst [c] x)) into (TESTQconst [c] x)
and (TESTQconst [-1] x) into (TESTQ x x)
if x is a (MOVQconst [-1]) we will be stuck in the endless rewrite loop.
Don't perform the rewrite in such cases.

Fixes #25006

Change-Id: I77f561ba2605fc104f1e5d5c57f32e9d67a2c000
Reviewed-on: https://go-review.googlesource.com/108879
Run-TryBot: Ilya Tocar <ilya.tocar@intel.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
  • Loading branch information
TocarIP committed Apr 24, 2018
1 parent cd037bc commit fb017c6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/cmd/compile/internal/ssa/gen/AMD64.rules
Expand Up @@ -1443,10 +1443,10 @@
(CMPLconst x [0]) -> (TESTL x x)
(CMPWconst x [0]) -> (TESTW x x)
(CMPBconst x [0]) -> (TESTB x x)
(TESTQconst [-1] x) -> (TESTQ x x)
(TESTLconst [-1] x) -> (TESTL x x)
(TESTWconst [-1] x) -> (TESTW x x)
(TESTBconst [-1] x) -> (TESTB x x)
(TESTQconst [-1] x) && x.Op != OpAMD64MOVQconst -> (TESTQ x x)
(TESTLconst [-1] x) && x.Op != OpAMD64MOVLconst -> (TESTL x x)
(TESTWconst [-1] x) && x.Op != OpAMD64MOVLconst -> (TESTW x x)
(TESTBconst [-1] x) && x.Op != OpAMD64MOVLconst -> (TESTB x x)

// Combining byte loads into larger (unaligned) loads.
// There are many ways these combinations could occur. This is
Expand Down
20 changes: 16 additions & 4 deletions src/cmd/compile/internal/ssa/rewriteAMD64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions test/fixedbugs/issue25006.go
@@ -0,0 +1,30 @@
// compile

// 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 p

func spin() {
var i int
var b bool

switch 1 {
case 0:
i = 1
}
switch 1 {
case i:
default:
i = 1
b = !b && (b && !b) && b
}
switch false {
case false:
i = 3 + -i
switch 0 {
case 1 - i:
}
}
}

0 comments on commit fb017c6

Please sign in to comment.