[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 13/15] tcg/optimize: Fold and to extu during optimize
From: |
Richard Henderson |
Subject: |
[PATCH 13/15] tcg/optimize: Fold and to extu during optimize |
Date: |
Tue, 12 Mar 2024 04:38:37 -1000 |
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
tcg/optimize.c | 43 +++++++++++++++++++++++++++++++++++++++----
1 file changed, 39 insertions(+), 4 deletions(-)
diff --git a/tcg/optimize.c b/tcg/optimize.c
index c6b0ab35c8..39bcd32f72 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -1300,11 +1300,46 @@ static bool fold_and(OptContext *ctx, TCGOp *op)
ctx->s_mask = arg_info(op->args[1])->s_mask
& arg_info(op->args[2])->s_mask;
- /*
- * Known-zeros does not imply known-ones. Therefore unless
- * arg2 is constant, we can't infer affected bits from it.
- */
if (arg_is_const(op->args[2])) {
+ TCGOpcode ext8 = 0, ext16 = 0, ext32 = 0;
+
+ /* Canonicalize as zero-extend, if supported. */
+ switch (ctx->type) {
+ case TCG_TYPE_I32:
+ ext8 = TCG_TARGET_HAS_ext8u_i32 ? INDEX_op_ext8u_i32 : 0;
+ ext16 = TCG_TARGET_HAS_ext16u_i32 ? INDEX_op_ext16u_i32 : 0;
+ break;
+ case TCG_TYPE_I64:
+ ext8 = TCG_TARGET_HAS_ext8u_i64 ? INDEX_op_ext8u_i64 : 0;
+ ext16 = TCG_TARGET_HAS_ext16u_i64 ? INDEX_op_ext16u_i64 : 0;
+ ext32 = TCG_TARGET_HAS_ext32u_i64 ? INDEX_op_ext32u_i64 : 0;
+ break;
+ default:
+ break;
+ }
+
+ switch (arg_info(op->args[2])->val) {
+ case 0xff:
+ if (ext8) {
+ op->opc = ext8;
+ }
+ break;
+ case 0xffff:
+ if (ext16) {
+ op->opc = ext16;
+ }
+ break;
+ case UINT32_MAX:
+ if (ext32) {
+ op->opc = ext32;
+ }
+ break;
+ }
+
+ /*
+ * Known-zeros does not imply known-ones. Therefore unless
+ * arg2 is constant, we can't infer affected bits from it.
+ */
ctx->a_mask = z1 & ~z2;
}
--
2.34.1
- [PATCH 06/15] tcg/arm: Do not accept immediate operand for andc, (continued)
- [PATCH 06/15] tcg/arm: Do not accept immediate operand for andc, Richard Henderson, 2024/03/12
- [PATCH 08/15] tcg/loongarch64: Do not accept immediate operand for andc, orc, Richard Henderson, 2024/03/12
- [PATCH 11/15] tcg/riscv: Do not accept immediate operands for sub, Richard Henderson, 2024/03/12
- [PATCH 02/15] tcg/optimize: Fold orc with immediate to or, Richard Henderson, 2024/03/12
- [PATCH 03/15] tcg/optimize: Fold eqv with immediate to xor, Richard Henderson, 2024/03/12
- [PATCH 05/15] tcg/aarch64: Do not accept immediate operand for andc, orc, eqv, Richard Henderson, 2024/03/12
- [PATCH 04/15] tcg/i386: Do not accept immediate operand for andc, Richard Henderson, 2024/03/12
- [PATCH 10/15] tcg/riscv: Do not accept immediate operand for andc, orc, eqv, Richard Henderson, 2024/03/12
- [PATCH 15/15] tcg/optimize: Lower unsupported deposit during optimize, Richard Henderson, 2024/03/12
- [PATCH 07/15] tcg/ppc: Do not accept immediate operand for andc, orc, eqv, Richard Henderson, 2024/03/12
- [PATCH 13/15] tcg/optimize: Fold and to extu during optimize,
Richard Henderson <=
- [PATCH 12/15] tcg/riscv: Do not accept zero operands for logicals, multiply or divide, Richard Henderson, 2024/03/12
- [PATCH 09/15] tcg/s390x: Do not accept immediate operand for andc, orc, Richard Henderson, 2024/03/12
- [PATCH 14/15] tcg: Use arg_is_const_val in fold_sub_to_neg, Richard Henderson, 2024/03/12