Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e6c2e12

Browse files
committed
cmd/compile/internal/ssa: optimise more branches with zero on riscv64
Optimise more branches with zero on riscv64. In particular, BLTU with zero occurs with IsInBounds checks for index zero. This currently results in two instructions and requires an additional register: li t2, 0 bltu t2, t1, 0x174b4 This is equivalent to checking if the bounds is not equal to zero. With this change: bnez t1, 0x174c0 This removes more than 500 instructions from the Go binary on riscv64. Change-Id: I6cd861d853e3ef270bd46dacecdfaa205b1c4644 Reviewed-on: https://go-review.googlesource.com/c/go/+/606715 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Meng Zhuo <mengzhuo1203@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
1 parent cfc784a commit e6c2e12

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

‎src/cmd/compile/internal/ssa/_gen/RISCV64.rules‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -558,14 +558,16 @@
558558
(BNEZ (SLTIU [x] y) yes no) => (BLTU y (MOVDconst [x]) yes no)
559559

560560
// Convert branch with zero to more optimal branch zero.
561-
(BEQ (MOVDconst [0]) cond yes no) => (BEQZ cond yes no)
562-
(BEQ cond (MOVDconst [0]) yes no) => (BEQZ cond yes no)
563-
(BNE (MOVDconst [0]) cond yes no) => (BNEZ cond yes no)
564-
(BNE cond (MOVDconst [0]) yes no) => (BNEZ cond yes no)
565-
(BLT (MOVDconst [0]) cond yes no) => (BGTZ cond yes no)
566-
(BLT cond (MOVDconst [0]) yes no) => (BLTZ cond yes no)
567-
(BGE (MOVDconst [0]) cond yes no) => (BLEZ cond yes no)
568-
(BGE cond (MOVDconst [0]) yes no) => (BGEZ cond yes no)
561+
(BEQ (MOVDconst [0]) cond yes no) => (BEQZ cond yes no)
562+
(BEQ cond (MOVDconst [0]) yes no) => (BEQZ cond yes no)
563+
(BNE (MOVDconst [0]) cond yes no) => (BNEZ cond yes no)
564+
(BNE cond (MOVDconst [0]) yes no) => (BNEZ cond yes no)
565+
(BLT (MOVDconst [0]) cond yes no) => (BGTZ cond yes no)
566+
(BLT cond (MOVDconst [0]) yes no) => (BLTZ cond yes no)
567+
(BLTU (MOVDconst [0]) cond yes no) => (BNEZ cond yes no)
568+
(BGE (MOVDconst [0]) cond yes no) => (BLEZ cond yes no)
569+
(BGE cond (MOVDconst [0]) yes no) => (BGEZ cond yes no)
570+
(BGEU (MOVDconst [0]) cond yes no) => (BEQZ cond yes no)
569571

570572
// Remove redundant NEG from SEQZ/SNEZ.
571573
(SEQZ (NEG x)) => (SEQZ x)

‎src/cmd/compile/internal/ssa/rewriteRISCV64.go‎

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎test/codegen/compare_and_branch.go‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,4 +241,14 @@ func ui64x0(x chan uint64) {
241241
for <-x < 1 {
242242
dummy()
243243
}
244+
245+
// riscv64:"BNEZ"
246+
for 0 < <-x {
247+
dummy()
248+
}
249+
250+
// riscv64:"BEQZ"
251+
for 0 >= <-x {
252+
dummy()
253+
}
244254
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /