[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] tcg/optimize: Fix constant folding of setcond
From: |
wannacu |
Subject: |
[PATCH] tcg/optimize: Fix constant folding of setcond |
Date: |
Fri, 6 Dec 2024 17:58:24 +0800 |
The `z_mask` field of TCGTemp argument needs to be
properly set for the upcoming `fold_setcond_zmask` call
This patch resolves issues with running some x86_64
applications (e.g., FontForge, Krita) on riscv64
Signed-off-by: wannacu <wannacu2049@gmail.com>
---
tcg/optimize.c | 3 +++
tests/tcg/x86_64/Makefile.target | 1 +
tests/tcg/x86_64/setcond.c | 28 ++++++++++++++++++++++++++++
3 files changed, 32 insertions(+)
create mode 100644 tests/tcg/x86_64/setcond.c
diff --git a/tcg/optimize.c b/tcg/optimize.c
index e9ef16b3c6..e580b8d8b1 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -834,6 +834,9 @@ static int do_constant_folding_cond1(OptContext *ctx, TCGOp
*op, TCGArg dest,
? INDEX_op_and_i32 : INDEX_op_and_i64);
TCGOp *op2 = tcg_op_insert_before(ctx->tcg, op, and_opc, 3);
TCGArg tmp = arg_new_temp(ctx);
+ /* Set z_mask for the follwing `fold_setcond_zmask` call. */
+ arg_info(tmp)->z_mask = (ctx->type == TCG_TYPE_I32
+ ? UINT32_MAX : UINT64_MAX);
op2->args[0] = tmp;
op2->args[1] = *p1;
diff --git a/tests/tcg/x86_64/Makefile.target b/tests/tcg/x86_64/Makefile.target
index d6dff559c7..085efa01e1 100644
--- a/tests/tcg/x86_64/Makefile.target
+++ b/tests/tcg/x86_64/Makefile.target
@@ -9,6 +9,7 @@
include $(SRC_PATH)/tests/tcg/i386/Makefile.target
X86_64_TESTS += test-2413
+X86_64_TESTS += setcond.c
ifeq ($(filter %-linux-user, $(TARGET)),$(TARGET))
X86_64_TESTS += vsyscall
diff --git a/tests/tcg/x86_64/setcond.c b/tests/tcg/x86_64/setcond.c
new file mode 100644
index 0000000000..317a7e74d2
--- /dev/null
+++ b/tests/tcg/x86_64/setcond.c
@@ -0,0 +1,28 @@
+#include <stdint.h>
+#include <assert.h>
+
+uint8_t test(uint8_t a)
+{
+ uint8_t res = 0xff;
+ asm(
+ "lea -0x1160(%%edi), %%edx\n\t"
+ "lea -0xd7b0(%%edi), %%ecx\n\t"
+ "cmp $0x9f, %%edx\n\t"
+ "setbe %%dl\n\t"
+ "cmp $0x4f, %%ecx\n\t"
+ "setbe %%cl\n\t"
+ "or %%ecx, %%edx\n\t"
+ "cmp $0x200b, %%edi\n\t"
+ "sete %0\n\t"
+ : "=r"(res)
+ );
+ return res;
+}
+
+int main(void)
+{
+ for (uint8_t a = 0; a < 0xff; a++) {
+ assert(test(a) == 0);
+ }
+ return 0;
+}
--
2.47.1
- [PATCH] tcg/optimize: Fix constant folding of setcond,
wannacu <=