From patchwork Sun Feb 16 23:09:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 865896 Delivered-To: patch@linaro.org Received: by 2002:a5d:64e6:0:b0:38f:210b:807b with SMTP id g6csp863802wri; Sun, 16 Feb 2025 15:36:37 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCViZrb31ba66Y/ZWFzoP7Xg5YqF5AIJMfA9qqeu9xCLwA9JVz6fsjDcpHG2NeiENp6j5Q9tpw==@linaro.org X-Google-Smtp-Source: AGHT+IElYb9b+kq54Q9yvntdOAyk4/I/yv9QakRfObmwY/ng72itYWkBtAyW02v62NsuEessbjZb X-Received: by 2002:a05:620a:f05:b0:7b1:3c0e:3289 with SMTP id af79cd13be357-7c08b1567cbmr928152385a.22.1739748996826; Sun, 16 Feb 2025 15:36:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739748996; cv=none; d=google.com; s=arc-20240605; b=J5l1fZ0mxZ8SIEdlezMeYduLrF9kYPtYOnO0d2jU+z9iTjVzmNJ5oEnt+KcqYcIA/P yWkhSw7T51T+NPV81kGEzh1Hgc9wqv/TVQdRoWSM9Ud19EVlW86i9Fb3eFjsFm9O8M6k /wL/UfdUU1pd2HFrMNeb4weh+JIdAb6xMUmjeKpywoZPeV7ZExIRYlbIoPDETlSx7NDP Mm1EGx5D9Ch8L6k//IFTvgNYIeF9hs737iyhErEQND7N3Pn9DgGr7fTaRdZukPJa0Wyd sI8XeX0RDbrvSaCJqRlAf6K6z1GTvpMGiX+6oYiHgMYXlEEtXPlZDD4eSRZjNOLIE7G5 5eDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=UoYZlm7zVSvFmsayL1ZEjyim5bfv044BhHGM/lCIFRY=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=kAogcS+sp7DL89YfuADLvMjdlm+0+/luWD9dumPYWiAzKDfLEYSX9cIePkVXIHAGbR oNIrtQtpyMjk5V3V3ljVfRxMi7nunPAxrxqk9FUOi9+ansDpxyujfbo6ihV7LIw7qfVB IhFCvfvEJk9Mny/c+66dqZJCBeH/Q3PbnWpAaMHYpjzB107MFbgriVgI/J/7JL9DYHvM FvqpWbnC+KtsXm21BjjV1VTFuq5EuhmUYeDJOVLWRapsldVe2ubRNtgLoR0AQp2GcuNp 8ilhjDYcCb2vaXQONirdv6wCcNzGSwhLwRXWZHYPj2PMQy4MqtFaQXUhodyKlQrjzhzX VlNA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yIWdBZgU; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7c07c8927d8si770163685a.426.2025.02.16.15.36.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 16 Feb 2025 15:36:36 -0800 (PST) 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=yIWdBZgU; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tjnul-0005qn-8D; Sun, 16 Feb 2025 18:19:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tjntP-0002yt-Ro for qemu-devel@nongnu.org; Sun, 16 Feb 2025 18:17:44 -0500 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tjntN-00065m-TT for qemu-devel@nongnu.org; Sun, 16 Feb 2025 18:17:43 -0500 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-21f2339dcfdso56394135ad.1 for ; Sun, 16 Feb 2025 15:17:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739747860; x=1740352660; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=UoYZlm7zVSvFmsayL1ZEjyim5bfv044BhHGM/lCIFRY=; b=yIWdBZgUg+Lq5Xav5/dDbrvkhT3wt5+/H+V8t5GOq76wSai7xe2SAFZKANsfLKe8Nb o/PwOtTmSpbJ8j68VjysovhlQqE+n576xZnNGDUSON7gparJ5MBqFTDQEa24+IOOetKG fzfkok+oYVl0Qt45LFRuxzDhaEtKKgG7HY2omS+IEFEb5PlL+7si7Y7BPL1EPf1pwO2u Y8ya/FTCDmaFwONa5Aoognsjz+vv7a7wjFoA6cgO11j0MO79KFgQfP/bF7ldEgDjoKgU +bxfyelpIH6NmLTWeQLHNjJqwpOpAWQWUvr1RJfw0N64tY2aMTy7f1TeUDPw2nbztEKs 7Zmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739747860; x=1740352660; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UoYZlm7zVSvFmsayL1ZEjyim5bfv044BhHGM/lCIFRY=; b=J/H8/XtXsJoY5RJbnS8WZEzkxwnPj/+hu/LLgx1F9WbngU4Mikd6qmdlM61lFVQOCU YCFwluMNQ5gd51WoJC26FfivpAgFevJfuK25ISdAEfV9Tf8xMJ+VYniordd69AzoyxJn iaY4/mWon8l6Elhqc6pWoX3quywRCR3pMD5BfaFo0mucjPr7qjIWc+MbmVut4rSAjeJf aOOD6FoTJ40zb7PLnZ4rbWtEulHJRIrbdDbhWmKhDARWxWPyEszB/yE3nPby+ZkGHbsO LX3CGGmHOE0+gb8sZvKgcEVaCEfjV3g0UEqlc5agTtVAeEK36Wwkib0BIzO6zYTdxWys xdqA== X-Gm-Message-State: AOJu0YzNRkzxxp9IR9mTcfoAG7n4yiWPFW+r+KIdavx4TUOa57fgs9a3 GyUyE9d6ZAlRiL4l+ikhrvvHjv2qv7HM4MyOGmcFEmry+GVOtYf4Xtz+KbQkHBuG2EAA9o0DYTv w X-Gm-Gg: ASbGncujcgihUdthtxE2OM998pyypFDLbogEItruZAVEJ9TsfhYfgVPYj/6fmNbBXrL czPolekKway23631nDTgDVRKSVQby5UKj5oJOODzx3+mk7o9gn7ljv/tVxPmgDgp4hEbXCG83ee H+zgohywYroROqsOcagapU+eMht/LGFFMrVTcb2QvVkc6UUfwfaHgWxYZzzNwnqFyFy1h9Yj4cN xjzL/mCX7U9vJVd6qVn1T+oE2cizOX0G+QNTdqjanz10YesQFY5u0OYOQkKloHlvOaZmZ0nN/nd ZflFSBrCnQkRK1LVSrKDnpWijeERedBdndkdZ5VK3m6fWbA= X-Received: by 2002:a17:902:f64f:b0:215:6c5f:d142 with SMTP id d9443c01a7336-2210460c80dmr103518895ad.20.1739747860436; Sun, 16 Feb 2025 15:17:40 -0800 (PST) Received: from stoup.. (71-212-39-66.tukw.qwest.net. [71.212.39.66]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2213394d6c8sm5449885ad.181.2025.02.16.15.17.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Feb 2025 15:17:40 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 115/162] tcg/optimize: With two const operands, prefer 0 in arg1 Date: Sun, 16 Feb 2025 15:09:24 -0800 Message-ID: <20250216231012.2808572-116-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250216231012.2808572-1-richard.henderson@linaro.org> References: <20250216231012.2808572-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.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.29 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-bounces+patch=linaro.org@nongnu.org For most binary operands, two const operands fold. However, the add/sub carry opcodes have a third input. Prefer "reg, zero, const" since many risc hosts have a zero register that can fit a "reg, reg, const" insn format. --- tcg/optimize.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tcg/optimize.c b/tcg/optimize.c index 1b3d0b5b5d..442f5b75e6 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -725,12 +725,18 @@ static int do_constant_folding_cond(TCGType type, TCGArg x, #define NO_DEST temp_arg(NULL) +static int pref_commutative(TempOptInfo *ti) +{ + /* Slight preference for non-zero constants second. */ + return !ti_is_const(ti) ? 0 : ti_const_val(ti) ? 3 : 2; +} + static bool swap_commutative(TCGArg dest, TCGArg *p1, TCGArg *p2) { TCGArg a1 = *p1, a2 = *p2; int sum = 0; - sum += arg_is_const(a1); - sum -= arg_is_const(a2); + sum += pref_commutative(arg_info(a1)); + sum -= pref_commutative(arg_info(a2)); /* Prefer the constant in second argument, and then the form op a, a, b, which is better handled on non-RISC hosts. */ @@ -745,10 +751,10 @@ static bool swap_commutative(TCGArg dest, TCGArg *p1, TCGArg *p2) static bool swap_commutative2(TCGArg *p1, TCGArg *p2) { int sum = 0; - sum += arg_is_const(p1[0]); - sum += arg_is_const(p1[1]); - sum -= arg_is_const(p2[0]); - sum -= arg_is_const(p2[1]); + sum += pref_commutative(arg_info(p1[0])); + sum += pref_commutative(arg_info(p1[1])); + sum -= pref_commutative(arg_info(p2[0])); + sum -= pref_commutative(arg_info(p2[1])); if (sum > 0) { TCGArg t; t = p1[0], p1[0] = p2[0], p2[0] = t;