From patchwork Mon Aug 30 06:24:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 504301 Delivered-To: patch@linaro.org Received: by 2002:a02:8629:0:0:0:0:0 with SMTP id e38csp1515454jai; Sun, 29 Aug 2021 23:36:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyB/TWNCjOeCdtE4HLihLOvGxjIzrfHVh3xz85UdwMuvX1vlfTpP2rgH3dhDax7GBbBTdcl X-Received: by 2002:a25:5987:: with SMTP id n129mr21456640ybb.194.1630305399751; Sun, 29 Aug 2021 23:36:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630305399; cv=none; d=google.com; s=arc-20160816; b=wb+83BSgI+ex6jwBwbIU3RhtmP+ZwwCoLTxO8ehvGixtePQQ33rNv7NidH0REDTDtW 5vRIqHhOFpRIR3r6exIa4XrnG/OOhM1+pNvPJfBsg4NKBmQatKNJQ1e23c7WAKWE2sqg iYEZv+rymLhaK5wjTHsZ66ml7E/PrvWPd4SxXLWSKoO0rdOCH22gFzR66+myELDRl5i9 gXamP+7iMQmRLAz6zTNsDkHHVNIgAOeaDM74jRKb2LgqExYgH6GGcf7MUYQ8395O4cLS GBzcEVhfCpUyRynD77v1s5za/pUJEhayK7tdIJIrM5i15848oHpLJOGUFBI+SzUWao/g h2Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=Dk8TGNQOVNzQn8cwlm1MaEPrVhLuKdgx7sOHdUet68w=; b=taqQFD79f2OENLUgjfYTeuBSPlqhkAfcZ4xqCCu8FMCPgfYzvw7nNj3mRO9RXH5sqC R1OmNq5qJsjzcQhgzt2Dz11DAwBkGpUseXJxeyphLtAp0Xh81CdbAGFs6sd1mjZ3SAbp trkslfLjUK283YEf4PW60/eXyRy0LUrM8nfNh4FwRiW3oPWJ8ncNcVDOGQZGI/KwG7lh VZLd8F+QoV8gdC9mhVZpLQlk1ygdh4X6S2ZK/rHeP7M6vlioxechi9bPDt6ofoUJqR6X WNzPPH4H/Sni6PSYKP5tIscbhBhqC1Ji15JYvd3nrnDDXYmJ3gS3SoA2V6mtLVYybJjR ch/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qHLA0FQT; 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=pass (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 w12si15763243ybp.131.2021.08.29.23.36.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 29 Aug 2021 23:36:39 -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=pass header.i=@linaro.org header.s=google header.b=qHLA0FQT; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60056 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mKauN-0007Ic-7R for patch@linaro.org; Mon, 30 Aug 2021 02:36:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46524) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mKajM-0004Na-2M for qemu-devel@nongnu.org; Mon, 30 Aug 2021 02:25:16 -0400 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]:40624) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mKajJ-0007eL-PT for qemu-devel@nongnu.org; Mon, 30 Aug 2021 02:25:15 -0400 Received: by mail-pg1-x530.google.com with SMTP id y23so12414618pgi.7 for ; Sun, 29 Aug 2021 23:25:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Dk8TGNQOVNzQn8cwlm1MaEPrVhLuKdgx7sOHdUet68w=; b=qHLA0FQTXvedK6h0BU9XOvS+oFEnmoCv874Kg41AdiAI/ZSOTCNlcteQkfzYNBfuuD 4SntmMPYG92y1f03OXDRXEuaNfKvzf7GXUnDYLwmUK91jzGUc1rML+mwnl/zMWdR7YaR U1sO20G7reXW1xSf8wmcCY4m194KSAL6PhnJ/HQ8E9XRmV2dlsJefJz+fWfQRo0s020P NvqDBZrcl3CTA0an+pczBuFKtFiOynntfkyAqINr1f5DisZfzymQ2SscMwG3JhARPwST 6kcAV/OvbMU2Lz8sWEWpAH/Vjg+PgXQqgEgfiRM1VHaOM/FB/IKEZ7Muz9lGrtHHmXSS zkrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Dk8TGNQOVNzQn8cwlm1MaEPrVhLuKdgx7sOHdUet68w=; b=XwpLvltl3Vm5nk+YorOwKjEFqr6k2HJGYOmiWnFs4/OYiWgrngfTY4yTgwKRXk9T5u rA3CJCfkO6Sn2CtN9K3ZO8qbM3UCfx8BqhhvKd0j/I4eEZoXP34Op4DhRxu6quavadRx UxGRZ6JJp5GxJz3tVLFBUOp/KenDO/5rjMoEw524WI0ENwSmeyCjOe1fJy37bxEv2oLj QVezZlvhjMaFxKpHpgcl5k/BFHF1pXL1bpy/AA1JrLW9O3LpBJil91SsAy8CMQGI656r mggU/BMPN2DkBLaEGxHeEozEK2qmTI7w3IA9Fa9H0VcWBTGu/yBFcEQZsFYcMbu0PVjF I/Gg== X-Gm-Message-State: AOAM5308bVoOHKHLQL1uXT4clahhsG5wYZDK2U/+V3zi8OojQ2j0jHT5 1Ab9Iu5WZZk5IzZ3Eb2pBZaGq/fTS7DWMA== X-Received: by 2002:aa7:9ae9:0:b0:3f5:e1a7:db23 with SMTP id y9-20020aa79ae9000000b003f5e1a7db23mr14282965pfp.42.1630304712224; Sun, 29 Aug 2021 23:25:12 -0700 (PDT) Received: from localhost.localdomain (174-21-72-39.tukw.qwest.net. [174.21.72.39]) by smtp.gmail.com with ESMTPSA id b12sm13942084pff.63.2021.08.29.23.25.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Aug 2021 23:25:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 30/48] tcg/optimize: Split out fold_xx_to_i Date: Sun, 29 Aug 2021 23:24:33 -0700 Message-Id: <20210830062451.639572-31-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210830062451.639572-1-richard.henderson@linaro.org> References: <20210830062451.639572-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::530; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x530.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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Pull the "op r, a, a => movi r, 0" optimization into a function, and use it in the outer opcode fold functions. Signed-off-by: Richard Henderson --- tcg/optimize.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) -- 2.25.1 Reviewed-by: Philippe Mathieu-Daudé diff --git a/tcg/optimize.c b/tcg/optimize.c index ee674fe623..f48d0bc52d 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -695,6 +695,15 @@ static bool fold_const2(OptContext *ctx, TCGOp *op) return false; } +/* If the binary operation has both arguments equal, fold to @i. */ +static bool fold_xx_to_i(OptContext *ctx, TCGOp *op, uint64_t i) +{ + if (args_are_copies(op->args[1], op->args[2])) { + return tcg_opt_gen_movi(ctx, op, op->args[0], i); + } + return false; +} + /* * These outermost fold_ functions are sorted alphabetically. */ @@ -744,7 +753,11 @@ static bool fold_and(OptContext *ctx, TCGOp *op) static bool fold_andc(OptContext *ctx, TCGOp *op) { - return fold_const2(ctx, op); + if (fold_const2(ctx, op) || + fold_xx_to_i(ctx, op, 0)) { + return true; + } + return false; } static bool fold_brcond(OptContext *ctx, TCGOp *op) @@ -1211,7 +1224,11 @@ static bool fold_shift(OptContext *ctx, TCGOp *op) static bool fold_sub(OptContext *ctx, TCGOp *op) { - return fold_const2(ctx, op); + if (fold_const2(ctx, op) || + fold_xx_to_i(ctx, op, 0)) { + return true; + } + return false; } static bool fold_sub2_i32(OptContext *ctx, TCGOp *op) @@ -1221,7 +1238,11 @@ static bool fold_sub2_i32(OptContext *ctx, TCGOp *op) static bool fold_xor(OptContext *ctx, TCGOp *op) { - return fold_const2(ctx, op); + if (fold_const2(ctx, op) || + fold_xx_to_i(ctx, op, 0)) { + return true; + } + return false; } /* Propagate constants and copies, fold constant expressions. */ @@ -1726,20 +1747,6 @@ void tcg_optimize(TCGContext *s) break; } - /* Simplify expression for "op r, a, a => movi r, 0" cases */ - switch (opc) { - CASE_OP_32_64_VEC(andc): - CASE_OP_32_64_VEC(sub): - CASE_OP_32_64_VEC(xor): - if (args_are_copies(op->args[1], op->args[2])) { - tcg_opt_gen_movi(&ctx, op, op->args[0], 0); - continue; - } - break; - default: - break; - } - /* * Process each opcode. * Sorted alphabetically by opcode as much as possible.