diff options
author | Alexandru Moșoi <brtzsnr@gmail.com> | 2016-04-05 23:32:49 +0200 |
---|---|---|
committer | Alexandru Moșoi <alexandru@mosoi.ro> | 2016-04-07 13:28:13 +0000 |
commit | 8448d3aace7f26bd6eca14e8b89c5a981c2ab9d3 (patch) | |
tree | 1a01cc1444c82e3e66cd194cefca29b7e02a2471 /test/checkbce.go | |
parent | 121c434f7add815c3147b01a097a8998018bcc6b (diff) | |
download | go-8448d3aace7f26bd6eca14e8b89c5a981c2ab9d3.tar.gz go-8448d3aace7f26bd6eca14e8b89c5a981c2ab9d3.zip |
cmd/compile: fold CMPconst and SHR
Fold the comparison when the SHR result is small.
Useful for:
- murmur mix like hashing where higher bits are desirable, i.e. hash = uint32(i * C) >> 18
- integer log2 via DeBruijn sequence: http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn
Change-Id: If70ae18cb86f4cc83ab6213f88ced03cc4986156
Reviewed-on: https://go-review.googlesource.com/21514
Run-TryBot: Alexandru Moșoi <alexandru@mosoi.ro>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'test/checkbce.go')
-rw-r--r-- | test/checkbce.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/test/checkbce.go b/test/checkbce.go index a3b0100db8..988375fcc7 100644 --- a/test/checkbce.go +++ b/test/checkbce.go @@ -52,6 +52,18 @@ func f5(a []int) { } } +func f6(a [32]int, b [64]int, i int) { + useInt(a[uint32(i*0x07C4ACDD)>>27]) + useInt(b[uint64(i*0x07C4ACDD)>>58]) + useInt(a[uint(i*0x07C4ACDD)>>59]) + + // The following bounds should removed as they can overflow. + useInt(a[uint32(i*0x106297f105d0cc86)>>26]) // ERROR "Found IsInBounds$" + useInt(b[uint64(i*0x106297f105d0cc86)>>57]) // ERROR "Found IsInBounds$" + useInt(a[int32(i*0x106297f105d0cc86)>>26]) // ERROR "Found IsInBounds$" + useInt(b[int64(i*0x106297f105d0cc86)>>57]) // ERROR "Found IsInBounds$" +} + func g1(a []int) { for i := range a { a[i] = i |