mirror of https://github.com/golang/go.git
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
|
// Boolean ops; 0=false, 1=true
|
||||||
(AndB ...) => (AND ...)
|
(AndB ...) => (AND ...)
|
||||||
(OrB ...) => (OR ...)
|
(OrB ...) => (OR ...)
|
||||||
(EqB x y) => (SEQZ (XOR <typ.Bool> x y))
|
(EqB x y) => (SEQZ (SUB <typ.Bool> x y))
|
||||||
(NeqB ...) => (XOR ...)
|
(NeqB x y) => (SNEZ (SUB <typ.Bool> x y))
|
||||||
(Not ...) => (SEQZ ...)
|
(Not ...) => (SEQZ ...)
|
||||||
|
|
||||||
// Lowering pointer arithmetic
|
// Lowering pointer arithmetic
|
||||||
|
|
|
||||||
|
|
@ -406,8 +406,7 @@ func rewriteValueRISCV64(v *Value) bool {
|
||||||
case OpNeq8:
|
case OpNeq8:
|
||||||
return rewriteValueRISCV64_OpNeq8(v)
|
return rewriteValueRISCV64_OpNeq8(v)
|
||||||
case OpNeqB:
|
case OpNeqB:
|
||||||
v.Op = OpRISCV64XOR
|
return rewriteValueRISCV64_OpNeqB(v)
|
||||||
return true
|
|
||||||
case OpNeqPtr:
|
case OpNeqPtr:
|
||||||
return rewriteValueRISCV64_OpNeqPtr(v)
|
return rewriteValueRISCV64_OpNeqPtr(v)
|
||||||
case OpNilCheck:
|
case OpNilCheck:
|
||||||
|
|
@ -1121,12 +1120,12 @@ func rewriteValueRISCV64_OpEqB(v *Value) bool {
|
||||||
b := v.Block
|
b := v.Block
|
||||||
typ := &b.Func.Config.Types
|
typ := &b.Func.Config.Types
|
||||||
// match: (EqB x y)
|
// match: (EqB x y)
|
||||||
// result: (SEQZ (XOR <typ.Bool> x y))
|
// result: (SEQZ (SUB <typ.Bool> x y))
|
||||||
for {
|
for {
|
||||||
x := v_0
|
x := v_0
|
||||||
y := v_1
|
y := v_1
|
||||||
v.reset(OpRISCV64SEQZ)
|
v.reset(OpRISCV64SEQZ)
|
||||||
v0 := b.NewValue0(v.Pos, OpRISCV64XOR, typ.Bool)
|
v0 := b.NewValue0(v.Pos, OpRISCV64SUB, typ.Bool)
|
||||||
v0.AddArg2(x, y)
|
v0.AddArg2(x, y)
|
||||||
v.AddArg(v0)
|
v.AddArg(v0)
|
||||||
return true
|
return true
|
||||||
|
|
@ -2970,6 +2969,23 @@ func rewriteValueRISCV64_OpNeq8(v *Value) bool {
|
||||||
return true
|
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 {
|
func rewriteValueRISCV64_OpNeqPtr(v *Value) bool {
|
||||||
v_1 := v.Args[1]
|
v_1 := v.Args[1]
|
||||||
v_0 := v.Args[0]
|
v_0 := v.Args[0]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue