Go version
go version go1.24.4 linux/amd64
Output of go env
in your module/workspace:
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v3'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/ren/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/ren/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3297555499=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/ren/dev/junk/bugXXX/go.mod'
GOMODCACHE='/home/ren/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/ren/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/ren/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.4'
GOWORK=''
PKG_CONFIG='pkg-config'
What did you do?
package main
func f(b uint8) uint8 {
return b / 128
}
What did you see happen?
MOVBLZX AL, AX
MOVL $-128, CX
MOVBLZX CL, CX
XORL DX, DX
DIVW CX
RET
What did you expect to see?
SHRB $7, AL
Comment From: gabyhelp
Related Issues
- Signed non-negative divide by power of 2. #44530 (closed)
- cmd/compile: favour UDIV over UMULH + LSR on arm64 for 64 bit integer division by a constant #37773 (closed)
- cmd/compile: missed shift optimizations on amd64 #19681 (closed)
- cmd/compile: unneccesary 0 check in division #45928 (closed)
- cmd/asm: amd64: Invalid instruction emits wrong binary without error #59462 (closed)
- cmd/compile: encoding/binary.PutUint32 generates unaligned data storage on arm64 arch #59856 (closed)
- cmd/compile: invalid instruction: MOVL $11553462026240, AX #41711 (closed)
- cmd/compile: constant division optimization is disabled on arm64 #15382 (closed)
- cmd/compile: unsafe conversion from slice to struct pointer generates worse code on amd64 than on 386 #65330
- cmd/compile: handle 64-bit masks better on 32-bit systems #32781 (closed)
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: randall77
Yes, this is an unfortunate consequence of our power-of-two detector. It gives up on -2^(n-1). Probably pretty easy to fix. I think we just need an unsigned power-of-two detector.