Skip to content

Commit b4efc4c

Browse files
rth7680Michael Tokarev
authored andcommitted
tcg/optimize: Fix TCG_COND_TST* simplification of setcond2
Argument ordering for setcond2 is: output, a_low, a_high, b_low, b_high, cond The test is supposed to be against b_low, not a_high. Cc: [email protected] Fixes: ceb9ee0 ("tcg/optimize: Handle TCG_COND_TST{EQ,NE}") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2413 Signed-off-by: Richard Henderson <[email protected]> Tested-by: Alex Bennée <[email protected]> Message-Id: <[email protected]> (cherry picked from commit a71d9df) Signed-off-by: Michael Tokarev <[email protected]>
1 parent 5be2bb4 commit b4efc4c

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

tcg/optimize.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2274,7 +2274,7 @@ static bool fold_setcond2(OptContext *ctx, TCGOp *op)
22742274

22752275
case TCG_COND_TSTEQ:
22762276
case TCG_COND_TSTNE:
2277-
if (arg_is_const_val(op->args[2], 0)) {
2277+
if (arg_is_const_val(op->args[3], 0)) {
22782278
goto do_setcond_high;
22792279
}
22802280
if (arg_is_const_val(op->args[4], 0)) {

tests/tcg/x86_64/Makefile.target

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
include $(SRC_PATH)/tests/tcg/i386/Makefile.target
1010

11+
X86_64_TESTS += test-2413
12+
1113
ifeq ($(filter %-linux-user, $(TARGET)),$(TARGET))
1214
X86_64_TESTS += vsyscall
1315
X86_64_TESTS += noexec

tests/tcg/x86_64/test-2413.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
/* Copyright 2024 Linaro, Ltd. */
3+
/* See https://gitlab.com/qemu-project/qemu/-/issues/2413 */
4+
5+
#include <assert.h>
6+
7+
void test(unsigned long *a, unsigned long *d, unsigned long c)
8+
{
9+
asm("xorl %%eax, %%eax\n\t"
10+
"xorl %%edx, %%edx\n\t"
11+
"testb $0x20, %%cl\n\t"
12+
"sete %%al\n\t"
13+
"setne %%dl\n\t"
14+
"shll %%cl, %%eax\n\t"
15+
"shll %%cl, %%edx\n\t"
16+
: "=a"(*a), "=d"(*d)
17+
: "c"(c));
18+
}
19+
20+
int main(void)
21+
{
22+
unsigned long a, c, d;
23+
24+
for (c = 0; c < 64; c++) {
25+
test(&a, &d, c);
26+
assert(a == (c & 0x20 ? 0 : 1u << (c & 0x1f)));
27+
assert(d == (c & 0x20 ? 1u << (c & 0x1f) : 0));
28+
}
29+
return 0;
30+
}

0 commit comments

Comments
 (0)