target/s390x: Fix R[NOX]SBG with T=1
v2 cover target/s390x: Fix R[NOX]SBG with T=1
v1: https://lists.gnu.org/archive/html/qemu-devel/2023-03/msg04493.html
v1 -> v2: Work around a clang issue (Thomas).
Add cc=0 test, use more human-friendly constants.
Hi,
This series fixes ROTATE THEN <do something with> SELECTED BITS when test-results control is on. The problem is the incorrect translation, which confuses the register allocator.
Patch 1 is the fix, patch 2 adds a test.
Best regards,
Ilya
Ilya Leoshkevich (2):
target/s390x: Fix R[NOX]SBG with T=1
tests/tcg/s390x: Add rxsbg.c
target/s390x/tcg/translate.c | 3 +++ tests/tcg/s390x/Makefile.target | 3 +++ tests/tcg/s390x/rxsbg.c | 46 +++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 tests/tcg/s390x/rxsbg.c
Signature · 1 line
2.39.2
PATCH v2 2/2 tests/tcg/s390x: Add rxsbg.c
Add a small test for RXSBG with T=1 to prevent regressions.
--- tests/tcg/s390x/Makefile.target | 3 +++ tests/tcg/s390x/rxsbg.c | 46 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 tests/tcg/s390x/rxsbg.c
tests/tcg/s390x/Makefile.target +3 -0
@@ -29,10 +29,13 @@ TESTS+=clst TESTS+=long-double TESTS+=cdsg TESTS+=chrl +TESTS+=rxsbg cdsg: CFLAGS+=-pthread cdsg: LDFLAGS+=-pthread +rxsbg: CFLAGS+=-O2 + Z13_TESTS=vistr $(Z13_TESTS): CFLAGS+=-march=z13 -O2 TESTS+=$(Z13_TESTS)
tests/tcg/s390x/rxsbg.c new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.39.2
PATCH v2 1/2 target/s390x: Fix R[NOX]SBG with T=1
In reply to Ilya LeoshkevichRXSBG usage in the "filetests" test from the wasmtime testsuite makes tcg_reg_alloc_op() attempt to temp_load() a TEMP_VAL_DEAD temporary, causing an assertion failure:
0x01000a70: ec14 b040 3057 rxsbg %r1, %r4, 0xb0, 0x40, 0x30
OP after optimization and liveness analysis:
---- 0000000001000a70 0000000000000004 0000000000000006
rotl_i64 tmp2,r4,$0x30 dead: 1 2 pref=0xffff
and_i64 tmp2,tmp2,$0x800000000000ffff dead: 1 pref=0xffff
[xor_i64 tmp3,tmp3,tmp2 dead: 1 2 pref=0xffff]
and_i64 cc_dst,tmp3,$0x800000000000ffff sync: 0 dead: 0 1 2 pref=0xffff
mov_i64 psw_addr,$0x1000a76 sync: 0 dead: 0 1 pref=0xffff
mov_i32 cc_op,$0x6 sync: 0 dead: 0 1 pref=0xffff
call lookup_tb_ptr,$0x6,$1,tmp8,env dead: 1 pref=none
goto_ptr tmp8 dead: 0
set_label $L0
exit_tb $0x7fffe809d183
../tcg/tcg.c:3865: tcg fatal errorThe reason is that tmp3 does not have an initial value, which confuses the register allocator. This also affects the correctness of the results.
Fix by assigning R1 to it.
--- target/s390x/tcg/translate.c | 3 +++ 1 file changed, 3 insertions(+)
target/s390x/tcg/translate.c +3 -0
@@ -3696,10 +3696,13 @@ static DisasJumpType op_rosbg(DisasContext *s, DisasOps *o)int i4 =get_field (s, i4);int i5 =get_field (s, i5);uint64_t mask; +TCGv_i64 tmp;/* If this is a test-only form, arrange to discard the result. */ if (i3 &0x80 ) { + tmp = o->out; o->out =tcg_temp_new_i64 (); +tcg_gen_mov_i64 (o->out, tmp); } i3 &=63 ;
Signature · 1 line
2.39.2
Quoted 21 lines · Ilya Leoshkevich
RXSBG usage in the "filetests" test from the wasmtime testsuite makes
tcg_reg_alloc_op()attempt totemp_load()aTEMP_VAL_DEADtemporary, causing an assertion failure:0x01000a70: ec14 b040 3057 rxsbg %r1, %r4, 0xb0, 0x40, 0x30 OP after optimization and liveness analysis: ---- 0000000001000a70 0000000000000004 0000000000000006 rotl_i64 tmp2,r4,$0x30 dead: 1 2 pref=0xffff and_i64 tmp2,tmp2,$0x800000000000ffff dead: 1 pref=0xffff [xor_i64 tmp3,tmp3,tmp2 dead: 1 2 pref=0xffff] and_i64 cc_dst,tmp3,$0x800000000000ffff sync: 0 dead: 0 1 2 pref=0xffff mov_i64 psw_addr,$0x1000a76 sync: 0 dead: 0 1 pref=0xffff mov_i32 cc_op,$0x6 sync: 0 dead: 0 1 pref=0xffff call lookup_tb_ptr,$0x6,$1,tmp8,env dead: 1 pref=none goto_ptr tmp8 dead: 0 set_label $L0 exit_tb $0x7fffe809d183 ../tcg/tcg.c:3865: tcg fatal error
Quoted 7 lines
The reason is that tmp3 does not have an initial value, which confuses the register allocator. This also affects the correctness of the results.
Fix by assigning R1 to it.
Fixes d6c6372e186e ("target-s390: Implement R[NOX]SBG")
Exposed by 3ac6f91bca..dd161de75f?
3ac6f91bca target/s390x: Drop tcg_temp_free from translate.c dd161de75f target/s390x: Remove g_out, g_out2, g_in1, g_in2
Quoted 11 lines
Reviewed-by David Hildenbrand <[email protected]>Signed-off-by Ilya Leoshkevich <[email protected]>--- target/s390x/tcg/translate.c | 3 +++ 1 file changed, 3 insertions(+)target/s390x/tcg/translate.c +0
-0
target/s390x/tcg/translate.c static DisasJumpType op_rosbg(DisasContext *s, DisasOps *o) · line 3702
Quoted 7 lines
target/s390x/tcg/translate.c +1
-0@@ -3696,10 +3696,13 @@ static DisasJumpType op_rosbg(DisasContext *s, DisasOps *o)int i4 =get_field (s, i4);int i5 =get_field (s, i5);uint64_t mask; +TCGv_i64 tmp;/* If this is a test-only form, arrange to discard the result. */ if (i3 &0x80 ) {
tcg_debug_assert(o->out != NULL); ?
target/s390x/tcg/translate.c static DisasJumpType op_rosbg(DisasContext *s, DisasOps *o) · line 3705
Quoted 3 lines
target/s390x/tcg/translate.c +2
-0+ tmp = o->out; o->out =tcg_temp_new_i64 (); +tcg_gen_mov_i64 (o->out, tmp);
Something bugs me with this pattern but I can't say why yet :(
Quoted 3 lines
target/s390x/tcg/translate.c +0
-0} i3 &=63 ;
Quoted 35 lines · Philippe Mathieu-Daudé
Quoted 34 lines · Ilya Leoshkevich
RXSBG usage in the "filetests" test from the wasmtime testsuite makes
tcg_reg_alloc_op()attempt totemp_load()aTEMP_VAL_DEADtemporary,
causing an assertion failure:0x01000a70: ec14 b040 3057 rxsbg %r1, %r4,
0xb0,0x40,0x30OP after optimization and liveness analysis:
----0000000001000a700000000000000004 0000000000000006rotl_i64tmp2,r4,$0x30 dead: 1 2 pref=0xffff
and_i64tmp2,tmp2,$0x800000000000ffff dead: 1 pref=0xffff [xor_i64tmp3,tmp3,tmp2 dead: 1 2 pref=0xffff]
and_i64cc_dst,tmp3,$0x800000000000ffff sync: 0 dead: 0 1 2 pref=0xffff
mov_i64psw_addr,$0x1000a76 sync: 0 dead: 0 1 pref=0xffff
mov_i32cc_op,$0x6 sync: 0 dead: 0 1 pref=0xffff
call lookup_tb_ptr,$0x6,$1,tmp8,env dead: 1 pref=nonegoto_ptrtmp8 dead: 0set_label$L0
exit_tb$0x7fffe809d183
../tcg/tcg.c:3865: tcg fatal errorThe reason is that tmp3 does not have an initial value, which confuses
the register allocator. This also affects the correctness of the results.
Quoted 5 lines
Quoted 3 lines
Fix by assigning R1 to it.
Fixes d6c6372e186e ("target-s390: Implement R[NOX]SBG")Exposed by
3ac6f91bca..dd161de75f?
Bisect points to:
commit e2e641fa3d5e730f128562d6901dcc729c9bf8a0
Author: Richard Henderson <[email protected]> Date: Sun Jan 29 14:09:00 2023 -1000
tcg: Change default temp lifetime to TEMP_TB
I will mention this.
Quoted 18 lines
3ac6f91bcatarget/s390x: Droptcg_temp_freefromtranslate.cdd161de75ftarget/s390x: Removeg_out,g_out2,g_in1,g_in2Quoted 15 lines
Reviewed-by David Hildenbrand <[email protected]>Signed-off-by Ilya Leoshkevich <[email protected]>---
target/s390x/tcg/translate.c| 3 +++1 file changed, 3 insertions(+)target/s390x/tcg/translate.c +0
-0@@ -3696,10 +3696,13 @@ static DisasJumpType op_rosbg(DisasContext *s, DisasOps *o) int i4 = get_field(s, i4); int i5 = get_field(s, i5);
Quoted 8 lines
Quoted 6 lines
target/s390x/tcg/translate.c +1
-0uint64_t mask; + TCGv_i64 tmp;
/* If this is a test-only form, arrange to discard the result. */
if (i3 &0x80) {
tcg_debug_assert(o->out != NULL); ?
Ok, I will add this.
Quoted 6 lines
Quoted 4 lines
+ tmp =
o->out;
o->out=tcg_temp_new_i64();
+tcg_gen_mov_i64(o->out, tmp);Something bugs me with this pattern but I can't say why yet :(
Please let me know once you come up with something. I will do s/tmp/orig_out/ send a v3 in the meantime.
Quoted 3 lines
Quoted 3 lines
}
i3 &= 63;