aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoel Sing <joel@sing.id.au>2022-08-28 06:11:43 +1000
committerJoel Sing <joel@sing.id.au>2022-09-07 05:39:23 +0000
commit77da976419ebef9beec480e86202db7a32ebd181 (patch)
tree9f02357dd7e9cc17976c54027f222191e0b37087 /src
parentb6a6847b2f33dc8fb231c78cc4d807eaf10a133a (diff)
downloadgo-77da976419ebef9beec480e86202db7a32ebd181.tar.xz
cmd/compile: remove redundant SEQZ/SNEZ on riscv64
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>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/ssa/gen/RISCV64.rules12
-rw-r--r--src/cmd/compile/internal/ssa/rewriteRISCV64.go44
2 files changed, 53 insertions, 3 deletions
diff --git a/src/cmd/compile/internal/ssa/gen/RISCV64.rules b/src/cmd/compile/internal/ssa/gen/RISCV64.rules
index 385f004b22..fd5bfd36c6 100644
--- a/src/cmd/compile/internal/ssa/gen/RISCV64.rules
+++ b/src/cmd/compile/internal/ssa/gen/RISCV64.rules
@@ -609,7 +609,7 @@
(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)
@@ -637,11 +637,17 @@
(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)
diff --git a/src/cmd/compile/internal/ssa/rewriteRISCV64.go b/src/cmd/compile/internal/ssa/rewriteRISCV64.go
index ac0770639e..66b729f046 100644
--- a/src/cmd/compile/internal/ssa/rewriteRISCV64.go
+++ b/src/cmd/compile/internal/ssa/rewriteRISCV64.go
@@ -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 {