From: Joel Sing Date: Sat, 27 Aug 2022 20:11:43 +0000 (+1000) Subject: cmd/compile: remove redundant SEQZ/SNEZ on riscv64 X-Git-Tag: go1.20rc1~1154 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=77da976419ebef9beec480e86202db7a32ebd181;p=gostls13.git 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 Reviewed-by: Cherry Mui Reviewed-by: Wayne Zuo TryBot-Result: Gopher Robot Reviewed-by: Michael Knyszek --- 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 {