[PATCH for-11.0] tcg/optimize: do use affected bits

Paolo Bonzini posted 1 patch 1 month, 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20251223163720.985578-1-pbonzini@redhat.com
Maintainers: Richard Henderson <richard.henderson@linaro.org>
tcg/optimize.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH for-11.0] tcg/optimize: do use affected bits
Posted by Paolo Bonzini 1 month, 2 weeks ago
Commit 932522a9ddc ("tcg/optimize: Fold and to extract during optimize",
2025-06-30) inadvertently disabled affected bits optimizations on
operations that use fold_masks_zosa.  These happen relatively often
in x86 code for extract/sextract; for example given the following:

   mov %esi, %ebp
   xor $0x1, %ebp

the optimizer is able to simplify the "extract_i64 rbp,tmp0,$0x0,$0x20"
produced by the second instruction to a move.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 tcg/optimize.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tcg/optimize.c b/tcg/optimize.c
index f69702b26e8..c546e8910ba 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -1102,7 +1102,7 @@ static bool fold_masks_zosa_int(OptContext *ctx, TCGOp *op,
 static bool fold_masks_zosa(OptContext *ctx, TCGOp *op, uint64_t z_mask,
                             uint64_t o_mask, int64_t s_mask, uint64_t a_mask)
 {
-    fold_masks_zosa_int(ctx, op, z_mask, o_mask, s_mask, -1);
+    fold_masks_zosa_int(ctx, op, z_mask, o_mask, s_mask, a_mask);
     return true;
 }
 
-- 
2.52.0
Re: [PATCH for-11.0] tcg/optimize: do use affected bits
Posted by Richard Henderson 1 month ago
On 12/24/25 03:37, Paolo Bonzini wrote:
> Commit 932522a9ddc ("tcg/optimize: Fold and to extract during optimize",
> 2025-06-30) inadvertently disabled affected bits optimizations on
> operations that use fold_masks_zosa.  These happen relatively often
> in x86 code for extract/sextract; for example given the following:
> 
>     mov %esi, %ebp
>     xor $0x1, %ebp
> 
> the optimizer is able to simplify the "extract_i64 rbp,tmp0,$0x0,$0x20"
> produced by the second instruction to a move.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   tcg/optimize.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tcg/optimize.c b/tcg/optimize.c
> index f69702b26e8..c546e8910ba 100644
> --- a/tcg/optimize.c
> +++ b/tcg/optimize.c
> @@ -1102,7 +1102,7 @@ static bool fold_masks_zosa_int(OptContext *ctx, TCGOp *op,
>   static bool fold_masks_zosa(OptContext *ctx, TCGOp *op, uint64_t z_mask,
>                               uint64_t o_mask, int64_t s_mask, uint64_t a_mask)
>   {
> -    fold_masks_zosa_int(ctx, op, z_mask, o_mask, s_mask, -1);
> +    fold_masks_zosa_int(ctx, op, z_mask, o_mask, s_mask, a_mask);
>       return true;
>   }
>   

Queued, thanks.

r~
Re: [PATCH for-11.0] tcg/optimize: do use affected bits
Posted by Richard Henderson 1 month ago
On 12/24/25 03:37, Paolo Bonzini wrote:
> Commit 932522a9ddc ("tcg/optimize: Fold and to extract during optimize",
> 2025-06-30) inadvertently disabled affected bits optimizations on
> operations that use fold_masks_zosa.  These happen relatively often
> in x86 code for extract/sextract; for example given the following:
> 
>     mov %esi, %ebp
>     xor $0x1, %ebp
> 
> the optimizer is able to simplify the "extract_i64 rbp,tmp0,$0x0,$0x20"
> produced by the second instruction to a move.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   tcg/optimize.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tcg/optimize.c b/tcg/optimize.c
> index f69702b26e8..c546e8910ba 100644
> --- a/tcg/optimize.c
> +++ b/tcg/optimize.c
> @@ -1102,7 +1102,7 @@ static bool fold_masks_zosa_int(OptContext *ctx, TCGOp *op,
>   static bool fold_masks_zosa(OptContext *ctx, TCGOp *op, uint64_t z_mask,
>                               uint64_t o_mask, int64_t s_mask, uint64_t a_mask)
>   {
> -    fold_masks_zosa_int(ctx, op, z_mask, o_mask, s_mask, -1);
> +    fold_masks_zosa_int(ctx, op, z_mask, o_mask, s_mask, a_mask);
>       return true;
>   }
>   

Oops.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~