diff mbox series

[v2,05/51] tcg/optimize: Augment s_mask from z_mask in fold_masks_zs

Message ID 20241220041104.53105-6-richard.henderson@linaro.org
State New
Headers show
Series tcg: Remove in-flight mask data from OptContext | expand

Commit Message

Richard Henderson Dec. 20, 2024, 4:10 a.m. UTC
Consider the passed s_mask to be a minimum deduced from
either existing s_mask or from a sign-extension operation.
We may be able to deduce more from the set of known zeros.
Remove identical logic from several opcode folders.

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

Comments

Pierrick Bouvier Dec. 20, 2024, 8:15 p.m. UTC | #1
On 12/19/24 20:10, Richard Henderson wrote:
> Consider the passed s_mask to be a minimum deduced from
> either existing s_mask or from a sign-extension operation.
> We may be able to deduce more from the set of known zeros.
> Remove identical logic from several opcode folders.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   tcg/optimize.c | 12 +++---------
>   1 file changed, 3 insertions(+), 9 deletions(-)
> 
> diff --git a/tcg/optimize.c b/tcg/optimize.c
> index d70127b88d..17b72fe759 100644
> --- a/tcg/optimize.c
> +++ b/tcg/optimize.c
> @@ -1048,6 +1048,7 @@ static bool fold_const2_commutative(OptContext *ctx, TCGOp *op)
>    * Record "zero" and "sign" masks for the single output of @op.
>    * See TempOptInfo definition of z_mask and s_mask.
>    * If z_mask allows, fold the output to constant zero.
> + * The passed s_mask may be augmented by z_mask.
>    */
>   static bool fold_masks_zs(OptContext *ctx, TCGOp *op,
>                             uint64_t z_mask, uint64_t s_mask)
> @@ -1080,7 +1081,7 @@ static bool fold_masks_zs(OptContext *ctx, TCGOp *op,
>   
>       ti = ts_info(ts);
>       ti->z_mask = z_mask;
> -    ti->s_mask = s_mask;
> +    ti->s_mask = s_mask | smask_from_zmask(z_mask);
>       return true;
>   }
>   
> @@ -1519,8 +1520,8 @@ static bool fold_bswap(OptContext *ctx, TCGOp *op)
>       default:
>           g_assert_not_reached();
>       }
> -    s_mask = smask_from_zmask(z_mask);
>   
> +    s_mask = 0;
>       switch (op->args[2] & (TCG_BSWAP_OZ | TCG_BSWAP_OS)) {
>       case TCG_BSWAP_OZ:
>           break;
> @@ -1534,7 +1535,6 @@ static bool fold_bswap(OptContext *ctx, TCGOp *op)
>       default:
>           /* The high bits are undefined: force all bits above the sign to 1. */
>           z_mask |= sign << 1;
> -        s_mask = 0;
>           break;
>       }
>       ctx->z_mask = z_mask;
> @@ -1605,7 +1605,6 @@ static bool fold_count_zeros(OptContext *ctx, TCGOp *op)
>           g_assert_not_reached();
>       }
>       ctx->z_mask = arg_info(op->args[2])->z_mask | z_mask;
> -    ctx->s_mask = smask_from_zmask(ctx->z_mask);
>       return false;
>   }
>   
> @@ -1625,7 +1624,6 @@ static bool fold_ctpop(OptContext *ctx, TCGOp *op)
>       default:
>           g_assert_not_reached();
>       }
> -    ctx->s_mask = smask_from_zmask(ctx->z_mask);
>       return false;
>   }
>   
> @@ -1746,7 +1744,6 @@ static bool fold_extract(OptContext *ctx, TCGOp *op)
>           return true;
>       }
>       ctx->z_mask = z_mask;
> -    ctx->s_mask = smask_from_zmask(z_mask);
>   
>       return fold_masks(ctx, op);
>   }
> @@ -1851,7 +1848,6 @@ static bool fold_extu(OptContext *ctx, TCGOp *op)
>       }
>   
>       ctx->z_mask = z_mask;
> -    ctx->s_mask = smask_from_zmask(z_mask);
>       if (!type_change && fold_affected_mask(ctx, op, z_mask_old ^ z_mask)) {
>           return true;
>       }
> @@ -2354,7 +2350,6 @@ static bool fold_setcond(OptContext *ctx, TCGOp *op)
>       fold_setcond_tst_pow2(ctx, op, false);
>   
>       ctx->z_mask = 1;
> -    ctx->s_mask = smask_from_zmask(1);
>       return false;
>   }
>   
> @@ -2455,7 +2450,6 @@ static bool fold_setcond2(OptContext *ctx, TCGOp *op)
>       }
>   
>       ctx->z_mask = 1;
> -    ctx->s_mask = smask_from_zmask(1);
>       return false;
>   
>    do_setcond_const:

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

