diff options
author | Josh Bleecher Snyder <josharian@gmail.com> | 2020-04-23 00:21:59 -0700 |
---|---|---|
committer | Josh Bleecher Snyder <josharian@gmail.com> | 2020-04-23 17:52:28 +0000 |
commit | e7c187369149741f96c445c153be4fc6475bc365 (patch) | |
tree | e3a9440e00e47c9bb3a00980540ecf97c3dff222 /src/cmd/compile/internal/ssa/rewriteAMD64.go | |
parent | 917aa72c1438c64e593d68a779892b97012b4779 (diff) | |
download | go-e7c187369149741f96c445c153be4fc6475bc365.tar.gz go-e7c187369149741f96c445c153be4fc6475bc365.zip |
cmd/compile: optimize x & 1 != 0 to x & 1 on amd64
Triggers a handful of times in std+cmd.
Change-Id: I9bb8ce9a5f8bae2547cb61157cd8f256e1b63e76
Reviewed-on: https://go-review.googlesource.com/c/go/+/229602
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/cmd/compile/internal/ssa/rewriteAMD64.go')
-rw-r--r-- | src/cmd/compile/internal/ssa/rewriteAMD64.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/rewriteAMD64.go b/src/cmd/compile/internal/ssa/rewriteAMD64.go index df36e41d2d..fee9cfee35 100644 --- a/src/cmd/compile/internal/ssa/rewriteAMD64.go +++ b/src/cmd/compile/internal/ssa/rewriteAMD64.go @@ -21833,6 +21833,30 @@ func rewriteValueAMD64_OpAMD64SETB(v *Value) bool { v.AuxInt = 0 return true } + // match: (SETB (BTLconst [0] x)) + // result: (ANDLconst [1] x) + for { + if v_0.Op != OpAMD64BTLconst || auxIntToInt8(v_0.AuxInt) != 0 { + break + } + x := v_0.Args[0] + v.reset(OpAMD64ANDLconst) + v.AuxInt = int32ToAuxInt(1) + v.AddArg(x) + return true + } + // match: (SETB (BTQconst [0] x)) + // result: (ANDQconst [1] x) + for { + if v_0.Op != OpAMD64BTQconst || auxIntToInt8(v_0.AuxInt) != 0 { + break + } + x := v_0.Args[0] + v.reset(OpAMD64ANDQconst) + v.AuxInt = int32ToAuxInt(1) + v.AddArg(x) + return true + } // match: (SETB (InvertFlags x)) // result: (SETA x) for { @@ -24176,6 +24200,30 @@ func rewriteValueAMD64_OpAMD64SETLstore(v *Value) bool { func rewriteValueAMD64_OpAMD64SETNE(v *Value) bool { v_0 := v.Args[0] b := v.Block + // match: (SETNE (TESTBconst [1] x)) + // result: (ANDLconst [1] x) + for { + if v_0.Op != OpAMD64TESTBconst || auxIntToInt8(v_0.AuxInt) != 1 { + break + } + x := v_0.Args[0] + v.reset(OpAMD64ANDLconst) + v.AuxInt = int32ToAuxInt(1) + v.AddArg(x) + return true + } + // match: (SETNE (TESTWconst [1] x)) + // result: (ANDLconst [1] x) + for { + if v_0.Op != OpAMD64TESTWconst || auxIntToInt16(v_0.AuxInt) != 1 { + break + } + x := v_0.Args[0] + v.reset(OpAMD64ANDLconst) + v.AuxInt = int32ToAuxInt(1) + v.AddArg(x) + return true + } // match: (SETNE (TESTL (SHLL (MOVLconst [1]) x) y)) // result: (SETB (BTL x y)) for { |