* [PATCH] tcg/optimize: Fix TCG_COND_TST* simplification of setcond2
@ 2024-07-01 2:46 Richard Henderson
2024-07-01 8:55 ` Alex Bennée
2024-07-01 9:47 ` Alex Bennée
0 siblings, 2 replies; 3+ messages in thread
From: Richard Henderson @ 2024-07-01 2:46 UTC (permalink / raw)
To: qemu-devel; +Cc: mark.cave-ayland, alex.bennee, qemu-stable
Fix a typo in the argument movement.
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>
---
tcg/optimize.c | 2 +-
tests/tcg/x86_64/test-2413.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 31 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..a0e4d25093
--- /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)
+{
+ 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;
+}
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] tcg/optimize: Fix TCG_COND_TST* simplification of setcond2
2024-07-01 2:46 [PATCH] tcg/optimize: Fix TCG_COND_TST* simplification of setcond2 Richard Henderson
@ 2024-07-01 8:55 ` Alex Bennée
2024-07-01 9:47 ` Alex Bennée
1 sibling, 0 replies; 3+ messages in thread
From: Alex Bennée @ 2024-07-01 8:55 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel, mark.cave-ayland, qemu-stable
Richard Henderson <richard.henderson@linaro.org> writes:
> Fix a typo in the argument movement.
>
> 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>
> ---
> tcg/optimize.c | 2 +-
> tests/tcg/x86_64/test-2413.c | 30 ++++++++++++++++++++++++++++++
> 2 files changed, 31 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..a0e4d25093
> --- /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>
This also needs:
X86_64_TESTS += test-2413
in the Makefile.
> +
> +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)
> +{
> + 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;
> +}
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] tcg/optimize: Fix TCG_COND_TST* simplification of setcond2
2024-07-01 2:46 [PATCH] tcg/optimize: Fix TCG_COND_TST* simplification of setcond2 Richard Henderson
2024-07-01 8:55 ` Alex Bennée
@ 2024-07-01 9:47 ` Alex Bennée
1 sibling, 0 replies; 3+ messages in thread
From: Alex Bennée @ 2024-07-01 9:47 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel, mark.cave-ayland, qemu-stable
Richard Henderson <richard.henderson@linaro.org> writes:
> Fix a typo in the argument movement.
>
> 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>
> ---
> tcg/optimize.c | 2 +-
> tests/tcg/x86_64/test-2413.c | 30 ++++++++++++++++++++++++++++++
> 2 files changed, 31 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..a0e4d25093
> --- /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)
> +{
> + long a, c, d;
The compiler complains about the mismatch between long and the unsigned
long of the test function.
Anyway dropping the previous fix and just using this:
Tested-by: Alex Bennée <alex.bennee@linaro.org>
> +
> + 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;
> +}
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-07-01 9:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-01 2:46 [PATCH] tcg/optimize: Fix TCG_COND_TST* simplification of setcond2 Richard Henderson
2024-07-01 8:55 ` Alex Bennée
2024-07-01 9:47 ` Alex Bennée
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).