Skip to contentSkip to conversation

tcg/optimize: Don't fold INDEX_op_and_vec to extract

PATCH In review Richard Henderson 3 participants 5 messages Jul 18, 2025 – Jul 19, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcg/optimize: Don't fold INDEX_op_and_vec to extract

There is no such thing as vector extract.

Fixes 932522a9ddc1 ("tcg/optimize: Fold and to extract during optimize")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3036

---
 tcg/optimize.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tcg/optimize.c +1 -1
index 62a128bc9b..3638ab9fea 100644
@@ -1454,7 +1454,7 @@ static bool fold_and(OptContext *ctx, TCGOp *op)
     a_mask = t1->z_mask & ~t2->o_mask;
 
     if (!fold_masks_zosa_int(ctx, op, z_mask, o_mask, s_mask, a_mask)) {
-        if (ti_is_const(t2)) {
+        if (op->opc == INDEX_op_and && ti_is_const(t2)) {
             /*
              * Canonicalize on extract, if valid.  This aids x86 with its
              * 2 operand MOVZBL and 2 operand AND, selecting the TCGOpcode
Signature · 1 line
2.43.0
#1 lore raw
Quoted 15 lines · Richard Henderson

There is no such thing as vector extract.

Fixes 932522a9ddc1 ("tcg/optimize: Fold and to extract during optimize")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3036

---
 tcg/optimize.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tcg/optimize.c +0 -0
index 62a128bc9b..3638ab9fea 100644

tcg/optimize.c static bool fold_and(OptContext *ctx, TCGOp *op) · line 1460

Quoted 8 lines
tcg/optimize.c +1 -1
@@ -1454,7 +1454,7 @@ static bool fold_and(OptContext *ctx, TCGOp *op)
     a_mask = t1->z_mask & ~t2->o_mask;
 
     if (!fold_masks_zosa_int(ctx, op, z_mask, o_mask, s_mask, a_mask)) {
-        if (ti_is_const(t2)) {
+        if (op->opc == INDEX_op_and && ti_is_const(t2)) {
             /*
              * Canonicalize on extract, if valid.  This aids x86 with its
              * 2 operand MOVZBL and 2 operand AND, selecting the TCGOpcod

How does the fold_masks_zosa stuff work for vector operations here? The masks are only 64 bits but the value we're working with is wider than that, right?

thanks
-- PMM

#2 lore raw
Quoted 19 lines · Peter Maydell
Quoted 17 lines · Richard Henderson

There is no such thing as vector extract.

Fixes 932522a9ddc1 ("tcg/optimize: Fold and to extract during optimize")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3036

---
  tcg/optimize.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tcg/optimize.c +0 -0
index 62a128bc9b..3638ab9fea 100644
@@ -1454,7 +1454,7 @@ static bool fold_and(OptContext *ctx, TCGOp *op)
      a_mask = t1->z_mask & ~t2->o_mask;
 
Quoted 11 lines

tcg/optimize.c static bool fold_and(OptContext *ctx, TCGOp *op)

Quoted 6 lines
tcg/optimize.c +1 -1
      if (!fold_masks_zosa_int(ctx, op, z_mask, o_mask, s_mask, a_mask)) {
-        if (ti_is_const(t2)) {
+        if (op->opc == INDEX_op_and && ti_is_const(t2)) {
              /*
               * Canonicalize on extract, if valid.  This aids x86 with its
               * 2 operand MOVZBL and 2 operand AND, selecting the TCGOpcod

How does the fold_masks_zosa stuff work for vector operations here? The masks are only 64 bits but the value we're working with is wider than that, right?

For vectors, the known one/zero bits stem from immediate operands. All vector immediates are dup_const, that is, some replication of uint64_t or smaller element. There is no way to represent (__vector uin8_t){ 1,2,3,4,5,6,7,8,9,a,b,c,d,e,f } with tcg at the moment.

Thus we can treat this sort of simple vector optimization as replications of uint64_t. Any other operation resets the masks to "unknown" state.

r~

Reviewed-by Tested-by on v1 1/1
#3 lore raw
In reply to Richard Henderson
Quoted 14 lines · Richard Henderson

There is no such thing as vector extract.

Fixes 932522a9ddc1 ("tcg/optimize: Fold and to extract during optimize")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3036

---
  tcg/optimize.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tcg/optimize.c +0 -0
index 62a128bc9b..3638ab9fea 100644

tcg/optimize.c static bool fold_and(OptContext *ctx, TCGOp *op) · line 1460

Quoted 8 lines
tcg/optimize.c +1 -1
@@ -1454,7 +1454,7 @@ static bool fold_and(OptContext *ctx, TCGOp *op)
      a_mask = t1->z_mask & ~t2->o_mask;
 
      if (!fold_masks_zosa_int(ctx, op, z_mask, o_mask, s_mask, a_mask)) {
-        if (ti_is_const(t2)) {
+        if (op->opc == INDEX_op_and && ti_is_const(t2)) {
              /*
               * Canonicalize on extract, if valid.  This aids x86 with its
               * 2 operand MOVZBL and 2 operand AND, selecting the TCGOpcode

This solves the failures observed, thanks.