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: incorrect math reduction #70481

Closed
randall77 opened this issue Nov 21, 2024 · 3 comments
Closed

cmd/compile: incorrect math reduction #70481

randall77 opened this issue Nov 21, 2024 · 3 comments
Assignees
Labels
arch-arm64 compiler/runtime Issues related to the Go compiler and/or runtime. release-blocker
Milestone

Comments

@randall77
Copy link
Contributor

randall77 commented Nov 21, 2024

Go version

tip

Output of go env in your module/workspace:

AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/khr/Library/Caches/go-build'
GODEBUG=''
GOENV='/Users/khr/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/z9/dty110711l9cr9w3ktv1_2380000gn/T/go-build1754495342=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/khr/sandbox/swissbase/src/go.mod'
GOMODCACHE='/Users/khr/gopath/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/khr/gopath'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/khr/sandbox/swissbase'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/khr/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/khr/sandbox/swissbase/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='devel go1.24-c483fdbfcf Wed Nov 20 16:57:48 2024 +0000'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

First seen as a failure on x/exp. The test rand.TestModulo is failing.

Reproducer:

package main

const maxUint64 = (1 << 64) - 1

//go:noinline
func f(n uint64) uint64 {
	return maxUint64 - maxUint64%n
}

func main() {
	for i := uint64(1); i < 20; i++ {
		println(i, maxUint64-f(i))
	}
}

This prints different things than go1.23 prints.

It was caused by me in CL 629858. Subtracting a negative should make a positive, it seems.

What did you see happen?

test failure. It prints

1 2
2 3
3 2
4 5
5 2
6 5
7 3
8 9
9 8
10 7
11 6
12 5
13 4
14 3
15 2
16 17
17 2
18 17
19 18

What did you expect to see?

It should print

1 0
2 1
3 0
4 3
5 0
6 3
7 1
8 7
9 6
10 5
11 4
12 3
13 2
14 1
15 0
16 15
17 0
18 15
19 16
@randall77 randall77 self-assigned this Nov 21, 2024
@randall77 randall77 added this to the Go1.24 milestone Nov 21, 2024
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Nov 21, 2024
@randall77
Copy link
Contributor Author

@dmitshur

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/630397 mentions this issue: cmd/compile: fix rewrite rules for multiply/add

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-arm64 compiler/runtime Issues related to the Go compiler and/or runtime. release-blocker
Projects
None yet
Development

No branches or pull requests

4 participants