[PATCH v2 25/27] tcg/optimize: Simplify fold_andc constant checks

Richard Henderson posted 27 patches 5 months, 2 weeks ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>
[PATCH v2 25/27] tcg/optimize: Simplify fold_andc constant checks
Posted by Richard Henderson 5 months, 2 weeks ago
If operand 2 is constant, then the computation of z_mask and a_mask
will produce the same results as the explicit check via fold_xi_to_i.
Shift the calls of fold_xx_to_i and fold_ix_to_not down below the
i2->is_const check.

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

diff --git a/tcg/optimize.c b/tcg/optimize.c
index f3a2328fe4..8d14a38f9d 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -1482,10 +1482,7 @@ static bool fold_andc(OptContext *ctx, TCGOp *op)
     uint64_t z_mask, o_mask, s_mask, a_mask;
     TempOptInfo *t1, *t2;
 
-    if (fold_const2(ctx, op) ||
-        fold_xx_to_i(ctx, op, 0) ||
-        fold_xi_to_x(ctx, op, 0) ||
-        fold_ix_to_not(ctx, op, -1)) {
+    if (fold_const2(ctx, op)) {
         return true;
     }
 
@@ -1510,6 +1507,10 @@ static bool fold_andc(OptContext *ctx, TCGOp *op)
         op->args[2] = arg_new_constant(ctx, ~ti_const_val(t2));
         return fold_and(ctx, op);
     }
+    if (fold_xx_to_i(ctx, op, 0) ||
+        fold_ix_to_not(ctx, op, -1)) {
+        return true;
+    }
 
     z_mask = t1->z_mask & ~t2->o_mask;
     o_mask = t1->o_mask & ~t2->z_mask;
-- 
2.43.0
Re: [PATCH v2 25/27] tcg/optimize: Simplify fold_andc constant checks
Posted by Pierrick Bouvier 4 months, 3 weeks ago
On 6/3/25 1:09 AM, Richard Henderson wrote:
> If operand 2 is constant, then the computation of z_mask and a_mask
> will produce the same results as the explicit check via fold_xi_to_i.
> Shift the calls of fold_xx_to_i and fold_ix_to_not down below the
> i2->is_const check.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   tcg/optimize.c | 9 +++++----
>   1 file changed, 5 insertions(+), 4 deletions(-)

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