]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.ssa] cmd/compile: implement lowering of constant bools
authorJosh Bleecher Snyder <josharian@gmail.com>
Thu, 16 Jul 2015 19:12:57 +0000 (13:12 -0600)
committerJosh Bleecher Snyder <josharian@gmail.com>
Thu, 16 Jul 2015 19:28:45 +0000 (19:28 +0000)
Change-Id: Ia56ee9798eefe123d4da04138a6a559d2c25ddf3
Reviewed-on: https://go-review.googlesource.com/12312
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/ssa/gen/AMD64.rules
src/cmd/compile/internal/ssa/rewriteAMD64.go

index 1eb29105d2f775e9a347821dfd9d551df4b25cde..6882621f710569ca2107fc4e58b5aa8df62411d8 100644 (file)
@@ -77,6 +77,8 @@
 
 (Const <t> [val]) && t.IsInteger() -> (MOVQconst [val])
 (Const <t>) && t.IsPtr() -> (MOVQconst [0]) // nil is the only const pointer
+(Const <t>) && t.IsBoolean() && !v.Aux.(bool) -> (MOVQconst [0])
+(Const <t>) && t.IsBoolean() && v.Aux.(bool) -> (MOVQconst [1])
 
 (Addr {sym} base) -> (LEAQ {sym} base)
 
index 728c45cc49f5b4b715e4a37689a9386aaef61743..7393cd9a8974c38f492fe379a43205beab10513a 100644 (file)
@@ -517,6 +517,42 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
                goto endd23abe8d7061f11c260b162e24eec060
        endd23abe8d7061f11c260b162e24eec060:
                ;
+               // match: (Const <t>)
+               // cond: t.IsBoolean() && !v.Aux.(bool)
+               // result: (MOVQconst [0])
+               {
+                       t := v.Type
+                       if !(t.IsBoolean() && !v.Aux.(bool)) {
+                               goto end7b1347fd0902b990ee1e49145c7e8c31
+                       }
+                       v.Op = OpAMD64MOVQconst
+                       v.AuxInt = 0
+                       v.Aux = nil
+                       v.resetArgs()
+                       v.AuxInt = 0
+                       return true
+               }
+               goto end7b1347fd0902b990ee1e49145c7e8c31
+       end7b1347fd0902b990ee1e49145c7e8c31:
+               ;
+               // match: (Const <t>)
+               // cond: t.IsBoolean() && v.Aux.(bool)
+               // result: (MOVQconst [1])
+               {
+                       t := v.Type
+                       if !(t.IsBoolean() && v.Aux.(bool)) {
+                               goto ende0d1c954b5ab5af7227bff9635774f1c
+                       }
+                       v.Op = OpAMD64MOVQconst
+                       v.AuxInt = 0
+                       v.Aux = nil
+                       v.resetArgs()
+                       v.AuxInt = 1
+                       return true
+               }
+               goto ende0d1c954b5ab5af7227bff9635774f1c
+       ende0d1c954b5ab5af7227bff9635774f1c:
+               ;
        case OpConvNop:
                // match: (ConvNop <t> x)
                // cond: t == x.Type