mirror of
https://github.com/golang/go
synced 2024-11-26 20:01:19 -07:00
cmd/compile: convert branch with zero to more optimal branch zero on riscv64
Convert BLT and BGE with a zero valued constant to BGTZ/BLTZ/BLEZ/BGEZ as appropriate. Removes over 4,500 instructions from the go binary on riscv64. Change-Id: Icc266e968b126ba04863ec88529630a9dd44498b Reviewed-on: https://go-review.googlesource.com/c/go/+/342849 Trust: Joel Sing <joel@sing.id.au> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
parent
dcee007aad
commit
bcd146d398
@ -596,11 +596,15 @@
|
||||
(BEQZ (SLTU x y) yes no) => (BGEU x y yes no)
|
||||
(BNEZ (SLTU x y) yes no) => (BLTU x y yes no)
|
||||
|
||||
// Convert branch with zero to BEQZ/BNEZ.
|
||||
// Convert branch with zero to more optimal branch zero.
|
||||
(BEQ (MOVDconst [0]) cond yes no) => (BEQZ cond yes no)
|
||||
(BEQ cond (MOVDconst [0]) yes no) => (BEQZ cond yes no)
|
||||
(BNE (MOVDconst [0]) cond yes no) => (BNEZ cond yes no)
|
||||
(BNE cond (MOVDconst [0]) yes no) => (BNEZ cond yes no)
|
||||
(BLT (MOVDconst [0]) cond yes no) => (BGTZ cond yes no)
|
||||
(BLT cond (MOVDconst [0]) yes no) => (BLTZ cond yes no)
|
||||
(BGE (MOVDconst [0]) cond yes no) => (BLEZ cond yes no)
|
||||
(BGE cond (MOVDconst [0]) yes no) => (BGEZ cond yes no)
|
||||
|
||||
// Store zero
|
||||
(MOVBstore [off] {sym} ptr (MOVDconst [0]) mem) => (MOVBstorezero [off] {sym} ptr mem)
|
||||
|
@ -6129,6 +6129,52 @@ func rewriteBlockRISCV64(b *Block) bool {
|
||||
b.resetWithControl2(BlockRISCV64BGEU, x, y)
|
||||
return true
|
||||
}
|
||||
case BlockRISCV64BGE:
|
||||
// match: (BGE (MOVDconst [0]) cond yes no)
|
||||
// result: (BLEZ cond yes no)
|
||||
for b.Controls[0].Op == OpRISCV64MOVDconst {
|
||||
v_0 := b.Controls[0]
|
||||
if auxIntToInt64(v_0.AuxInt) != 0 {
|
||||
break
|
||||
}
|
||||
cond := b.Controls[1]
|
||||
b.resetWithControl(BlockRISCV64BLEZ, cond)
|
||||
return true
|
||||
}
|
||||
// match: (BGE cond (MOVDconst [0]) yes no)
|
||||
// result: (BGEZ cond yes no)
|
||||
for b.Controls[1].Op == OpRISCV64MOVDconst {
|
||||
cond := b.Controls[0]
|
||||
v_1 := b.Controls[1]
|
||||
if auxIntToInt64(v_1.AuxInt) != 0 {
|
||||
break
|
||||
}
|
||||
b.resetWithControl(BlockRISCV64BGEZ, cond)
|
||||
return true
|
||||
}
|
||||
case BlockRISCV64BLT:
|
||||
// match: (BLT (MOVDconst [0]) cond yes no)
|
||||
// result: (BGTZ cond yes no)
|
||||
for b.Controls[0].Op == OpRISCV64MOVDconst {
|
||||
v_0 := b.Controls[0]
|
||||
if auxIntToInt64(v_0.AuxInt) != 0 {
|
||||
break
|
||||
}
|
||||
cond := b.Controls[1]
|
||||
b.resetWithControl(BlockRISCV64BGTZ, cond)
|
||||
return true
|
||||
}
|
||||
// match: (BLT cond (MOVDconst [0]) yes no)
|
||||
// result: (BLTZ cond yes no)
|
||||
for b.Controls[1].Op == OpRISCV64MOVDconst {
|
||||
cond := b.Controls[0]
|
||||
v_1 := b.Controls[1]
|
||||
if auxIntToInt64(v_1.AuxInt) != 0 {
|
||||
break
|
||||
}
|
||||
b.resetWithControl(BlockRISCV64BLTZ, cond)
|
||||
return true
|
||||
}
|
||||
case BlockRISCV64BNE:
|
||||
// match: (BNE (MOVDconst [0]) cond yes no)
|
||||
// result: (BNEZ cond yes no)
|
||||
|
Loading…
Reference in New Issue
Block a user