Skip to contentSkip to conversation

tcg/optimize: do use affected bits

PATCH Applied Paolo Bonzini 2 participants 3 messages Dec 23, 2025 – Jan 5

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcg/optimize: do use affected bits

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.

---
 tcg/optimize.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tcg/optimize.c +1 -1
index f69702b26e8..c546e8910ba 100644
@@ -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;
 }
 
Signature · 1 line
2.52.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 21 lines · Paolo Bonzini

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.

---
  tcg/optimize.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tcg/optimize.c +0 -0
index f69702b26e8..c546e8910ba 100644

tcg/optimize.c static bool fold_masks_zosa_int(OptContext *ctx, TCGOp *op, · line 1108

Quoted 8 lines
tcg/optimize.c +1 -1
@@ -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.

r~

#2 lore raw
In reply to Paolo Bonzini
Quoted 21 lines · Paolo Bonzini

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.

---
  tcg/optimize.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tcg/optimize.c +0 -0
index f69702b26e8..c546e8910ba 100644

tcg/optimize.c static bool fold_masks_zosa_int(OptContext *ctx, TCGOp *op, · line 1108

Quoted 8 lines
tcg/optimize.c +1 -1
@@ -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~