From patchwork Thu Oct 21 21:05:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 516096 Delivered-To: patch@linaro.org Received: by 2002:ac0:bf50:0:0:0:0:0 with SMTP id o16csp344324imj; Thu, 21 Oct 2021 14:30:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfPLL1I1jiuB/ajx/Q0DhQWvQqyQJd7XO+1ny2tFb6hIApcskKD7Wc/S6zoC8FQC21dKWx X-Received: by 2002:a05:6808:110:: with SMTP id b16mr6284961oie.7.1634851834774; Thu, 21 Oct 2021 14:30:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634851834; cv=none; d=google.com; s=arc-20160816; b=dUxfQqe9oFjXuPA2xJob3Cq5Fa4aTsPgCrJliNQd1Q9uWP38oWbL1Mr9YInj/KNRNG qt9b+M8ifdrxNKCIwY9VoQe+H0V2k4dXIwFSnxwiy/AGZe0WNJRwZh75/WKbwQkcWPFk IGD9ODZMtgFDF9g/loLuDEYdZXCHTPS/H7U/6jimU1Xbg4t16IARC1zHswJh/tVKB94P RoOEIfsGZrIGUKkH1uTGiUUe0Gyl0e9EU17EJX000pMbsPpRANwB20zKB21bl8VzSbIV yQ9JaGAUJRi4E76123ZDO8KJlIs5gNPyC/ckAgDd0CAZpTXhsEP8UNrc46izTLqpuY0J mNJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=mVQAUu9tUDiVXS3KTEo22nGHaNB56YhTgguLTU/cCL0=; b=O00RGHxGm0+ebN5f5+s0TQl61uHhaIKoDXRVEFuKylEwy6GgV0BOhO7wxYGocDdVi+ s8N9WL/n8R0SPTzB2kVqf5RRvugSZPzLYadkO3Ngu1ChCJqhet3rQO3uUZnQ7k2m00oZ Xr9TkXUs4N1AgvqG61nm8Yyg9RJcUtqRw0YV2neHLhpGrR1Kn3TCSJcYliKLyye+P1/X IdOT9rUsvCmnCQniFOnwYzaKTmkjQFj8czS9cC70Brlyn2Hz+cmN4Uca3fLPgjJpE5AR iwQCAIgQIRjn4qvEytgCztNIbhf1pZJaDql+f2qbcH291hpuVDXy2ArG92muMI+u1Bf5 xIXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="eo5tHXN/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id r6si10533451oth.73.2021.10.21.14.30.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Oct 2021 14:30:34 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="eo5tHXN/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48716 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mdfdx-0006b6-DJ for patch@linaro.org; Thu, 21 Oct 2021 17:30:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48716) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdfGQ-0007jm-96 for qemu-devel@nongnu.org; Thu, 21 Oct 2021 17:06:14 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]:36773) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mdfGL-0004kI-5C for qemu-devel@nongnu.org; Thu, 21 Oct 2021 17:06:12 -0400 Received: by mail-pj1-x1033.google.com with SMTP id s61-20020a17090a69c300b0019f663cfcd1so4149072pjj.1 for ; Thu, 21 Oct 2021 14:06:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mVQAUu9tUDiVXS3KTEo22nGHaNB56YhTgguLTU/cCL0=; b=eo5tHXN/OOvub319YTIBooZJnW7w7HTcEb+hkG/kSABbwlpCqvGj8Yn17uN4Pz2qSL 4uyzyP9vlTXB1zAhG5Bil5f09YPxu0uLapIqcLp5HUp8whYVD2kDWss9MNHsmfUuO6I3 EexjKRBWkRqWN8I5iqSTykBwJTjrim7Z+b61LmdfsIvdJ8UmFcD3pAi07TVGTgVnsEj4 ttK45sgfc6STA/h3ZkZed3pVdgkB0u9qkKgDf2IysfPo/9TbfQwVSAO1dyNI+1hxmHiM sp+3ZLTqzxAKrhnydkkKjfi5FWgkUEw3246xDYaTZWh4xfbM62melEZZ+XKFWdKT0dxJ AnQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mVQAUu9tUDiVXS3KTEo22nGHaNB56YhTgguLTU/cCL0=; b=CiiPLniZZ34JnmDqTJgRguSy7fDo0OMeQHUEVmyXWWTgUzYJKVvopdhvC0X5van9zt EbKCarbH4EFMC4UH1REupim+3hBMicEJ8aB9iE+MoylHlOVQfI9Q7FJGOq+U6plW7ZEF QQtctftsjhcSqEAra+t/U+kM9ju89dCRt4ePbwjShkcyX4+UZsmVLgMaoT8X+qFE2yYr qIv5clBaalbJ9ZDi4062pdSBlBmlGhHy7Mwvh/1IwrFEqhswpKoz9f68BeayFiN5grzh WqzDoBTp97gOYjFljhUkPTchw/MGAJbqWULyqSmLOFIWfS5Pu/VPVDu3QFaEAqINYEW6 am4g== X-Gm-Message-State: AOAM530GVlx3iK8Jle6ahoEj3ogTuvwc5OGyFV19F/iLADdRwFYMFOxQ vkVRlGTsy4kjq71Y1GJg+kmRUys8dfp/HA== X-Received: by 2002:a17:902:780f:b0:13a:3919:e365 with SMTP id p15-20020a170902780f00b0013a3919e365mr7392129pll.63.1634850367404; Thu, 21 Oct 2021 14:06:07 -0700 (PDT) Received: from localhost.localdomain ([71.212.134.125]) by smtp.gmail.com with ESMTPSA id g7sm5981670pgp.17.2021.10.21.14.06.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Oct 2021 14:06:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 36/48] tcg/optimize: Split out fold_xi_to_x Date: Thu, 21 Oct 2021 14:05:27 -0700 Message-Id: <20211021210539.825582-37-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211021210539.825582-1-richard.henderson@linaro.org> References: <20211021210539.825582-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1033.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luis.pires@eldorado.org.br, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Pull the "op r, a, i => mov r, a" optimization into a function, and use them int the outer-most logical operations. Signed-off-by: Richard Henderson --- tcg/optimize.c | 60 +++++++++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 35 deletions(-) -- 2.25.1 diff --git a/tcg/optimize.c b/tcg/optimize.c index e4cf746321..af26429175 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -749,6 +749,15 @@ static bool fold_xi_to_i(OptContext *ctx, TCGOp *op, uint64_t i) return false; } +/* If the binary operation has second argument @i, fold to identity. */ +static bool fold_xi_to_x(OptContext *ctx, TCGOp *op, uint64_t i) +{ + if (arg_is_const(op->args[2]) && arg_info(op->args[2])->val == i) { + return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[1]); + } + return false; +} + /* If the binary operation has second argument @i, fold to NOT. */ static bool fold_xi_to_not(OptContext *ctx, TCGOp *op, uint64_t i) { @@ -787,7 +796,11 @@ static bool fold_xx_to_x(OptContext *ctx, TCGOp *op) static bool fold_add(OptContext *ctx, TCGOp *op) { - return fold_const2(ctx, op); + if (fold_const2(ctx, op) || + fold_xi_to_x(ctx, op, 0)) { + return true; + } + return false; } static bool fold_addsub2_i32(OptContext *ctx, TCGOp *op, bool add) @@ -827,6 +840,7 @@ static bool fold_and(OptContext *ctx, TCGOp *op) { if (fold_const2(ctx, op) || fold_xi_to_i(ctx, op, 0) || + fold_xi_to_x(ctx, op, -1) || fold_xx_to_x(ctx, op)) { return true; } @@ -837,6 +851,7 @@ static bool fold_andc(OptContext *ctx, TCGOp *op) { if (fold_const2(ctx, op) || fold_xx_to_i(ctx, op, 0) || + fold_xi_to_x(ctx, op, 0) || fold_ix_to_not(ctx, op, -1)) { return true; } @@ -1039,6 +1054,7 @@ static bool fold_dup2(OptContext *ctx, TCGOp *op) static bool fold_eqv(OptContext *ctx, TCGOp *op) { if (fold_const2(ctx, op) || + fold_xi_to_x(ctx, op, -1) || fold_xi_to_not(ctx, op, 0)) { return true; } @@ -1223,6 +1239,7 @@ static bool fold_not(OptContext *ctx, TCGOp *op) static bool fold_or(OptContext *ctx, TCGOp *op) { if (fold_const2(ctx, op) || + fold_xi_to_x(ctx, op, 0) || fold_xx_to_x(ctx, op)) { return true; } @@ -1346,7 +1363,11 @@ static bool fold_sextract(OptContext *ctx, TCGOp *op) static bool fold_shift(OptContext *ctx, TCGOp *op) { - return fold_const2(ctx, op); + if (fold_const2(ctx, op) || + fold_xi_to_x(ctx, op, 0)) { + return true; + } + return false; } static bool fold_sub_to_neg(OptContext *ctx, TCGOp *op) @@ -1389,6 +1410,7 @@ static bool fold_sub(OptContext *ctx, TCGOp *op) { if (fold_const2(ctx, op) || fold_xx_to_i(ctx, op, 0) || + fold_xi_to_x(ctx, op, 0) || fold_sub_to_neg(ctx, op)) { return true; } @@ -1404,6 +1426,7 @@ static bool fold_xor(OptContext *ctx, TCGOp *op) { if (fold_const2(ctx, op) || fold_xx_to_i(ctx, op, 0) || + fold_xi_to_x(ctx, op, 0) || fold_xi_to_not(ctx, op, -1)) { return true; } @@ -1527,39 +1550,6 @@ void tcg_optimize(TCGContext *s) break; } - /* Simplify expression for "op r, a, const => mov r, a" cases */ - switch (opc) { - CASE_OP_32_64_VEC(add): - CASE_OP_32_64_VEC(sub): - CASE_OP_32_64_VEC(or): - CASE_OP_32_64_VEC(xor): - CASE_OP_32_64_VEC(andc): - CASE_OP_32_64(shl): - CASE_OP_32_64(shr): - CASE_OP_32_64(sar): - CASE_OP_32_64(rotl): - CASE_OP_32_64(rotr): - if (!arg_is_const(op->args[1]) - && arg_is_const(op->args[2]) - && arg_info(op->args[2])->val == 0) { - tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); - continue; - } - break; - CASE_OP_32_64_VEC(and): - CASE_OP_32_64_VEC(orc): - CASE_OP_32_64(eqv): - if (!arg_is_const(op->args[1]) - && arg_is_const(op->args[2]) - && arg_info(op->args[2])->val == -1) { - tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); - continue; - } - break; - default: - break; - } - /* Simplify using known-zero bits. Currently only ops with a single output argument is supported. */ z_mask = -1;