The CMP* family of instructions are longer than their TEST counterparts by one byte.
After this change, my go tool has 13 cmp.*$0x0 instructions, compared to 5612 before.
Change-Id: Ieb87d65657917e494c0e4b711a7ba2918ae27610
Reviewed-on: https://go-review.googlesource.com/21255
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
(CMPWconst (ANDWconst [c] x) [0]) -> (TESTWconst [c] x)
(CMPBconst (ANDBconst [c] x) [0]) -> (TESTBconst [c] x)
+// TEST %reg,%reg is shorter than CMP
+(CMPQconst x [0]) -> (TESTQ x x)
+(CMPLconst x [0]) -> (TESTL x x)
+(CMPWconst x [0]) -> (TESTW x x)
+(CMPBconst x [0]) -> (TESTB x x)
+
// Combining byte loads into larger (unaligned) loads.
// There are many ways these combinations could occur. This is
// designed to match the way encoding/binary.LittleEndian does it.
v.AddArg(x)
return true
}
+ // match: (CMPBconst x [0])
+ // cond:
+ // result: (TESTB x x)
+ for {
+ x := v.Args[0]
+ if v.AuxInt != 0 {
+ break
+ }
+ v.reset(OpAMD64TESTB)
+ v.AddArg(x)
+ v.AddArg(x)
+ return true
+ }
return false
}
func rewriteValueAMD64_OpAMD64CMPL(v *Value, config *Config) bool {
v.AddArg(x)
return true
}
+ // match: (CMPLconst x [0])
+ // cond:
+ // result: (TESTL x x)
+ for {
+ x := v.Args[0]
+ if v.AuxInt != 0 {
+ break
+ }
+ v.reset(OpAMD64TESTL)
+ v.AddArg(x)
+ v.AddArg(x)
+ return true
+ }
return false
}
func rewriteValueAMD64_OpAMD64CMPQ(v *Value, config *Config) bool {
v.AddArg(x)
return true
}
+ // match: (CMPQconst x [0])
+ // cond:
+ // result: (TESTQ x x)
+ for {
+ x := v.Args[0]
+ if v.AuxInt != 0 {
+ break
+ }
+ v.reset(OpAMD64TESTQ)
+ v.AddArg(x)
+ v.AddArg(x)
+ return true
+ }
return false
}
func rewriteValueAMD64_OpAMD64CMPW(v *Value, config *Config) bool {
v.AddArg(x)
return true
}
+ // match: (CMPWconst x [0])
+ // cond:
+ // result: (TESTW x x)
+ for {
+ x := v.Args[0]
+ if v.AuxInt != 0 {
+ break
+ }
+ v.reset(OpAMD64TESTW)
+ v.AddArg(x)
+ v.AddArg(x)
+ return true
+ }
return false
}
func rewriteValueAMD64_OpClosureCall(v *Value, config *Config) bool {