diff options
| author | Josh Bleecher Snyder <josharian@gmail.com> | 2019-03-13 14:36:34 -0700 |
|---|---|---|
| committer | Josh Bleecher Snyder <josharian@gmail.com> | 2019-03-14 00:03:38 +0000 |
| commit | 66f5d4e03500bf5085d10eb5ffd89bf33b7d2b9f (patch) | |
| tree | 131a2f21aac3351877dc18ce012c3b14d8685bc3 /src | |
| parent | 61945fc5022e36ae88758f2c4e8f7c29f0824ae0 (diff) | |
| download | go-66f5d4e03500bf5085d10eb5ffd89bf33b7d2b9f.tar.xz | |
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 <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src')
| -rw-r--r-- | src/cmd/compile/internal/ssa/gen/generic.rules | 2 | ||||
| -rw-r--r-- | src/cmd/compile/internal/ssa/rewritegeneric.go | 29 |
2 files changed, 31 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/gen/generic.rules b/src/cmd/compile/internal/ssa/gen/generic.rules index 43e788562c..aac7438e0a 100644 --- a/src/cmd/compile/internal/ssa/gen/generic.rules +++ b/src/cmd/compile/internal/ssa/gen/generic.rules @@ -425,6 +425,8 @@ (Geq32 (And32 _ (Const32 [c])) (Const32 [0])) && int32(c) >= 0 -> (ConstBool [1]) (Geq64 (And64 _ (Const64 [c])) (Const64 [0])) && int64(c) >= 0 -> (ConstBool [1]) +(Geq64 (Rsh64Ux64 _ (Const64 [c])) (Const64 [0])) && c > 0 -> (ConstBool [1]) + (Greater64U (Const64 [c]) (Const64 [d])) -> (ConstBool [b2i(uint64(c) > uint64(d))]) (Greater32U (Const32 [c]) (Const32 [d])) -> (ConstBool [b2i(uint32(c) > uint32(d))]) (Greater16U (Const16 [c]) (Const16 [d])) -> (ConstBool [b2i(uint16(c) > uint16(d))]) diff --git a/src/cmd/compile/internal/ssa/rewritegeneric.go b/src/cmd/compile/internal/ssa/rewritegeneric.go index b25012cb31..543664c8bc 100644 --- a/src/cmd/compile/internal/ssa/rewritegeneric.go +++ b/src/cmd/compile/internal/ssa/rewritegeneric.go @@ -10714,6 +10714,35 @@ func rewriteValuegeneric_OpGeq64_0(v *Value) bool { v.AuxInt = 1 return true } + // match: (Geq64 (Rsh64Ux64 _ (Const64 [c])) (Const64 [0])) + // cond: c > 0 + // result: (ConstBool [1]) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpRsh64Ux64 { + break + } + _ = v_0.Args[1] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpConst64 { + break + } + c := v_0_1.AuxInt + v_1 := v.Args[1] + if v_1.Op != OpConst64 { + break + } + if v_1.AuxInt != 0 { + break + } + if !(c > 0) { + break + } + v.reset(OpConstBool) + v.AuxInt = 1 + return true + } return false } func rewriteValuegeneric_OpGeq64F_0(v *Value) bool { |
