]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: add rules handling unsigned div/mod by constant 1<<63
authorCherry Zhang <cherryyz@google.com>
Fri, 18 Aug 2017 12:37:58 +0000 (08:37 -0400)
committerCherry Zhang <cherryyz@google.com>
Fri, 18 Aug 2017 17:12:14 +0000 (17:12 +0000)
commit99fe3f8c63c20d675b0237665a535a8ad9783de4
treed85092714c2390c3c235123394b0cdeed36bfb1c
parent839b28246f7ec04b6d5a8d747a84d6c8bb1c33ef
cmd/compile: add rules handling unsigned div/mod by constant 1<<63

Normally 64-bit div/mod is turned into runtime calls on 32-bit
arch, but the front end leaves power-of-two constant division
and hopes the SSA backend turns into a shift or AND. The SSA rule is

(Mod64u <t> n (Const64 [c])) && isPowerOfTwo(c) -> (And64 n (Const64 <t> [c-1]))

But isPowerOfTwo returns true only for positive int64, which leaves
out 1<<63 unhandled. Add a special case for 1<<63.

Fixes #21517.

Change-Id: I02d27dc7177d4af0ee8d7f5533714edecddf8c95
Reviewed-on: https://go-review.googlesource.com/56890
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/testdata/arithConst.go
src/cmd/compile/internal/gc/testdata/gen/arithConstGen.go
src/cmd/compile/internal/ssa/gen/generic.rules
src/cmd/compile/internal/ssa/rewritegeneric.go