From 13d5ca42fdbbbd4e3f104928f945a266642857dd Mon Sep 17 00:00:00 2001 From: Joel Sing Date: Mon, 28 Aug 2023 02:14:22 +1000 Subject: [PATCH] cmd/internal/obj/riscv: simplify instructionsForMOV 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 Reviewed-by: Cherry Mui Run-TryBot: Joel Sing Reviewed-by: Dmitri Shuralyov Reviewed-by: Mark Ryan TryBot-Result: Gopher Robot --- src/cmd/internal/obj/riscv/obj.go | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/cmd/internal/obj/riscv/obj.go b/src/cmd/internal/obj/riscv/obj.go index 776c3a8df6..36812833a9 100644 --- a/src/cmd/internal/obj/riscv/obj.go +++ b/src/cmd/internal/obj/riscv/obj.go @@ -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) -- 2.50.0