Commit 5876627594 for qemu.org

commit 5876627594cb372a93e4eab178c95213473f2597
Author: Richard Henderson <richard.henderson@linaro.org>
Date:   Sun Sep 13 22:54:48 2026 +0000

    tcg/riscv64: Adjust sign of lui immediate in tcg_out_movi

    No real bug fix here, as we've already shown the full value
    fits in int32_t, but simple subtraction in tcg_target_long
    may produce a positive out-of-range intermediate.

    Reviewed-by: Max Chou <max.chou@sifive.com>
    Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
    Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

diff --git a/tcg/riscv64/tcg-target.c.inc b/tcg/riscv64/tcg-target.c.inc
index 1ed87646e0..247b4a6a60 100644
--- a/tcg/riscv64/tcg-target.c.inc
+++ b/tcg/riscv64/tcg-target.c.inc
@@ -789,21 +789,22 @@ static bool tcg_out_mov(TCGContext *s, TCGType type, TCGReg ret, TCGReg arg)
 static void tcg_out_movi(TCGContext *s, TCGType type, TCGReg rd,
                          tcg_target_long val)
 {
-    tcg_target_long lo, hi, tmp;
+    tcg_target_long tmp;
+    int32_t lo, hi;
     int shift, ret;

     if (type == TCG_TYPE_I32) {
         val = (int32_t)val;
     }

-    lo = sextreg(val, 0, 12);
+    lo = sextract32(val, 0, 12);
     if (val == lo) {
         tcg_out_opc_imm(s, OPC_ADDI, rd, TCG_REG_ZERO, lo);
         return;
     }

-    hi = val - lo;
     if (val == (int32_t)val) {
+        hi = val - lo;
         tcg_out_opc_upper(s, OPC_LUI, rd, hi);
         if (lo != 0) {
             tcg_out_opc_imm(s, OPC_ADDIW, rd, rd, lo);