On Sun, 2026-09-13 at 14:08 -1000, Richard Henderson wrote:
> 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.
> 
> Signed-off-by: Richard Henderson <[email protected]>

Reviewed-by: Alistair Francis <[email protected]>

Alistair

> ---
>  tcg/riscv64/tcg-target.c.inc | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/tcg/riscv64/tcg-target.c.inc b/tcg/riscv64/tcg-
> target.c.inc
> index 99bc658c264..d0c9d8e9cd2 100644
> --- a/tcg/riscv64/tcg-target.c.inc
> +++ b/tcg/riscv64/tcg-target.c.inc
> @@ -792,21 +792,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);

Reply via email to