golang/go

cmd/compile: compiler hangs on tiny program

ALTree opened this issue · 5 comments

$ gotip version
go version devel +d11df8baa8 Sun Apr 22 22:32:11 2018 +0000 linux/amd64

The following program:

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:
		}
	}
}

hangs the tip compiler (spinning at 100% cpu) when built for amd64.

It compiles in no time in go1.10.

The issue was introduced in CL 100935 (cmd/compile: implement CMOV on amd64).

cc @rasky @randall77

Looks like an endless loop in rules application. Will send fix soon

Change https://golang.org/cl/108879 mentions this issue: cmd/compile/internal/ssa: fix endless compile loop on AMD64

Looks like it is easy to introduce endless rewrite, maybe we should just stop rewrite after e. g. 1000*values rewrites and suggest opening a bug.

rasky commented

Thanks @TocarIP for cleaning up after me!