tcg/riscv64: Fix vector constant matching for logical ops
PATCH 1/1 tcg/riscv64: Fix vector constant matching for logical ops
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.
--- tcg/riscv64/tcg-target.c.inc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
tcg/riscv64/tcg-target.c.inc +9 -2
@@ -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].
Signature · 1 line
2.53.0
Quoted 1 line · Aurelien Jarno
+ if ((vece !=
MO_8) || (val == (uint8_t)val *0x0101010101010101ull)) {
Do you really want
val = dup_const(vece, val)
?
r~
Hi,
Quoted 8 lines · Richard Henderson
Quoted 1 line · Aurelien Jarno
+ if ((vece !=
MO_8) || (val == (uint8_t)val *0x0101010101010101ull)) {Do you really want
val =
dup_const(vece, val)?
No, I do not want that, as vece is not defined (in practice is 0 aka MO_8) for logical ops.
What I want is really extracting the element only if:
- vece != MO_8
=> This means VECE is defined (not 0), so it is possible to blindly extract a single element.
OR
- val == dup_const(vece, val)
=> When VECE is possibly undefined, this checks that the constant can be properly represented as an element replicated using VECE.
Or maybe you just mean to replace the check by
+ if ((vece != MO_8) || (val == dup_const(vece, val))) {
?
Regards
Aurelien
Signature · 2 lines
Aurelien Jarno GPG: 4096R/1DDD8C9B [email protected] http://aurel32.net
Quoted 6 lines · Aurelien Jarno
Hi,
Quoted 3 lines · Richard Henderson
Quoted 1 line · Aurelien Jarno
+ if ((vece !=
MO_8) || (val == (uint8_t)val *0x0101010101010101ull)) {
Quoted 8 lines
Quoted 3 lines
Do you really want
val =
dup_const(vece, val)Or maybe you just mean to replace the check by
+ if ((vece !=
MO_8) || (val ==dup_const(vece, val))) {
Likely ;)
Quoted 5 lines · Aurelien Jarno
Or maybe you just mean to replace the check by
+ if ((vece !=
MO_8) || (val ==dup_const(vece, val))) {?
Yep.
r~