mirror of
https://github.com/golang/go.git
synced 2026-01-29 07:02:05 +03:00
cmd/compile: fold boolean NOT into branches
Gets rid of an EOR $1 instruction. Change-Id: Ib032b0cee9ac484329c978af9b1305446f8d5dac Reviewed-on: https://go-review.googlesource.com/c/go/+/721501 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Junyang Shao <shaojunyang@google.com> Reviewed-by: Keith Randall <khr@google.com>
This commit is contained in:
@@ -573,6 +573,8 @@
|
||||
(TBNZ [0] (GreaterThanF cc) yes no) => (FGT cc yes no)
|
||||
(TBNZ [0] (GreaterEqualF cc) yes no) => (FGE cc yes no)
|
||||
|
||||
(TB(Z|NZ) [0] (XORconst [1] x) yes no) => (TB(NZ|Z) [0] x yes no)
|
||||
|
||||
((EQ|NE|LT|LE|GT|GE) (CMPconst [0] z:(AND x y)) yes no) && z.Uses == 1 => ((EQ|NE|LT|LE|GT|GE) (TST x y) yes no)
|
||||
((EQ|NE|LT|LE|GT|GE) (CMPconst [0] x:(ANDconst [c] y)) yes no) && x.Uses == 1 => ((EQ|NE|LT|LE|GT|GE) (TSTconst [c] y) yes no)
|
||||
((EQ|NE|LT|LE|GT|GE) (CMPWconst [0] z:(AND x y)) yes no) && z.Uses == 1 => ((EQ|NE|LT|LE|GT|GE) (TSTW x y) yes no)
|
||||
|
||||
@@ -25321,6 +25321,37 @@ func rewriteBlockARM64(b *Block) bool {
|
||||
b.resetWithControl(BlockARM64FGE, cc)
|
||||
return true
|
||||
}
|
||||
// match: (TBNZ [0] (XORconst [1] x) yes no)
|
||||
// result: (TBZ [0] x yes no)
|
||||
for b.Controls[0].Op == OpARM64XORconst {
|
||||
v_0 := b.Controls[0]
|
||||
if auxIntToInt64(v_0.AuxInt) != 1 {
|
||||
break
|
||||
}
|
||||
x := v_0.Args[0]
|
||||
if auxIntToInt64(b.AuxInt) != 0 {
|
||||
break
|
||||
}
|
||||
b.resetWithControl(BlockARM64TBZ, x)
|
||||
b.AuxInt = int64ToAuxInt(0)
|
||||
return true
|
||||
}
|
||||
case BlockARM64TBZ:
|
||||
// match: (TBZ [0] (XORconst [1] x) yes no)
|
||||
// result: (TBNZ [0] x yes no)
|
||||
for b.Controls[0].Op == OpARM64XORconst {
|
||||
v_0 := b.Controls[0]
|
||||
if auxIntToInt64(v_0.AuxInt) != 1 {
|
||||
break
|
||||
}
|
||||
x := v_0.Args[0]
|
||||
if auxIntToInt64(b.AuxInt) != 0 {
|
||||
break
|
||||
}
|
||||
b.resetWithControl(BlockARM64TBNZ, x)
|
||||
b.AuxInt = int64ToAuxInt(0)
|
||||
return true
|
||||
}
|
||||
case BlockARM64UGE:
|
||||
// match: (UGE (FlagConstant [fc]) yes no)
|
||||
// cond: fc.uge()
|
||||
|
||||
@@ -313,3 +313,18 @@ func constantWrite(b bool, p *bool) {
|
||||
*p = b
|
||||
}
|
||||
}
|
||||
|
||||
func boolCompare1(p, q *bool) int {
|
||||
// arm64:-"EOR [$]1"
|
||||
if *p == *q {
|
||||
return 5
|
||||
}
|
||||
return 7
|
||||
}
|
||||
func boolCompare2(p, q *bool) int {
|
||||
// arm64:-"EOR [$]1"
|
||||
if *p != *q {
|
||||
return 5
|
||||
}
|
||||
return 7
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user