]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: remove redundant SEQZ/SNEZ on riscv64
authorJoel Sing <joel@sing.id.au>
Sat, 27 Aug 2022 20:11:43 +0000 (06:11 +1000)
committerJoel Sing <joel@sing.id.au>
Wed, 7 Sep 2022 05:39:23 +0000 (05:39 +0000)
In particular, (SEQZ (SNEZ x)) can arise from (Not (IsNonNil x)).

Change-Id: Ie249cd1934d71087e0f774cf8f6c937ceeed7ad5
Reviewed-on: https://go-review.googlesource.com/c/go/+/428215
Run-TryBot: Joel Sing <joel@sing.id.au>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Wayne Zuo <wdvxdr@golangcn.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/cmd/compile/internal/ssa/gen/RISCV64.rules
src/cmd/compile/internal/ssa/rewriteRISCV64.go

index 385f004b225504e1ee970360e7d2307a1111725f..fd5bfd36c6d8bb3a85a156f3c5f627795f505580 100644 (file)
 (BNEZ (SEQZ x) yes no) => (BEQZ x yes no)
 (BNEZ (SNEZ x) yes no) => (BNEZ x yes no)
 
-// Absorb NEG into branch.
+// Remove redundant NEG from BEQZ/BNEZ.
 (BEQZ (NEG x) yes no) => (BEQZ x yes no)
 (BNEZ (NEG x) yes no) => (BNEZ x yes no)
 
 (BGE (MOVDconst [0]) cond yes no) => (BLEZ cond yes no)
 (BGE cond (MOVDconst [0]) yes no) => (BGEZ cond yes no)
 
-// Remove NEG when used with SEQZ/SNEZ.
+// Remove redundant NEG from SEQZ/SNEZ.
 (SEQZ (NEG x)) => (SEQZ x)
 (SNEZ (NEG x)) => (SNEZ x)
 
-// Store zero
+// Remove redundant SEQZ/SNEZ.
+(SEQZ (SEQZ x)) => (SNEZ x)
+(SEQZ (SNEZ x)) => (SEQZ x)
+(SNEZ (SEQZ x)) => (SEQZ x)
+(SNEZ (SNEZ x)) => (SNEZ x)
+
+// Store zero.
 (MOVBstore [off] {sym} ptr (MOVDconst [0]) mem) => (MOVBstorezero [off] {sym} ptr mem)
 (MOVHstore [off] {sym} ptr (MOVDconst [0]) mem) => (MOVHstorezero [off] {sym} ptr mem)
 (MOVWstore [off] {sym} ptr (MOVDconst [0]) mem) => (MOVWstorezero [off] {sym} ptr mem)
index ac0770639eab0e12feb9be322d456dd84004e6e1..66b729f046591c629653c79c1163ee46db10880b 100644 (file)
@@ -5350,6 +5350,28 @@ func rewriteValueRISCV64_OpRISCV64SEQZ(v *Value) bool {
                v.AddArg(x)
                return true
        }
+       // match: (SEQZ (SEQZ x))
+       // result: (SNEZ x)
+       for {
+               if v_0.Op != OpRISCV64SEQZ {
+                       break
+               }
+               x := v_0.Args[0]
+               v.reset(OpRISCV64SNEZ)
+               v.AddArg(x)
+               return true
+       }
+       // match: (SEQZ (SNEZ x))
+       // result: (SEQZ x)
+       for {
+               if v_0.Op != OpRISCV64SNEZ {
+                       break
+               }
+               x := v_0.Args[0]
+               v.reset(OpRISCV64SEQZ)
+               v.AddArg(x)
+               return true
+       }
        return false
 }
 func rewriteValueRISCV64_OpRISCV64SLL(v *Value) bool {
@@ -5467,6 +5489,28 @@ func rewriteValueRISCV64_OpRISCV64SNEZ(v *Value) bool {
                v.AddArg(x)
                return true
        }
+       // match: (SNEZ (SEQZ x))
+       // result: (SEQZ x)
+       for {
+               if v_0.Op != OpRISCV64SEQZ {
+                       break
+               }
+               x := v_0.Args[0]
+               v.reset(OpRISCV64SEQZ)
+               v.AddArg(x)
+               return true
+       }
+       // match: (SNEZ (SNEZ x))
+       // result: (SNEZ x)
+       for {
+               if v_0.Op != OpRISCV64SNEZ {
+                       break
+               }
+               x := v_0.Args[0]
+               v.reset(OpRISCV64SNEZ)
+               v.AddArg(x)
+               return true
+       }
        return false
 }
 func rewriteValueRISCV64_OpRISCV64SRA(v *Value) bool {