aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile
diff options
context:
space:
mode:
authorJoel Sing <joel@sing.id.au>2026-02-21 03:29:09 +1100
committerGopher Robot <gobot@golang.org>2026-03-06 14:39:32 -0800
commit3a29ebeef985efb12d2b8670f50b146e9a2815ca (patch)
treee08894e3c63d59cdff57ccdaf8d71cf4a0505f54 /src/cmd/compile
parent426ea5cd22d8de6b1ed909062c624fd1e6e04757 (diff)
downloadgo-3a29ebeef985efb12d2b8670f50b146e9a2815ca.tar.xz
cmd/compile: additional optimisation for CZEROEQZ/CZERONEZ on riscv64
Negation on a condition can be eliminated. Change-Id: I94fab5f019cbaebb2ca589e1d8796a9cb72f3894 Reviewed-on: https://go-review.googlesource.com/c/go/+/748401 Reviewed-by: Xueqi Luo <1824368278@qq.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Julian Zhu <jz531210@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/cmd/compile')
-rw-r--r--src/cmd/compile/internal/ssa/_gen/RISCV64.rules1
-rw-r--r--src/cmd/compile/internal/ssa/rewriteRISCV64.go24
2 files changed, 25 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/_gen/RISCV64.rules b/src/cmd/compile/internal/ssa/_gen/RISCV64.rules
index 06130d242d..9e3911ea0c 100644
--- a/src/cmd/compile/internal/ssa/_gen/RISCV64.rules
+++ b/src/cmd/compile/internal/ssa/_gen/RISCV64.rules
@@ -866,6 +866,7 @@
(OR (CZEROEQZ <t> x (MOVBUreg <typ.UInt64> cond)) (CZERONEZ <t> y (MOVBUreg <typ.UInt64> cond)))
(CZERO(EQ|NE)Z x (SNEZ y)) => (CZERO(EQ|NE)Z x y)
(CZERO(EQ|NE)Z x (SEQZ y)) => (CZERO(NE|EQ)Z x y)
+(CZERO(EQ|NE)Z x (NEG y)) => (CZERO(EQ|NE)Z x y)
(CZEROEQZ x x) => x
(CZERONEZ x x) => (MOVDconst [0])
(CZERO(EQ|NE)Z (MOVDconst [0]) _) => (MOVDconst [0])
diff --git a/src/cmd/compile/internal/ssa/rewriteRISCV64.go b/src/cmd/compile/internal/ssa/rewriteRISCV64.go
index 1700604422..d5c52c5eb1 100644
--- a/src/cmd/compile/internal/ssa/rewriteRISCV64.go
+++ b/src/cmd/compile/internal/ssa/rewriteRISCV64.go
@@ -3588,6 +3588,18 @@ func rewriteValueRISCV64_OpRISCV64CZEROEQZ(v *Value) bool {
v.AddArg2(x, y)
return true
}
+ // match: (CZEROEQZ x (NEG y))
+ // result: (CZEROEQZ x y)
+ for {
+ x := v_0
+ if v_1.Op != OpRISCV64NEG {
+ break
+ }
+ y := v_1.Args[0]
+ v.reset(OpRISCV64CZEROEQZ)
+ v.AddArg2(x, y)
+ return true
+ }
// match: (CZEROEQZ x x)
// result: x
for {
@@ -3637,6 +3649,18 @@ func rewriteValueRISCV64_OpRISCV64CZERONEZ(v *Value) bool {
v.AddArg2(x, y)
return true
}
+ // match: (CZERONEZ x (NEG y))
+ // result: (CZERONEZ x y)
+ for {
+ x := v_0
+ if v_1.Op != OpRISCV64NEG {
+ break
+ }
+ y := v_1.Args[0]
+ v.reset(OpRISCV64CZERONEZ)
+ v.AddArg2(x, y)
+ return true
+ }
// match: (CZERONEZ x x)
// result: (MOVDconst [0])
for {