[PATCH v2 40/51] tcg/optimize: Canonicalize s_mask in fold_exts, fold_sextract

Richard Henderson posted 51 patches 3 days, 19 hours ago
There is a newer version of this series
[PATCH v2 40/51] tcg/optimize: Canonicalize s_mask in fold_exts, fold_sextract
Posted by Richard Henderson 3 days, 19 hours ago
Simply or'ing the an input s_mask with the mask implied by
the sign extension operation may leave disconnected bits
to the right.  Use smask_from_smask to canonicalize.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 tcg/optimize.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tcg/optimize.c b/tcg/optimize.c
index d0a9ea1ee4..8735dc0c9c 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -1827,6 +1827,7 @@ static bool fold_exts(OptContext *ctx, TCGOp *op)
         g_assert_not_reached();
     }
     s_mask |= sign << 1;
+    s_mask = smask_from_smask(s_mask);
 
     if (!type_change && fold_affected_mask(ctx, op, s_mask & ~s_mask_old)) {
         return true;
@@ -2534,8 +2535,13 @@ static bool fold_sextract(OptContext *ctx, TCGOp *op)
     }
 
     s_mask_old = t1->s_mask;
+    /*
+     * Use the sign mask from the input, force the repetitons from
+     * the sign extension operation, and canonicalize the result.
+     */
     s_mask = sextract64(s_mask_old, pos, len);
     s_mask |= MAKE_64BIT_MASK(len, 64 - len);
+    s_mask = smask_from_smask(s_mask);
 
     if (pos == 0 && fold_affected_mask(ctx, op, s_mask & ~s_mask_old)) {
         return true;
-- 
2.43.0
Re: [PATCH v2 40/51] tcg/optimize: Canonicalize s_mask in fold_exts, fold_sextract
Posted by Pierrick Bouvier 3 days, 3 hours ago
On 12/19/24 20:10, Richard Henderson wrote:
> Simply or'ing the an input s_mask with the mask implied by
> the sign extension operation may leave disconnected bits
> to the right.  Use smask_from_smask to canonicalize.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   tcg/optimize.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/tcg/optimize.c b/tcg/optimize.c
> index d0a9ea1ee4..8735dc0c9c 100644
> --- a/tcg/optimize.c
> +++ b/tcg/optimize.c
> @@ -1827,6 +1827,7 @@ static bool fold_exts(OptContext *ctx, TCGOp *op)
>           g_assert_not_reached();
>       }
>       s_mask |= sign << 1;
> +    s_mask = smask_from_smask(s_mask);
>   
>       if (!type_change && fold_affected_mask(ctx, op, s_mask & ~s_mask_old)) {
>           return true;
> @@ -2534,8 +2535,13 @@ static bool fold_sextract(OptContext *ctx, TCGOp *op)
>       }
>   
>       s_mask_old = t1->s_mask;
> +    /*
> +     * Use the sign mask from the input, force the repetitons from
> +     * the sign extension operation, and canonicalize the result.
> +     */
>       s_mask = sextract64(s_mask_old, pos, len);
>       s_mask |= MAKE_64BIT_MASK(len, 64 - len);
> +    s_mask = smask_from_smask(s_mask);
>   
>       if (pos == 0 && fold_affected_mask(ctx, op, s_mask & ~s_mask_old)) {
>           return true;

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>