]> Cypherpunks.ru repositories - gostls13.git/commit
[release-branch.go1.9] cmd/compile: add rules handling unsigned div/mod by constant...
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 18:43:00 +0000 (18:43 +0000)
commit5927854f7d2bf10704d80cf28fed2385fc0a7b42
tree9c06e53582b808159c067407a7fa374b7afaf379
parent65717b2dca2d927a2210696c1fe22c0952f9c139
[release-branch.go1.9] cmd/compile: add rules handling unsigned div/mod by constant 1<<63

Cherry-pick CL 56890.

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: Ic91f86fd5e035a8bb64b937c15cb1c38fec917d6
Reviewed-on: https://go-review.googlesource.com/57070
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@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