diff options
author | Ben Shi <powerman1st@163.com> | 2021-09-02 00:06:42 +0000 |
---|---|---|
committer | Joel Sing <joel@sing.id.au> | 2021-09-02 14:35:10 +0000 |
commit | 37d4532867b9c49f936cb8e394dec44d8985fe29 (patch) | |
tree | a3e0fe2646bedfb552dd897a2262faf91c5e487f /test | |
parent | 4fb79569d2fb7a0eabc88729f400addb0162f21e (diff) | |
download | go-37d4532867b9c49f936cb8e394dec44d8985fe29.tar.gz go-37d4532867b9c49f936cb8e394dec44d8985fe29.zip |
cmd/internal/obj/riscv: simplify addition with constant
This CL simplifies riscv addition (add r, imm) to
(ADDI (ADDI r, imm/2), imm-imm/2) if imm is in specific ranges.
(-4096 <= imm <= -2049 or 2048 <= imm <= 4094)
There is little impact to the go1 benchmark, while the total
size of pkg/linux_riscv64 decreased by about 11KB.
Change-Id: I236eb8af3b83bb35ce9c0b318fc1d235e8ab9a4e
GitHub-Last-Rev: a2f56a07635344a40d6b8a9571f236743122be34
GitHub-Pull-Request: golang/go#48110
Reviewed-on: https://go-review.googlesource.com/c/go/+/346689
Run-TryBot: Ben Shi <powerman1st@163.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Joel Sing <joel@sing.id.au>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Michael Munday <mike.munday@lowrisc.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/codegen/arithmetic.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/test/codegen/arithmetic.go b/test/codegen/arithmetic.go index eb95416b6a..754c5c9bc9 100644 --- a/test/codegen/arithmetic.go +++ b/test/codegen/arithmetic.go @@ -575,3 +575,11 @@ func constantFold3(i, j int) int { r := (5 * i) * (6 * j) return r } + +func addConst(i int64) (int64, int64) { + // riscv64:`ADDI`,-`LUI` + a := i + 3001 + // riscv64:`LUI`,`ADDIW` + b := i + 5009 + return a, b +} |