qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v3 41/48] tcg/optimize: Sink commutative operand swapping int


From: Alex Bennée
Subject: Re: [PATCH v3 41/48] tcg/optimize: Sink commutative operand swapping into fold functions
Date: Tue, 26 Oct 2021 17:27:23 +0100
User-agent: mu4e 1.7.4; emacs 28.0.60

Richard Henderson <richard.henderson@linaro.org> writes:

> Most of these are handled by creating a fold_const2_commutative
> to handle all of the binary operators.  The rest were already
> handled on a case-by-case basis in the switch, and have their
> own fold function in which to place the call.
>
> We now have only one major switch on TCGOpcode.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  tcg/optimize.c | 128 ++++++++++++++++++++++---------------------------
>  1 file changed, 56 insertions(+), 72 deletions(-)
>
> diff --git a/tcg/optimize.c b/tcg/optimize.c
> index ba068e7d3e..92b35a8c3f 100644
> --- a/tcg/optimize.c
> +++ b/tcg/optimize.c
> @@ -696,6 +696,12 @@ static bool fold_const2(OptContext *ctx, TCGOp *op)
>      return false;
>  }
>  
> +static bool fold_const2_commutative(OptContext *ctx, TCGOp *op)
> +{
> +    swap_commutative(op->args[0], &op->args[1], &op->args[2]);
> +    return fold_const2(ctx, op);
> +}
> +
>  static bool fold_masks(OptContext *ctx, TCGOp *op)
>  {
>      uint64_t a_mask = ctx->a_mask;
> @@ -832,7 +838,7 @@ static bool fold_xx_to_x(OptContext *ctx, TCGOp *op)
>  
>  static bool fold_add(OptContext *ctx, TCGOp *op)
>  {
> -    if (fold_const2(ctx, op) ||
> +    if (fold_const2_commutative(ctx, op) ||
>          fold_xi_to_x(ctx, op, 0)) {
>          return true;
>      }
> @@ -891,6 +897,9 @@ static bool fold_addsub2(OptContext *ctx, TCGOp *op, bool 
> add)
>  
>  static bool fold_add2(OptContext *ctx, TCGOp *op)
>  {
> +    swap_commutative(op->args[0], &op->args[2], &op->args[4]);
> +    swap_commutative(op->args[1], &op->args[3], &op->args[5]);
> +
>      return fold_addsub2(ctx, op, true);
>  }
>  
> @@ -898,7 +907,7 @@ static bool fold_and(OptContext *ctx, TCGOp *op)
>  {
>      uint64_t z1, z2;
>  
> -    if (fold_const2(ctx, op) ||
> +    if (fold_const2_commutative(ctx, op) ||
>          fold_xi_to_i(ctx, op, 0) ||
>          fold_xi_to_x(ctx, op, -1) ||
>          fold_xx_to_x(ctx, op)) {
> @@ -950,8 +959,13 @@ static bool fold_andc(OptContext *ctx, TCGOp *op)
>  static bool fold_brcond(OptContext *ctx, TCGOp *op)
>  {
>      TCGCond cond = op->args[2];
> -    int i = do_constant_folding_cond(ctx->type, op->args[0], op->args[1], 
> cond);
> +    int i;
>  
> +    if (swap_commutative(-1, &op->args[0], &op->args[1])) {

I find this a bit magical. I couldn't find anything about TCGArg except
it's type:

  typedef tcg_target_ulong TCGArg;

so I'm not sure what to make of -1 in this case. I guess it just means
we never have a (sum == 0 && dest == a2) leg but it's not obvious
reading the fold code.
>  
> +    if (swap_commutative(-1, &op->args[1], &op->args[2])) {
> +        op->args[5] = cond = tcg_swap_cond(cond);
> +    }

Also here.

<snip>

-- 
Alex Bennée



reply via email to

[Prev in Thread] Current Thread [Next in Thread]