]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj/riscv: simplify instructionsForMOV
authorJoel Sing <joel@sing.id.au>
Sun, 27 Aug 2023 16:14:22 +0000 (02:14 +1000)
committerJoel Sing <joel@sing.id.au>
Fri, 8 Sep 2023 04:20:37 +0000 (04:20 +0000)
Rather than handling shift based scaling in two locations, rework logic
so there is a single exit path.

Change-Id: I832b4932d53183736050059a11019ced08281b3b
Reviewed-on: https://go-review.googlesource.com/c/go/+/523455
Reviewed-by: M Zhuo <mzh@golangcn.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Joel Sing <joel@sing.id.au>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Mark Ryan <markdryan@rivosinc.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/internal/obj/riscv/obj.go

index 776c3a8df60f18a147fd2ccdaa7a05985622889b..36812833a9358d64c8e75a23a8efcd9812ad7505 100644 (file)
@@ -1992,20 +1992,15 @@ func instructionsForMOV(p *obj.Prog) []*instruction {
                ins.as, ins.rs1, ins.rs2, ins.imm = AADDI, REG_ZERO, obj.REG_NONE, low
 
                // LUI is only necessary if the constant does not fit in 12 bits.
-               if high == 0 {
-                       if insSLLI != nil {
-                               inss = append(inss, insSLLI)
+               if high != 0 {
+                       // LUI top20bits(c), R
+                       // ADD bottom12bits(c), R, R
+                       insLUI := &instruction{as: ALUI, rd: ins.rd, imm: high}
+                       inss = []*instruction{insLUI}
+                       if low != 0 {
+                               ins.as, ins.rs1 = AADDIW, ins.rd
+                               inss = append(inss, ins)
                        }
-                       break
-               }
-
-               // LUI top20bits(c), R
-               // ADD bottom12bits(c), R, R
-               insLUI := &instruction{as: ALUI, rd: ins.rd, imm: high}
-               inss = []*instruction{insLUI}
-               if low != 0 {
-                       ins.as, ins.rs1 = AADDIW, ins.rd
-                       inss = append(inss, ins)
                }
                if insSLLI != nil {
                        inss = append(inss, insSLLI)