]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: int64(uint64 >> x) >= 0 if x > 0
authorJosh Bleecher Snyder <josharian@gmail.com>
Wed, 13 Mar 2019 21:36:34 +0000 (14:36 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Thu, 14 Mar 2019 00:03:38 +0000 (00:03 +0000)
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>
src/cmd/compile/internal/ssa/gen/generic.rules
src/cmd/compile/internal/ssa/rewritegeneric.go

index 43e788562c83bdd365f185e8a3da78abfff43454..aac7438e0a8861a465d6944260729dbf6883c0e4 100644 (file)
 (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))])
index b25012cb313348a6581ccc77cf200662241c87e1..543664c8bcbcfc5f4dc46004a05421aa5c453658 100644 (file)
@@ -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 {