Patch

diff --git a/tcg/optimize.c b/tcg/optimize.c
index d70127b88d..17b72fe759 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -1048,6 +1048,7 @@  static bool fold_const2_commutative(OptContext *ctx, TCGOp *op)
  * Record "zero" and "sign" masks for the single output of @op.
  * See TempOptInfo definition of z_mask and s_mask.
  * If z_mask allows, fold the output to constant zero.
+ * The passed s_mask may be augmented by z_mask.
  */
 static bool fold_masks_zs(OptContext *ctx, TCGOp *op,
                           uint64_t z_mask, uint64_t s_mask)
@@ -1080,7 +1081,7 @@  static bool fold_masks_zs(OptContext *ctx, TCGOp *op,
 
     ti = ts_info(ts);
     ti->z_mask = z_mask;
-    ti->s_mask = s_mask;
+    ti->s_mask = s_mask | smask_from_zmask(z_mask);
     return true;
 }
 
@@ -1519,8 +1520,8 @@  static bool fold_bswap(OptContext *ctx, TCGOp *op)
     default:
         g_assert_not_reached();
     }
-    s_mask = smask_from_zmask(z_mask);
 
+    s_mask = 0;
     switch (op->args[2] & (TCG_BSWAP_OZ | TCG_BSWAP_OS)) {
     case TCG_BSWAP_OZ:
         break;
@@ -1534,7 +1535,6 @@  static bool fold_bswap(OptContext *ctx, TCGOp *op)
     default:
         /* The high bits are undefined: force all bits above the sign to 1. */
         z_mask |= sign << 1;
-        s_mask = 0;
         break;
     }
     ctx->z_mask = z_mask;
@@ -1605,7 +1605,6 @@  static bool fold_count_zeros(OptContext *ctx, TCGOp *op)
         g_assert_not_reached();
     }
     ctx->z_mask = arg_info(op->args[2])->z_mask | z_mask;
-    ctx->s_mask = smask_from_zmask(ctx->z_mask);
     return false;
 }
 
@@ -1625,7 +1624,6 @@  static bool fold_ctpop(OptContext *ctx, TCGOp *op)
     default:
         g_assert_not_reached();
     }
-    ctx->s_mask = smask_from_zmask(ctx->z_mask);
     return false;
 }
 
@@ -1746,7 +1744,6 @@  static bool fold_extract(OptContext *ctx, TCGOp *op)
         return true;
     }
     ctx->z_mask = z_mask;
-    ctx->s_mask = smask_from_zmask(z_mask);
 
     return fold_masks(ctx, op);
 }
@@ -1851,7 +1848,6 @@  static bool fold_extu(OptContext *ctx, TCGOp *op)
     }
 
     ctx->z_mask = z_mask;
-    ctx->s_mask = smask_from_zmask(z_mask);
     if (!type_change && fold_affected_mask(ctx, op, z_mask_old ^ z_mask)) {
         return true;
     }
@@ -2354,7 +2350,6 @@  static bool fold_setcond(OptContext *ctx, TCGOp *op)
     fold_setcond_tst_pow2(ctx, op, false);
 
     ctx->z_mask = 1;
-    ctx->s_mask = smask_from_zmask(1);
     return false;
 }
 
@@ -2455,7 +2450,6 @@  static bool fold_setcond2(OptContext *ctx, TCGOp *op)
     }
 
     ctx->z_mask = 1;
-    ctx->s_mask = smask_from_zmask(1);
     return false;
 
  do_setcond_const: