Skip to content

Commit 66f5d4e

Browse files
committed
cmd/compile: int64(uint64 >> x) >= 0 if x > 0
This rewrite rule triggers only once, in math/big.quotToFloat64, as part of converting a uint64 to a float64. Nevertheless, it is cheap; let's add it. Change-Id: I3ed4a197a559110fec1bc04b3a8abb4c7fcc2c89 Reviewed-on: https://go-review.googlesource.com/c/go/+/167500 Run-TryBot: Josh Bleecher Snyder <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 61945fc commit 66f5d4e

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/cmd/compile/internal/ssa/gen/generic.rules

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@
425425
(Geq32 (And32 _ (Const32 [c])) (Const32 [0])) && int32(c) >= 0 -> (ConstBool [1])
426426
(Geq64 (And64 _ (Const64 [c])) (Const64 [0])) && int64(c) >= 0 -> (ConstBool [1])
427427

428+
(Geq64 (Rsh64Ux64 _ (Const64 [c])) (Const64 [0])) && c > 0 -> (ConstBool [1])
429+
428430
(Greater64U (Const64 [c]) (Const64 [d])) -> (ConstBool [b2i(uint64(c) > uint64(d))])
429431
(Greater32U (Const32 [c]) (Const32 [d])) -> (ConstBool [b2i(uint32(c) > uint32(d))])
430432
(Greater16U (Const16 [c]) (Const16 [d])) -> (ConstBool [b2i(uint16(c) > uint16(d))])

src/cmd/compile/internal/ssa/rewritegeneric.go

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)