[PATCH 1/5] tcg: Simplify extract2 usage in tcg_gen_shifti_i64

Richard Henderson posted 5 patches 1 month, 2 weeks ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>
[PATCH 1/5] tcg: Simplify extract2 usage in tcg_gen_shifti_i64
Posted by Richard Henderson 1 month, 2 weeks ago
The else after the TCG_TARGET_HAS_extract2 test is exactly
the same as what tcg_gen_extract2_i32 would emit itself.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 tcg/tcg-op.c | 22 ++++------------------
 1 file changed, 4 insertions(+), 18 deletions(-)

diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index dfa5c38728..ab7b409be6 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -1818,30 +1818,16 @@ static inline void tcg_gen_shifti_i64(TCGv_i64 ret, TCGv_i64 arg1,
             tcg_gen_movi_i32(TCGV_LOW(ret), 0);
         }
     } else if (right) {
-        if (tcg_op_supported(INDEX_op_extract2, TCG_TYPE_I32, 0)) {
-            tcg_gen_extract2_i32(TCGV_LOW(ret),
-                                 TCGV_LOW(arg1), TCGV_HIGH(arg1), c);
-        } else {
-            tcg_gen_shri_i32(TCGV_LOW(ret), TCGV_LOW(arg1), c);
-            tcg_gen_deposit_i32(TCGV_LOW(ret), TCGV_LOW(ret),
-                                TCGV_HIGH(arg1), 32 - c, c);
-        }
+        tcg_gen_extract2_i32(TCGV_LOW(ret), TCGV_LOW(arg1),
+                             TCGV_HIGH(arg1), c);
         if (arith) {
             tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), c);
         } else {
             tcg_gen_shri_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), c);
         }
     } else {
-        if (tcg_op_supported(INDEX_op_extract2, TCG_TYPE_I32, 0)) {
-            tcg_gen_extract2_i32(TCGV_HIGH(ret),
-                                 TCGV_LOW(arg1), TCGV_HIGH(arg1), 32 - c);
-        } else {
-            TCGv_i32 t0 = tcg_temp_ebb_new_i32();
-            tcg_gen_shri_i32(t0, TCGV_LOW(arg1), 32 - c);
-            tcg_gen_deposit_i32(TCGV_HIGH(ret), t0,
-                                TCGV_HIGH(arg1), c, 32 - c);
-            tcg_temp_free_i32(t0);
-        }
+        tcg_gen_extract2_i32(TCGV_HIGH(ret), TCGV_LOW(arg1),
+                             TCGV_HIGH(arg1), 32 - c);
         tcg_gen_shli_i32(TCGV_LOW(ret), TCGV_LOW(arg1), c);
     }
 }
-- 
2.43.0
Re: [PATCH 1/5] tcg: Simplify extract2 usage in tcg_gen_shifti_i64
Posted by Philippe Mathieu-Daudé 2 weeks, 2 days ago
On 28/9/25 18:31, Richard Henderson wrote:
> The else after the TCG_TARGET_HAS_extract2 test is exactly
> the same as what tcg_gen_extract2_i32 would emit itself.

Not /exactly/, since tcg_gen_extract2_i32() even optimize
for ofs=={0, 32} or aL==aH, so this cleanup is even better.

> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   tcg/tcg-op.c | 22 ++++------------------
>   1 file changed, 4 insertions(+), 18 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>


Re: [PATCH 1/5] tcg: Simplify extract2 usage in tcg_gen_shifti_i64
Posted by Manos Pitsidianakis 2 weeks, 2 days ago
On Sun, Sep 28, 2025 at 7:33 PM Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> The else after the TCG_TARGET_HAS_extract2 test is exactly
> the same as what tcg_gen_extract2_i32 would emit itself.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---

Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>

>  tcg/tcg-op.c | 22 ++++------------------
>  1 file changed, 4 insertions(+), 18 deletions(-)
>
> diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
> index dfa5c38728..ab7b409be6 100644
> --- a/tcg/tcg-op.c
> +++ b/tcg/tcg-op.c
> @@ -1818,30 +1818,16 @@ static inline void tcg_gen_shifti_i64(TCGv_i64 ret, TCGv_i64 arg1,
>              tcg_gen_movi_i32(TCGV_LOW(ret), 0);
>          }
>      } else if (right) {
> -        if (tcg_op_supported(INDEX_op_extract2, TCG_TYPE_I32, 0)) {
> -            tcg_gen_extract2_i32(TCGV_LOW(ret),
> -                                 TCGV_LOW(arg1), TCGV_HIGH(arg1), c);
> -        } else {
> -            tcg_gen_shri_i32(TCGV_LOW(ret), TCGV_LOW(arg1), c);
> -            tcg_gen_deposit_i32(TCGV_LOW(ret), TCGV_LOW(ret),
> -                                TCGV_HIGH(arg1), 32 - c, c);
> -        }
> +        tcg_gen_extract2_i32(TCGV_LOW(ret), TCGV_LOW(arg1),
> +                             TCGV_HIGH(arg1), c);
>          if (arith) {
>              tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), c);
>          } else {
>              tcg_gen_shri_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), c);
>          }
>      } else {
> -        if (tcg_op_supported(INDEX_op_extract2, TCG_TYPE_I32, 0)) {
> -            tcg_gen_extract2_i32(TCGV_HIGH(ret),
> -                                 TCGV_LOW(arg1), TCGV_HIGH(arg1), 32 - c);
> -        } else {
> -            TCGv_i32 t0 = tcg_temp_ebb_new_i32();
> -            tcg_gen_shri_i32(t0, TCGV_LOW(arg1), 32 - c);
> -            tcg_gen_deposit_i32(TCGV_HIGH(ret), t0,
> -                                TCGV_HIGH(arg1), c, 32 - c);
> -            tcg_temp_free_i32(t0);
> -        }
> +        tcg_gen_extract2_i32(TCGV_HIGH(ret), TCGV_LOW(arg1),
> +                             TCGV_HIGH(arg1), 32 - c);
>          tcg_gen_shli_i32(TCGV_LOW(ret), TCGV_LOW(arg1), c);
>      }
>  }
> --
> 2.43.0
>
>