mirror of
https://github.com/golang/go
synced 2024-11-17 06:04:47 -07:00
cmd/compile: avoid the use of XOR for boolean equality on riscv64
The use of SEQZ/SNEZ and SUB allows for other optimisations to be utilised, particularly absorption into branch equality conditions. Change-Id: I74e7d6a07a8decc1bdb651660c322bcc6eb6a10a Reviewed-on: https://go-review.googlesource.com/c/go/+/428216 Run-TryBot: Joel Sing <joel@sing.id.au> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Meng Zhuo <mzh@golangcn.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
parent
fd82718e06
commit
83d94daec2
@ -534,8 +534,8 @@
|
||||
// Boolean ops; 0=false, 1=true
|
||||
(AndB ...) => (AND ...)
|
||||
(OrB ...) => (OR ...)
|
||||
(EqB x y) => (SEQZ (XOR <typ.Bool> x y))
|
||||
(NeqB ...) => (XOR ...)
|
||||
(EqB x y) => (SEQZ (SUB <typ.Bool> x y))
|
||||
(NeqB x y) => (SNEZ (SUB <typ.Bool> x y))
|
||||
(Not ...) => (SEQZ ...)
|
||||
|
||||
// Lowering pointer arithmetic
|
||||
|
@ -406,8 +406,7 @@ func rewriteValueRISCV64(v *Value) bool {
|
||||
case OpNeq8:
|
||||
return rewriteValueRISCV64_OpNeq8(v)
|
||||
case OpNeqB:
|
||||
v.Op = OpRISCV64XOR
|
||||
return true
|
||||
return rewriteValueRISCV64_OpNeqB(v)
|
||||
case OpNeqPtr:
|
||||
return rewriteValueRISCV64_OpNeqPtr(v)
|
||||
case OpNilCheck:
|
||||
@ -1121,12 +1120,12 @@ func rewriteValueRISCV64_OpEqB(v *Value) bool {
|
||||
b := v.Block
|
||||
typ := &b.Func.Config.Types
|
||||
// match: (EqB x y)
|
||||
// result: (SEQZ (XOR <typ.Bool> x y))
|
||||
// result: (SEQZ (SUB <typ.Bool> x y))
|
||||
for {
|
||||
x := v_0
|
||||
y := v_1
|
||||
v.reset(OpRISCV64SEQZ)
|
||||
v0 := b.NewValue0(v.Pos, OpRISCV64XOR, typ.Bool)
|
||||
v0 := b.NewValue0(v.Pos, OpRISCV64SUB, typ.Bool)
|
||||
v0.AddArg2(x, y)
|
||||
v.AddArg(v0)
|
||||
return true
|
||||
@ -2970,6 +2969,23 @@ func rewriteValueRISCV64_OpNeq8(v *Value) bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
func rewriteValueRISCV64_OpNeqB(v *Value) bool {
|
||||
v_1 := v.Args[1]
|
||||
v_0 := v.Args[0]
|
||||
b := v.Block
|
||||
typ := &b.Func.Config.Types
|
||||
// match: (NeqB x y)
|
||||
// result: (SNEZ (SUB <typ.Bool> x y))
|
||||
for {
|
||||
x := v_0
|
||||
y := v_1
|
||||
v.reset(OpRISCV64SNEZ)
|
||||
v0 := b.NewValue0(v.Pos, OpRISCV64SUB, typ.Bool)
|
||||
v0.AddArg2(x, y)
|
||||
v.AddArg(v0)
|
||||
return true
|
||||
}
|
||||
}
|
||||
func rewriteValueRISCV64_OpNeqPtr(v *Value) bool {
|
||||
v_1 := v.Args[1]
|
||||
v_0 := v.Args[0]
|
||||
|
Loading…
Reference in New Issue
Block a user