]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: avoid the use of XOR for boolean equality on riscv64
authorJoel Sing <joel@sing.id.au>
Tue, 30 Aug 2022 08:59:53 +0000 (18:59 +1000)
committerJoel Sing <joel@sing.id.au>
Mon, 19 Sep 2022 19:01:06 +0000 (19:01 +0000)
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>
src/cmd/compile/internal/ssa/gen/RISCV64.rules
src/cmd/compile/internal/ssa/rewriteRISCV64.go

index c2f1c16b6bc68044e06ce11e5a5ae926c06dcd27..5c3c8625714a05dec7b093776f335c046c9cff86 100644 (file)
 // 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
index 097232ab185ea6a2ed9e7ed29d17a78ac651b4ac..05c646e4a6fd595b3b25249eccedede45383cf2d 100644 (file)
@@ -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]