From patchwork Sun Sep 22 12:00:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 830131 Delivered-To: patch@linaro.org Received: by 2002:adf:ebcc:0:b0:367:895a:4699 with SMTP id v12csp1554346wrn; Sun, 22 Sep 2024 05:05:46 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVcnKP3nPqwhtHt6jBngrTDz/z9BNjpjQfPtHJELad4MciIoy5k8KavrMHuagqY5AGVn48Jkg==@linaro.org X-Google-Smtp-Source: AGHT+IGGV7BbUJKoBeapvhsyh/gKFSZCtYS/VmKUmWH4vBpqG4neOtDecYYG45TTtAhd9XXyiS/R X-Received: by 2002:a05:6214:3907:b0:6c5:b6de:5ee with SMTP id 6a1803df08f44-6c7bc7455f8mr133072386d6.30.1727006746418; Sun, 22 Sep 2024 05:05:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727006746; cv=none; d=google.com; s=arc-20240605; b=ANKxcZtB030yadONbqHrmi4OtW5eSf+ISULERe00rn70kEJ2M8PPtJtqdoYaqJGNNp y6JsfAn+2r3adYYbyTHhkSRnvVkHXauTpjaAe+cFGoi0xyDxncAmmptLOeHVArF34xJx /NPSvT9emJ3daQiufU2VrpHkCdq6dU7VkYkAUNpnaKE57FqehVJtfMZyHtLJbpEeIowD ktj0LO7D4aiKYOsY5E2BS5RN1GBBhyz21hLObvrLTCXeSxaOQ+JJ9QGJOzp/SV98yrJ9 RHRv4nd2cnBkr8K2D5xtCjjerBpstGouV+Sp/j0fBLh9Wo31WkU74H/HSCoL1A++bdWb 4F3g== 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:cc:to :from:dkim-signature; bh=tk0wGAYaA1BFCH8Bi5mZsOhd6+SwTodI8yFR1/zj/XA=; fh=UQCixiNfr28ZOrfhmxiGPA65dFhly8CmRsnoYC6xI9k=; b=JS7ZSVXGE27suDMTf1/CW7Bi5ktai+AmmjNcmCjyKS2bJUBRoHzfG1+Br0UUFJMxbK 3ECyH983U24ByWfqsFgiO0pLrJOyxmLQb2TwLux+TOO4YzwX2UxfrbP4OK1pERYGckhH uMRQnDNm64DgSZXxuKdX/Yg1Gz2jJdoDFtp4cP5B7mFYkAeOkkxmboOAozjvFv/23/6Q cE13/aZaPc2WXvcImY/oeCwJ7ayIrlqf6qsOwfcUhHvTMTyrJcJ8qUvt2ktWdZp6UB05 CZp4XusSGJoMz8Ho72SfMV4iYQZ5tPf97InJFLoztqTh75wHRJe8L8ANayH4OeNsZ5XX O7tg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A5WIVbUe; 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 6a1803df08f44-6c75e5a7063si84032816d6.461.2024.09.22.05.05.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 22 Sep 2024 05:05:46 -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=A5WIVbUe; 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 1ssLIO-0004NU-D5; Sun, 22 Sep 2024 08:02:34 -0400 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 1ssLHJ-0000vk-Hj for qemu-devel@nongnu.org; Sun, 22 Sep 2024 08:01:33 -0400 Received: from mail-ej1-x629.google.com ([2a00:1450: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 1ssLHG-0002Na-KC for qemu-devel@nongnu.org; Sun, 22 Sep 2024 08:01:24 -0400 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-a8a789c4fc5so757458666b.0 for ; Sun, 22 Sep 2024 05:01:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1727006480; x=1727611280; 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=tk0wGAYaA1BFCH8Bi5mZsOhd6+SwTodI8yFR1/zj/XA=; b=A5WIVbUe9sWhZiblHzOYQR5NqVm9ELlEpwB78G8ZFZCEr/DYez59UbZddo7LCKBX5x kiBHtw0g1mlDuw4vcMbJ8l+kGBp9HbXdz9/FrVDFjhuZ+Qt5WkD7FPMNsGBQW1ptFcUI 6z8SO5fjzI3EvzhihjlasveaYx7nMaYuJpfERtwyGufwdnoyo1Nivg7AG5wbtgRPgMMq Ueqa+DuaAfuISE6+l1Uv+WqY9XbnQt0o7FKREgN57BW7h5TvokVxZxyqYemdtaMZ97Q9 lUJWnwA66jPxQUHBTHa9vEx5SdyVEBNV9Ky/juzj6lV9GniUCo4ypyssRJANbJnrkvlW mQhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727006480; x=1727611280; 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=tk0wGAYaA1BFCH8Bi5mZsOhd6+SwTodI8yFR1/zj/XA=; b=uxNu2+/i03FORhXmZiYDMSQEOMWqM6Pj/ClI2UwRUWSQXDrQGhPqxUrj0vi1sUQU1S 4qJOFpZAYEJrCj/D0cURNPWYkbwyRhEhAnatCFd7cxXpfTIUB1uFg/HvyB2ziTqFCmwS o6xZgDRI1InE0S32XwvC4bbKII/n0Rk2Hv1vKqohGKC5gzBfXOGA/vgPIo0PmYlaTNTP JxXc3eshOYsneoJ4Qp0kmTEhXYzoRvNlwe1kyFb1h+QA4o4vfsVzbRKPVaSsj6NOJorW 0FnqvNx0k8ZnWl5y6HS88lugjt/sNzngD46Mfo+h9LpV/gYQJ5iSKO9dZKe/FyFvuGph PjMw== X-Gm-Message-State: AOJu0YyegvTput6eBo3msNDwxf1MOYO5GT7fGvrAxEAOgGHPPgRBpRHp AoAvnsN1gzIFoRtCZ6emFgedcYeMDVBGO44Olt/8eJrpIHdKXGzWQJ3ZrbS6fKVrr2n/VpLygNW 71CA= X-Received: by 2002:a17:907:3ea2:b0:a8b:58e3:ac1f with SMTP id a640c23a62f3a-a90d3510a4amr858043666b.12.1727006480395; Sun, 22 Sep 2024 05:01:20 -0700 (PDT) Received: from stoup.. (90-181-218-29.rco.o2.cz. [90.181.218.29]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a90612df525sm1067909966b.159.2024.09.22.05.01.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Sep 2024 05:01:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org Subject: [PULL 11/31] tcg/optimize: Optimize cmp_vec and cmpsel_vec Date: Sun, 22 Sep 2024 14:00:52 +0200 Message-ID: <20240922120112.5067-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240922120112.5067-1-richard.henderson@linaro.org> References: <20240922120112.5067-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-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 Place immediate values second in the comparison. Place destination matches first in the true/false values. All of this mirrors what we do for integer setcond and movcond. Signed-off-by: Richard Henderson --- tcg/optimize.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tcg/optimize.c b/tcg/optimize.c index cf311790e0..f11f576fd4 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -2422,6 +2422,36 @@ static bool fold_setcond2(OptContext *ctx, TCGOp *op) return tcg_opt_gen_movi(ctx, op, op->args[0], i); } +static bool fold_cmp_vec(OptContext *ctx, TCGOp *op) +{ + /* Canonicalize the comparison to put immediate second. */ + if (swap_commutative(NO_DEST, &op->args[1], &op->args[2])) { + op->args[3] = tcg_swap_cond(op->args[3]); + } + return false; +} + +static bool fold_cmpsel_vec(OptContext *ctx, TCGOp *op) +{ + /* If true and false values are the same, eliminate the cmp. */ + if (args_are_copies(op->args[3], op->args[4])) { + return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[3]); + } + + /* Canonicalize the comparison to put immediate second. */ + if (swap_commutative(NO_DEST, &op->args[1], &op->args[2])) { + op->args[5] = tcg_swap_cond(op->args[5]); + } + /* + * Canonicalize the "false" input reg to match the destination, + * so that the tcg backend can implement "move if true". + */ + if (swap_commutative(op->args[0], &op->args[4], &op->args[3])) { + op->args[5] = tcg_invert_cond(op->args[5]); + } + return false; +} + static bool fold_sextract(OptContext *ctx, TCGOp *op) { uint64_t z_mask, s_mask, s_mask_old; @@ -2928,6 +2958,12 @@ void tcg_optimize(TCGContext *s) case INDEX_op_setcond2_i32: done = fold_setcond2(&ctx, op); break; + case INDEX_op_cmp_vec: + done = fold_cmp_vec(&ctx, op); + break; + case INDEX_op_cmpsel_vec: + done = fold_cmpsel_vec(&ctx, op); + break; CASE_OP_32_64(sextract): done = fold_sextract(&ctx, op); break;