]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: constant fold SSA bool to int conversions
authorJosh Bleecher Snyder <josharian@gmail.com>
Sat, 29 Feb 2020 15:07:56 +0000 (07:07 -0800)
committerJosh Bleecher Snyder <josharian@gmail.com>
Sat, 29 Feb 2020 17:02:40 +0000 (17:02 +0000)
Shaves off a few instructions here and there.

file                        before   after    Δ       %
go/types.s                  322118   321851   -267    -0.083%
go/internal/gcimporter.s    34937    34909    -28     -0.080%
go/internal/gccgoimporter.s 56493    56474    -19     -0.034%
cmd/compile/internal/ssa.s  3926994  3927177  +183    +0.005%
total                       18862670 18862539 -131    -0.001%

Change-Id: I724f32317b946b5138224808f85709d9c097a247
Reviewed-on: https://go-review.googlesource.com/c/go/+/221428
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ssa/gen/generic.rules
src/cmd/compile/internal/ssa/rewritegeneric.go

index f4d487176b6cebad142bd5b12434f74896bba037..54c5ed646f5671a29528c38f1c8e73d9e1e8025d 100644 (file)
@@ -56,6 +56,7 @@
 (Cvt64Fto64  (Const64F [c])) -> (Const64  [int64(auxTo64F(c))])
 (Round32F x:(Const32F)) -> x
 (Round64F x:(Const64F)) -> x
+(CvtBoolToUint8 (ConstBool [c])) -> (Const8 [c])
 
 (Trunc16to8  (ZeroExt8to16  x)) -> x
 (Trunc32to8  (ZeroExt8to32  x)) -> x
index c711af249c9fcccd21619a75f867816e7866c2cb..94c2353fd97a58ee13206a7148506e787c7a1946 100644 (file)
@@ -68,6 +68,8 @@ func rewriteValuegeneric(v *Value) bool {
                return rewriteValuegeneric_OpCvt64to32F(v)
        case OpCvt64to64F:
                return rewriteValuegeneric_OpCvt64to64F(v)
+       case OpCvtBoolToUint8:
+               return rewriteValuegeneric_OpCvtBoolToUint8(v)
        case OpDiv16:
                return rewriteValuegeneric_OpDiv16(v)
        case OpDiv16u:
@@ -2981,6 +2983,21 @@ func rewriteValuegeneric_OpCvt64to64F(v *Value) bool {
        }
        return false
 }
+func rewriteValuegeneric_OpCvtBoolToUint8(v *Value) bool {
+       v_0 := v.Args[0]
+       // match: (CvtBoolToUint8 (ConstBool [c]))
+       // result: (Const8 [c])
+       for {
+               if v_0.Op != OpConstBool {
+                       break
+               }
+               c := v_0.AuxInt
+               v.reset(OpConst8)
+               v.AuxInt = c
+               return true
+       }
+       return false
+}
 func rewriteValuegeneric_OpDiv16(v *Value) bool {
        v_1 := v.Args[1]
        v_0 := v.Args[0]