diff --git a/src/cmd/compile/internal/ssa/gen/AMD64.rules b/src/cmd/compile/internal/ssa/gen/AMD64.rules index 1eb29105d2..6882621f71 100644 --- a/src/cmd/compile/internal/ssa/gen/AMD64.rules +++ b/src/cmd/compile/internal/ssa/gen/AMD64.rules @@ -77,6 +77,8 @@ (Const [val]) && t.IsInteger() -> (MOVQconst [val]) (Const ) && t.IsPtr() -> (MOVQconst [0]) // nil is the only const pointer +(Const ) && t.IsBoolean() && !v.Aux.(bool) -> (MOVQconst [0]) +(Const ) && t.IsBoolean() && v.Aux.(bool) -> (MOVQconst [1]) (Addr {sym} base) -> (LEAQ {sym} base) diff --git a/src/cmd/compile/internal/ssa/rewriteAMD64.go b/src/cmd/compile/internal/ssa/rewriteAMD64.go index 728c45cc49..7393cd9a89 100644 --- a/src/cmd/compile/internal/ssa/rewriteAMD64.go +++ b/src/cmd/compile/internal/ssa/rewriteAMD64.go @@ -517,6 +517,42 @@ func rewriteValueAMD64(v *Value, config *Config) bool { goto endd23abe8d7061f11c260b162e24eec060 endd23abe8d7061f11c260b162e24eec060: ; + // match: (Const ) + // 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 ) + // 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 x) // cond: t == x.Type