[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 7/7] tcg/optimize: Fix TCG_COND_TST* simplification of setcond2
From: |
Richard Henderson |
Subject: |
[PULL 7/7] tcg/optimize: Fix TCG_COND_TST* simplification of setcond2 |
Date: |
Wed, 3 Jul 2024 10:42:26 -0700 |
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: qemu-stable@nongnu.org
Fixes: ceb9ee06b71 ("tcg/optimize: Handle TCG_COND_TST{EQ,NE}")
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2413
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Tested-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20240701024623.1265028-1-richard.henderson@linaro.org>
---
tcg/optimize.c | 2 +-
tests/tcg/x86_64/test-2413.c | 30 ++++++++++++++++++++++++++++++
tests/tcg/x86_64/Makefile.target | 2 ++
3 files changed, 33 insertions(+), 1 deletion(-)
create mode 100644 tests/tcg/x86_64/test-2413.c
diff --git a/tcg/optimize.c b/tcg/optimize.c
index 8886f7037a..ba16ec27e2 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -2384,7 +2384,7 @@ static bool fold_setcond2(OptContext *ctx, TCGOp *op)
case TCG_COND_TSTEQ:
case TCG_COND_TSTNE:
- if (arg_is_const_val(op->args[2], 0)) {
+ if (arg_is_const_val(op->args[3], 0)) {
goto do_setcond_high;
}
if (arg_is_const_val(op->args[4], 0)) {
diff --git a/tests/tcg/x86_64/test-2413.c b/tests/tcg/x86_64/test-2413.c
new file mode 100644
index 0000000000..456e5332fc
--- /dev/null
+++ b/tests/tcg/x86_64/test-2413.c
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Copyright 2024 Linaro, Ltd. */
+/* See https://gitlab.com/qemu-project/qemu/-/issues/2413 */
+
+#include <assert.h>
+
+void test(unsigned long *a, unsigned long *d, unsigned long c)
+{
+ asm("xorl %%eax, %%eax\n\t"
+ "xorl %%edx, %%edx\n\t"
+ "testb $0x20, %%cl\n\t"
+ "sete %%al\n\t"
+ "setne %%dl\n\t"
+ "shll %%cl, %%eax\n\t"
+ "shll %%cl, %%edx\n\t"
+ : "=a"(*a), "=d"(*d)
+ : "c"(c));
+}
+
+int main(void)
+{
+ unsigned long a, c, d;
+
+ for (c = 0; c < 64; c++) {
+ test(&a, &d, c);
+ assert(a == (c & 0x20 ? 0 : 1u << (c & 0x1f)));
+ assert(d == (c & 0x20 ? 1u << (c & 0x1f) : 0));
+ }
+ return 0;
+}
diff --git a/tests/tcg/x86_64/Makefile.target b/tests/tcg/x86_64/Makefile.target
index 5fedf22117..eda9bd7396 100644
--- a/tests/tcg/x86_64/Makefile.target
+++ b/tests/tcg/x86_64/Makefile.target
@@ -8,6 +8,8 @@
include $(SRC_PATH)/tests/tcg/i386/Makefile.target
+X86_64_TESTS += test-2413
+
ifeq ($(filter %-linux-user, $(TARGET)),$(TARGET))
X86_64_TESTS += vsyscall
X86_64_TESTS += noexec
--
2.34.1
- [PULL 0/7] tcg patch queue, Richard Henderson, 2024/07/03
- [PULL 2/7] util/cpuinfo-ppc: Add FreeBSD support, Richard Henderson, 2024/07/03
- [PULL 4/7] util/cpuinfo-riscv: Support host/cpuinfo.h for riscv, Richard Henderson, 2024/07/03
- [PULL 5/7] util/cpuinfo-riscv: Support OpenBSD signal frame, Richard Henderson, 2024/07/03
- [PULL 1/7] util/cpuinfo-ppc: Fix building on OpenBSD, Richard Henderson, 2024/07/03
- [PULL 6/7] util/cpuinfo-riscv: Use linux __riscv_hwprobe syscall, Richard Henderson, 2024/07/03
- [PULL 3/7] util/cpuinfo-aarch64: Add OpenBSD support, Richard Henderson, 2024/07/03
- [PULL 7/7] tcg/optimize: Fix TCG_COND_TST* simplification of setcond2,
Richard Henderson <=
- Re: [PULL 0/7] tcg patch queue, Richard Henderson, 2024/07/03