Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile/internal/ssa: occurred the wrong rewrite cycle detection #51639

Closed
orisano opened this issue Mar 12, 2022 · 6 comments
Closed

cmd/compile/internal/ssa: occurred the wrong rewrite cycle detection #51639

orisano opened this issue Mar 12, 2022 · 6 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@orisano
Copy link
Contributor

orisano commented Mar 12, 2022

What version of Go are you using (go version)?

$ go version
go version go1.18rc1 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/orisano/Library/Caches/go-build"
GOENV="/Users/orisano/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/orisano/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/orisano/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/orisano/sdk/go1.18rc1"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/orisano/sdk/go1.18rc1/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18rc1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/orisano/tmp/repro/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/5s/d4b31rld7l7d1169gfk7cfl80000gn/T/go-build2915424394=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

https://go.dev/play/p/sw3yvtCuPYW?v=gotip

I tried to build this program with -gcflags='-d "ssa/opt/debug=2"'

What did you expect to see?

debug logs.

What did you see instead?

$ go build -gcflags='-d "ssa/opt/debug=2"'
# repro
opt: rewriting for f
rewriting v13 = Convert <unsafe.Pointer> v12 v1  ->  v13 = AddPtr <unsafe.Pointer> v7 v8
./a.go:6:56: internal compiler error: 'f': rewrite cycle detected

Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new

Note

I investigated the cause of this issue.
it only rewrote rewriting v13 = Convert <unsafe.Pointer> v12 v1 -> v13 = AddPtr <unsafe.Pointer> v7 v8 on the 1st step.
and then calculate the hash of this function, store it to the states.
on the 2nd step, it only proceeded to remove dead values.

if v.Uses == 0 && v.removeable() {
if v.Op != OpInvalid && deadcode == removeDeadValues {
// Reset any values that are now unused, so that we decrement
// the use count of all of its arguments.
// Not quite a deadcode pass, because it does not handle cycles.
// But it should help Uses==1 rules to fire.
v.reset(OpInvalid)
change = true
}
// No point rewriting values which aren't used.
continue
}

it calculated the hash of this function again, got the same result to trigger the rewrite cycle detected.

@cuonglm
Copy link
Member

cuonglm commented Mar 13, 2022

cc @josharian

@cuonglm cuonglm added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 13, 2022
@cuonglm cuonglm added this to the Go1.19 milestone Mar 13, 2022
@gopherbot
Copy link

gopherbot commented Mar 14, 2022

Change https://go.dev/cl/392760 mentions this issue: cmd/compile: disable rewrite loop detector for deadcode-only changes

@randall77
Copy link
Contributor

randall77 commented Apr 15, 2022

@gopherbot please open a backport issue for 1.18.

@gopherbot
Copy link

gopherbot commented Apr 15, 2022

Backport issue(s) opened: #52366 (for 1.18).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@bo-er
Copy link

bo-er commented Jun 7, 2022

I had the same problem using GO version 1.18, after switching to Go 1.14 the problem is gone.

@randall77
Copy link
Contributor

randall77 commented Jun 7, 2022

@bo-er This issue was fixed in 1.18.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants