From patchwork Wed Sep 11 16:50:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 827461 Delivered-To: patch@linaro.org Received: by 2002:adf:ab1c:0:b0:367:895a:4699 with SMTP id q28csp891572wrc; Wed, 11 Sep 2024 09:52:51 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVWs4qZ/O9YT+ltl77meG8xk6bBWikJqSfpwbxxnZfwsl1vb/7EzEZMVuiNFBI7NvHWKTs9kA==@linaro.org X-Google-Smtp-Source: AGHT+IFY/EqSBdT1bc2DMpzBRuUbm6XbBfjyFZYV/xGQrP5g3mAPu+nZZsLj3HJme18w0MHP0N32 X-Received: by 2002:a05:6214:3a8a:b0:6c5:1a21:b8b9 with SMTP id 6a1803df08f44-6c573514ed0mr2424146d6.13.1726073571198; Wed, 11 Sep 2024 09:52:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726073571; cv=none; d=google.com; s=arc-20240605; b=CNLgGbQ6UkrvPbSnPFRGRvtSVZI4M8fOJ6uPssgXnpUGyL//DVGY5QWdVblO/8BOvl 8vRI5jY28sBw3tjERXX1A3xN38EhRjeK3JNArG7Buc/PpzUizlaW5Zs2jifGmXjf/akO 0pWZzfjQ2vCzGBjeXzEdjh9SsP9HznRygKybA9Ag4BILmyIkG8sDTMtf4rIfyMcUpMXJ ZouK2QZ5JucFiOCJxxk6jb7CyhD7fwyzY5Rdbe9RDWZSnTVhD6NtV6raW4qCR4qrwifO PX/mKlHGxoUex9UtBBcg7Imuq4HLyXYji1NOH41WzTTVXTOVq37f0e5sfJ8eCeaII+PH aCbQ== 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=gW8xxqNJ+GKzLr7OBpcms3Apqae8iNJSKgK4r5swIT4=; b=HZDwIWH8eTj/Uq/l9jfrYutIUZt5nw9J+uGbZJ25LcBxljGXyidkKHWB04k/AhfN32 VrCeCe26OatR6N3qNHqGREWrKKmwCNOlMRR9m0vkxYIeM3ac4CkkiOGmOq4Ji8IC6TDB fWAD/IJDdHLyMeRikwEDFhHeVERSiF6UAQGiHJEK7Qn1OXeMApzBicj2SvKi2YnUGSo3 Fqfh9ZaJTFBg2mqQqdQ34Sxlp94bIifI8LeB9O7Xvx7AszCXJhKfD4gI5UYZsW4hJXo5 q9c/+HyMYcuF9fIpeohj/VJUSqVUqAdHVb1GdQ6p9gARKnsnvZD10YSLzz3zwWjDlr80 M1uQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FlXBPM95; 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-6c5348c9911si108763086d6.566.2024.09.11.09.52.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Sep 2024 09:52:51 -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=FlXBPM95; 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 1soQYX-0002JI-U3; Wed, 11 Sep 2024 12:51:01 -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 1soQYV-0002An-Oc for qemu-devel@nongnu.org; Wed, 11 Sep 2024 12:50:59 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1soQYU-0003fR-5h for qemu-devel@nongnu.org; Wed, 11 Sep 2024 12:50:59 -0400 Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-7db174f9050so30673a12.3 for ; Wed, 11 Sep 2024 09:50:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726073457; x=1726678257; 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=FlXBPM95djXqNx3Cm/ZUu/skoabuT4/rvdoEIgRp+jdM+Whfwczis24DJyL28ibXAG 3lKAZW0fVBA47XqunI6+DRHrFqWetkE46Nt0dMG/SpR9+ucSj8eUox2KwBApJDggdl40 uu+5tPRBgb2MWZ4lTU68aj5eJFDYsny+U1qQKTGYz1DuOlkNZqjpXMcS8le3lKt2yP7L 0i5taD+z4pOWt8MmSpAwlHyMSgj511YLzovK+p24mddpYx/P/3AchQpN7IFK66gHH7R3 X0tsQtGEJWUExbmR59i0iHe/cg+IIPJo9MjPWUZat1HcHsTvvJeXEkGEkLJhwVcL886b lmVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726073457; x=1726678257; 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=vzNMcmEPtAHbo2uHzyZqAQPGjeBjymD3aCAxdt5lUjQ7UuO6umlj0UfLSm222E/6Hs u2adYoeM6YidjhFeh+nq9269pRGqTatODrJGa19VQuBnbh4WJYwDPIXeha644WkivMAw z5O+5+J2jlmdU24Q1P1OieDd16yp0khkCleqZxCdtH67Iz0FswRsJXOUaVW6rAtCUkb0 wGQ37CF/RWtUyEBLMqHrGd9ZfzZdCELrZ8FGUS3ivQa/78ZXqdp+cBjoCdYOfkGRMODh 0vgzglvSb+GVtUviPHEAGNDJTdqcy5+FG2kf3mbeFNivvWwLT61lTkEholKl/DKHXKki mcJg== X-Gm-Message-State: AOJu0YzBVRcvavn+fr99Uy1LDkuD0azLmos+qvM7VsJpU+ZuV3X1UnfV vTFUr3MjHOGu0rnu66/m9SaNoBVtrkLR2Oxf9VbPTUvF/uEWlhJ6xxgkx3IrdoWTvqEaFrUn9xV + X-Received: by 2002:a05:6a21:3318:b0:1cf:54bd:393a with SMTP id adf61e73a8af0-1cf5e15780fmr5944984637.37.1726073456480; Wed, 11 Sep 2024 09:50:56 -0700 (PDT) Received: from stoup.. (174-21-81-121.tukw.qwest.net. [174.21.81.121]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fe4e7esm3186947b3a.80.2024.09.11.09.50.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 09:50:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: zhiwei_liu@linux.alibaba.com, tangtiancheng.ttc@alibaba-inc.com, philmd@linaro.org Subject: [PATCH v2 08/18] tcg/optimize: Optimize cmp_vec and cmpsel_vec Date: Wed, 11 Sep 2024 09:50:37 -0700 Message-ID: <20240911165047.1035764-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240911165047.1035764-1-richard.henderson@linaro.org> References: <20240911165047.1035764-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x529.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;