From patchwork Thu Oct 21 21:05:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 516095 Delivered-To: patch@linaro.org Received: by 2002:ac0:bf50:0:0:0:0:0 with SMTP id o16csp343907imj; Thu, 21 Oct 2021 14:30:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMAvw8CMsxQHf5M1rHDoGekTK/LMj8na37j7kvde2Rc/yVXA+0jPmoLML5hj3cd74j7fBF X-Received: by 2002:a05:6830:418c:: with SMTP id r12mr6964849otu.148.1634851807316; Thu, 21 Oct 2021 14:30:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634851807; cv=none; d=google.com; s=arc-20160816; b=GuCHIv45CrpkB4Vbedt6DgbpxiSoIgpdldMgiqK1oRlt7j6beeGIFdzxhUHRLN/xyW rPYqSjgQOwXvG2kkWPnXcX4o0p6otONpSqWBh0geIu8YdQ8zcASqB4qR4II1BDWleRa7 SfnGSOr5ds93GeAMEoJhaj0apNom9QnyR+GGsPK0fPh4gjsX0EMoTxMBFahFGMtPenB2 FR441DJvd7G8gzYx4b0U+a7YQ0GdEa1pGvdMNyVthoV7EmexGRzpD+o/dq6l25cjNCFt rFBjitE0TtHsCi283Wc7FrNz3/lA4pkcqI13qliQSPVmP4ELKCmRcGqIhCwuhoPS3WZc HF2g== 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=+uohhzNTf7E5o0HvirytHnR+Nn+FzxrY7IKuf21OlIs=; b=DMw79Ej4WdqSAeGL7YlriPWmsZz0Vl1pUKlvMzwMi6ooaFcGjkfoAs0TURCAk491I/ JKy8HK3E5LXVH7QvBhlLYSB2FSmi31T6azZXI+vwLTsiKCxlIGI7uKJDZ/PEWB1oCGhl lNF7Vp8I3hiEf2k7Ge2dudGVGBKn5nKJjK2QvPIvZyCaJiyrMTavjDTveqWaim6NWthp kt1fhqDe1FAjOMWUpmaFDjgR/zTnKF5TQWJygW+u9mamEnNz+xATDSWANHtoEe7GMPRq uZdX4XdiLtCgkrobxNki7ZcAnNHWRbsR06DbNMO/pW2QJ0DF9nfD4plFOpxRdAd1TKmf eMzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=uoTduUiw; 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 90si6303215otx.305.2021.10.21.14.30.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Oct 2021 14:30:07 -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=uoTduUiw; 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]:47986 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mdfdW-00066w-Il for patch@linaro.org; Thu, 21 Oct 2021 17:30:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48634) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdfGL-0007fS-E4 for qemu-devel@nongnu.org; Thu, 21 Oct 2021 17:06:09 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]:39654) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mdfGH-0004bT-RL for qemu-devel@nongnu.org; Thu, 21 Oct 2021 17:06:09 -0400 Received: by mail-pl1-x62a.google.com with SMTP id t21so1283838plr.6 for ; Thu, 21 Oct 2021 14:06:04 -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=+uohhzNTf7E5o0HvirytHnR+Nn+FzxrY7IKuf21OlIs=; b=uoTduUiw0VNq2G20WtL0fK3YpHmLXYFNyhYdb9HjDo3WnkBPEcZcivjB8fXIKoiDNE ukBW6FSnLV1lwmpnn529Yf7h62Tig1675XOUZutQleRMOwwG3qgp024gXBHoUybO4YF2 v9yR0bnREiY0Cd9Mwwn4JFBKZZY9af0IWsfm/00cTiA1opY4loDkB5+pXdSoMn0ro8VP c0zzBKd2pHgDHZSbqE854YUEiu8NwO3FsBz8R7bASm1kdsTaR473fsaYPkb5wRPSHHdi DwC2/6oh10r2y7i9rujDuqz3S+3cqnXWtJumpK/TBnTo7vTkfP8IUJwfh4Xa3ekXrVZw 2NcQ== 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=+uohhzNTf7E5o0HvirytHnR+Nn+FzxrY7IKuf21OlIs=; b=htJxo86OIwsmamcOynzbOWFhx+wImHY0x01Lny/l8CFHrco/S30NjS91+31eG7er5T lNpLOj6ATtAYcbLc258FPT15AHSQpNvcz9/j/Nofu60k0Lk5d1Tktz2S63IKmUW/6GmQ TAXOoE7ACM1coSY4Enc9PmEUCTwmOLmIvOyDuONV3e4v5bdNuRDiIKguq74B6tJw/mn5 GM+Lm/JYQaGGy1MI8xAEFaZTEOWiXVjpc/bOPVUjRnVLMZ4PDlnrr22y5PCDSJbjDSSS Mh3F+2aXRvWQkLhrOPMz4aacUp+gL+tW/bsnEmzFF07dWKP91Q1L73HsqWj9SgKGYlmG SoZA== X-Gm-Message-State: AOAM531zsvuEJoEs+h6bM1VGs4pdX9tlB65PtxsjOSgIyl7mUNQtGta4 ZrdCTuBg+c/CMw4aFHhU4eyGKqrZdKc= X-Received: by 2002:a17:90a:6b0d:: with SMTP id v13mr9331861pjj.138.1634850363487; Thu, 21 Oct 2021 14:06:03 -0700 (PDT) Received: from localhost.localdomain ([71.212.134.125]) by smtp.gmail.com with ESMTPSA id g7sm5981670pgp.17.2021.10.21.14.06.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Oct 2021 14:06:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 31/48] tcg/optimize: Split out fold_xx_to_x Date: Thu, 21 Oct 2021 14:05:22 -0700 Message-Id: <20211021210539.825582-32-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::62a; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62a.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, =?utf-8?q?Philippe?= =?utf-8?q?_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Pull the "op r, a, a => mov r, a" optimization into a function, and use it in the outer opcode fold functions. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- tcg/optimize.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) -- 2.25.1 Reviewed-by: Luis Pires diff --git a/tcg/optimize.c b/tcg/optimize.c index 5ac7a45597..8dfe8694da 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -704,8 +704,22 @@ static bool fold_xx_to_i(OptContext *ctx, TCGOp *op, uint64_t i) return false; } +/* If the binary operation has both arguments equal, fold to identity. */ +static bool fold_xx_to_x(OptContext *ctx, TCGOp *op) +{ + if (args_are_copies(op->args[1], op->args[2])) { + return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[1]); + } + return false; +} + /* * These outermost fold_ functions are sorted alphabetically. + * + * The ordering of the transformations should be: + * 1) those that produce a constant + * 2) those that produce a copy + * 3) those that produce information about the result value. */ static bool fold_add(OptContext *ctx, TCGOp *op) @@ -748,7 +762,11 @@ static bool fold_add2_i32(OptContext *ctx, TCGOp *op) static bool fold_and(OptContext *ctx, TCGOp *op) { - return fold_const2(ctx, op); + if (fold_const2(ctx, op) || + fold_xx_to_x(ctx, op)) { + return true; + } + return false; } static bool fold_andc(OptContext *ctx, TCGOp *op) @@ -1101,7 +1119,11 @@ static bool fold_not(OptContext *ctx, TCGOp *op) static bool fold_or(OptContext *ctx, TCGOp *op) { - return fold_const2(ctx, op); + if (fold_const2(ctx, op) || + fold_xx_to_x(ctx, op)) { + return true; + } + return false; } static bool fold_orc(OptContext *ctx, TCGOp *op) @@ -1732,19 +1754,6 @@ void tcg_optimize(TCGContext *s) break; } - /* Simplify expression for "op r, a, a => mov r, a" cases */ - switch (opc) { - CASE_OP_32_64_VEC(or): - CASE_OP_32_64_VEC(and): - if (args_are_copies(op->args[1], op->args[2])) { - tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); - continue; - } - break; - default: - break; - } - /* * Process each opcode. * Sorted alphabetically by opcode as much as possible.