[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 22/24] tcg/i386: Clear dest first in tcg_out_setcond if possible
From: |
Richard Henderson |
Subject: |
[PATCH 22/24] tcg/i386: Clear dest first in tcg_out_setcond if possible |
Date: |
Mon, 7 Aug 2023 20:11:41 -0700 |
Using XOR first is both smaller and more efficient,
though cannot be applied if it clobbers an input.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
tcg/i386/tcg-target.c.inc | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/tcg/i386/tcg-target.c.inc b/tcg/i386/tcg-target.c.inc
index e06ac638b0..cca49fe63a 100644
--- a/tcg/i386/tcg-target.c.inc
+++ b/tcg/i386/tcg-target.c.inc
@@ -1529,6 +1529,7 @@ static void tcg_out_setcond(TCGContext *s, int rexw,
TCGCond cond,
int const_arg2)
{
bool inv = false;
+ bool cleared;
switch (cond) {
case TCG_COND_NE:
@@ -1578,9 +1579,23 @@ static void tcg_out_setcond(TCGContext *s, int rexw,
TCGCond cond,
break;
}
+ /*
+ * If dest does not overlap the inputs, clearing it first is preferred.
+ * The XOR breaks any false dependency for the low-byte write to dest,
+ * and is also one byte smaller than MOVZBL.
+ */
+ cleared = false;
+ if (dest != arg1 && (const_arg2 || dest != arg2)) {
+ tgen_arithr(s, ARITH_XOR, dest, dest);
+ cleared = true;
+ }
+
tcg_out_cmp(s, rexw, arg1, arg2, const_arg2, false);
tcg_out_modrm(s, OPC_SETCC | tcg_cond_to_jcc[cond], 0, dest);
- tcg_out_ext8u(s, dest, dest);
+
+ if (!cleared) {
+ tcg_out_ext8u(s, dest, dest);
+ }
}
#if TCG_TARGET_REG_BITS == 32
--
2.34.1
- [PATCH 16/24] tcg/sparc64: Implement negsetcond_*, (continued)
- [PATCH 16/24] tcg/sparc64: Implement negsetcond_*, Richard Henderson, 2023/08/07
- [PATCH 17/24] tcg/i386: Merge tcg_out_brcond{32,64}, Richard Henderson, 2023/08/07
- [PATCH 18/24] tcg/i386: Merge tcg_out_setcond{32,64}, Richard Henderson, 2023/08/07
- [PATCH 19/24] tcg/i386: Merge tcg_out_movcond{32,64}, Richard Henderson, 2023/08/07
- [PATCH 23/24] tcg/i386: Use shift in tcg_out_setcond, Richard Henderson, 2023/08/07
- [PATCH 22/24] tcg/i386: Clear dest first in tcg_out_setcond if possible,
Richard Henderson <=
- [PATCH 24/24] tcg/i386: Implement negsetcond_*, Richard Henderson, 2023/08/07
- [PATCH 20/24] tcg/i386: Add cf parameter to tcg_out_cmp, Richard Henderson, 2023/08/07
[PATCH 21/24] tcg/i386: Use CMP+SBB in tcg_out_setcond, Richard Henderson, 2023/08/07