Skip to content

Commit a71d9df

Browse files
committed
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]>
1 parent e571730 commit a71d9df

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

tcg/optimize.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2384,7 +2384,7 @@ static bool fold_setcond2(OptContext *ctx, TCGOp *op)
23842384

23852385
case TCG_COND_TSTEQ:
23862386
case TCG_COND_TSTNE:
2387-
if (arg_is_const_val(op->args[2], 0)) {
2387+
if (arg_is_const_val(op->args[3], 0)) {
23882388
goto do_setcond_high;
23892389
}
23902390
if (arg_is_const_val(op->args[4], 0)) {

tests/tcg/x86_64/Makefile.target

+2
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

+30
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)