All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tcg/riscv64: Fix vector constant matching for logical ops
@ 2026-10-08 18:16 Aurelien Jarno
  2026-10-09  5:05 ` Richard Henderson
  0 siblings, 1 reply; 4+ messages in thread
From: Aurelien Jarno @ 2026-10-08 18:16 UTC (permalink / raw)
  To: Palmer Dabbelt, Alistair Francis, Daniel Henrique Barboza,
	Richard Henderson, open list:RISC-V TCG target,
	open list:All patches CC here
  Cc: Aurelien Jarno

For logical vector operations (in the case of the RISC-V backend that
corresponds to and_vec, or_vec and xor_vec), VECE is unused. However,
tcg_target_const_match() always treat it as an element size to extract
the corresponding constant element from the whole constant.

This causes the following aarch64 instruction
  bic v4.8h, #0xf0
to be translated into the following op:
  ...
  and_vec v128,e8,tmp5,tmp4,v128$0xff0fff0fff0fff0f
  ...
which is then translated to the following RISC-V instruction:
  vand.vi v1,v1,15

Fix that by, when VECE is 0 aka MO_8, only extracting the element if the
it can actually be represented as a duplicated constant.

Fixes: 5a63f5998791 ("tcg/riscv: Add support for basic vector opcodes")
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
---
 tcg/riscv64/tcg-target.c.inc | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/tcg/riscv64/tcg-target.c.inc b/tcg/riscv64/tcg-target.c.inc
index 14a397117a..382c4b6a28 100644
--- a/tcg/riscv64/tcg-target.c.inc
+++ b/tcg/riscv64/tcg-target.c.inc
@@ -392,8 +392,15 @@ static bool tcg_target_const_match(int64_t val, int ct,
         return 1;
     }
     if (type >= TCG_TYPE_V64) {
-        /* Val is replicated by VECE; extract the highest element. */
-        val >>= (-8 << vece) & 63;
+        /*
+         * For vector logical operations, VECE is unused and equals to 0, so
+         * we need to check that the constant can properly be represented after
+         * replication.
+         */
+        if ((vece != MO_8) || (val == (uint8_t)val * 0x0101010101010101ull)) {
+            /* Val is replicated by VECE; extract the highest element. */
+            val >>= (-8 << vece) & 63;
+        }
     }
     /*
      * Sign extended from 12 bits: [-0x800, 0x7ff].
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-09 21:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-08 18:16 [PATCH] tcg/riscv64: Fix vector constant matching for logical ops Aurelien Jarno
2026-10-09  5:05 ` Richard Henderson
2026-10-09 18:02   ` Aurelien Jarno
2026-10-09 21:51     ` Philippe Mathieu-Daudé

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.