Skip to content

Commit fb017c6

Browse files
committed
cmd/compile/internal/ssa: fix endless compile loop on AMD64
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>
1 parent cd037bc commit fb017c6

File tree

3 files changed

+50
-8
lines changed

3 files changed

+50
-8
lines changed

src/cmd/compile/internal/ssa/gen/AMD64.rules

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,10 +1443,10 @@
14431443
(CMPLconst x [0]) -> (TESTL x x)
14441444
(CMPWconst x [0]) -> (TESTW x x)
14451445
(CMPBconst x [0]) -> (TESTB x x)
1446-
(TESTQconst [-1] x) -> (TESTQ x x)
1447-
(TESTLconst [-1] x) -> (TESTL x x)
1448-
(TESTWconst [-1] x) -> (TESTW x x)
1449-
(TESTBconst [-1] x) -> (TESTB x x)
1446+
(TESTQconst [-1] x) && x.Op != OpAMD64MOVQconst -> (TESTQ x x)
1447+
(TESTLconst [-1] x) && x.Op != OpAMD64MOVLconst -> (TESTL x x)
1448+
(TESTWconst [-1] x) && x.Op != OpAMD64MOVLconst -> (TESTW x x)
1449+
(TESTBconst [-1] x) && x.Op != OpAMD64MOVLconst -> (TESTB x x)
14501450

14511451
// Combining byte loads into larger (unaligned) loads.
14521452
// There are many ways these combinations could occur. This is

src/cmd/compile/internal/ssa/rewriteAMD64.go

Lines changed: 16 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixedbugs/issue25006.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// compile
2+
3+
// Copyright 2018 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package p
8+
9+
func spin() {
10+
var i int
11+
var b bool
12+
13+
switch 1 {
14+
case 0:
15+
i = 1
16+
}
17+
switch 1 {
18+
case i:
19+
default:
20+
i = 1
21+
b = !b && (b && !b) && b
22+
}
23+
switch false {
24+
case false:
25+
i = 3 + -i
26+
switch 0 {
27+
case 1 - i:
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)