From patchwork Tue Nov 7 02:48:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 741746 Delivered-To: patch@linaro.org Received: by 2002:adf:fd90:0:b0:32d:baff:b0ca with SMTP id d16csp1414661wrr; Mon, 6 Nov 2023 18:50:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IGugyOeRgWooCOL9xHu+AclI1LsQBFHDdJgEPP7uwVOREmd77QuzxucsGc8PriI6HH8C9hB X-Received: by 2002:a05:6214:21ca:b0:65b:765:254 with SMTP id d10-20020a05621421ca00b0065b07650254mr33645154qvh.4.1699325417308; Mon, 06 Nov 2023 18:50:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699325417; cv=none; d=google.com; s=arc-20160816; b=CtdohCG41Gg4/QzBqyh7nM229lOyY9SLn2L+spzihI1lw5Um/tMUsqgLG8mwV5O3b7 HgXR6gQrcCNIEGURWf1rYgeG4UwiuqDBOIWbxqYybTQWKSK1+Rs+lnqlk2tOk691cXj6 Ledzf0RM3Js1pO1ynMtv9Mltm8qvhmqN1Ovecs0bOuAey6N5L3Xb2+y8LM4rcgP6PwJ/ pVzpDwdklgjW9CWhlawo8wbM6yrCO4hH7JEjpFkLf0LoSgO5bAGbHa9jDC0KtCzAGD8H GYpi/4eYbAgbtzkNyou7mVAwMskGgqhACAHg2VgO+7w7lWhzsijqYyO1ILAVi2JPhChR w96g== 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:cc:to :from:dkim-signature; bh=YHmBTBkZIpyIbEJIll5966friKsejaD+iHlMP+LfScE=; fh=kQadAhxV42GJ3cd2VUw1RyURv/zJQGvmUdF7iLEVTtc=; b=jM9KHkEA0ZZxugx8syoEkJTun7zwXzi72s1MQLMv5HU17eMH0cHhg6VgGVbE8kYLUy uRinS/YB0i/Pwrf3Q9KLKu1ZK7u4s8R20iqEF91zGuCDVkCcZYp4BE8PWtvsYdb/2GEB 0/LLDZBKP0XASiAE9K1MFi00jbA0cB0Jo6s+E1Ya9kMftP9Lc5dH/Y2OY5jpspkqq88C PvAS6gHDwqR8dDkTehUmxjXPsg5caQGt6wJ8APyxS9iRPwQptKASHZmgBsisY/vbxhvJ uLukBylkOIWi8FhN/mjU5+ttWRekHTN2P1ZJVu6vshv1me3e0lBhAjzYTwcSrykR777X YB4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ieVjWNme; 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 p7-20020a0cfd87000000b0066d0755101fsi6396964qvr.287.2023.11.06.18.50.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 06 Nov 2023 18:50:17 -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=ieVjWNme; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r0C9T-0008SW-HH; Mon, 06 Nov 2023 21:49:15 -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 1r0C9Q-0008Qx-Vw for qemu-devel@nongnu.org; Mon, 06 Nov 2023 21:49:13 -0500 Received: from mail-vk1-xa2c.google.com ([2607:f8b0:4864:20::a2c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r0C9P-0005wh-IG for qemu-devel@nongnu.org; Mon, 06 Nov 2023 21:49:12 -0500 Received: by mail-vk1-xa2c.google.com with SMTP id 71dfb90a1353d-4ac023c8f82so1566268e0c.1 for ; Mon, 06 Nov 2023 18:49:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699325350; x=1699930150; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YHmBTBkZIpyIbEJIll5966friKsejaD+iHlMP+LfScE=; b=ieVjWNmem8Ga4QJGRrNvnMPgxwmaktNVS53aDo0vuUmfd2O8D1XJie9BEmWGVQTdGh AA+TFxXAgZOJZMfs1pj80cXFvXQU/OZITGQWozmctyr+BVYZtha/rjdorcYK5UmQZ+r3 gsXby9CoQ8rWGQnnouINm4+q8eiPpRf0S3847y9LfZJmfJEYeaZ/+JUKpa//TlrM0yxI vD3xrv6fTUiXZ7TzsK8bnkcQvKQS/4KgYn1CkfEOAgWWUFTdqcRyWh8TBmfl1PDf2EWT zTyXUd3gRu9NG5e+JwKKj+p6OgD1QpXy9AEM+r+/Wf4td2v87kS2RNC/dEIVn5F637Ln Medg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699325350; x=1699930150; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YHmBTBkZIpyIbEJIll5966friKsejaD+iHlMP+LfScE=; b=tS0VvFtA7nI7pAlnerAtw1t9GNAExHvkV+jgt6eS80WD2BiS3YgwkQwLfMhlmG+IQF /hcOAtRYBqU994xqiz0BtR6ZEJXKNkqUwoRXIStAMFMeSss1uS2SkEpk1KnXQc/ytWsU wmgb4sUrv6u/OEof/jePegeVTO/VTremz12QRsmIGEDcGrSahbBXatNSVKlWWVkcoqs6 KhAc3i+4ZCZfVlJcc+EcTTdsJyPS7e2UZ/QHE5YoYIzyrXA3nCzwea6I13lCGX/muY6/ BiDcxiDCOh1b4+a2ga69RZnZhfaot1xVWUdksud6dOj01AarMXHB75lDOXE0VNnPVzFQ 3Uzw== X-Gm-Message-State: AOJu0YyNtWEcEnUjPieTFrQliMke6cJaU/rjsDxnOnPInrah7AgwbjOj Rqac7bnLZ7Q3ECHlwT6zVvacyuOcnSEq+6JDqPo= X-Received: by 2002:a1f:2992:0:b0:4ab:fbff:a811 with SMTP id p140-20020a1f2992000000b004abfbffa811mr6793222vkp.14.1699325350551; Mon, 06 Nov 2023 18:49:10 -0800 (PST) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id fn11-20020a056a002fcb00b006bff7c36fb3sm6367478pfb.95.2023.11.06.18.49.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 18:49:10 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 33/35] tcg/optimize: Canonicalize subi to addi during optimization Date: Mon, 6 Nov 2023 18:48:40 -0800 Message-Id: <20231107024842.7650-34-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231107024842.7650-1-richard.henderson@linaro.org> References: <20231107024842.7650-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::a2c; envelope-from=richard.henderson@linaro.org; helo=mail-vk1-xa2c.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, T_SCC_BODY_TEXT_LINE=-0.01 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 Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20231026013945.1152174-3-richard.henderson@linaro.org> --- tcg/optimize.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tcg/optimize.c b/tcg/optimize.c index d8e437c826..468f827399 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -2166,7 +2166,19 @@ static bool fold_sub_vec(OptContext *ctx, TCGOp *op) static bool fold_sub(OptContext *ctx, TCGOp *op) { - return fold_const2(ctx, op) || fold_sub_vec(ctx, op); + if (fold_const2(ctx, op) || fold_sub_vec(ctx, op)) { + return true; + } + + /* Fold sub r,x,i to add r,x,-i */ + if (arg_is_const(op->args[2])) { + uint64_t val = arg_info(op->args[2])->val; + + op->opc = (ctx->type == TCG_TYPE_I32 + ? INDEX_op_add_i32 : INDEX_op_add_i64); + op->args[2] = arg_new_constant(ctx, -val); + } + return false; } static bool fold_sub2(OptContext *ctx, TCGOp *op)