From patchwork Fri Oct 29 04:32:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 516395 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp399301iml; Thu, 28 Oct 2021 21:51:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzi441u8PkVhjtpB8wbkznrGwkZWpb48hXQJmnPDYU3bca+RYCZwptaIK8a7YoAioatvFbx X-Received: by 2002:a05:6830:19d3:: with SMTP id p19mr6635506otp.355.1635483104554; Thu, 28 Oct 2021 21:51:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635483104; cv=none; d=google.com; s=arc-20160816; b=Enl5MCje8exQBvyVKDhw319tm8SkNt4qhKk4cFcsYX7C82e1Adwoc43tvvOavQS2pX RlfRaZSur1BX2Iw00vb53v3lFHyqrnVQPPJCZvf4Bv/cjm9GyFOa6ttyM+yRgKNyCK/7 AKbF9ZwNz+lMqmNW6pvWezQk3DHLl+2El5XY/e2QFG6TGi0R6XSf0kWodtuE7veABPuh YEwXPQfTuj5ibek+rajkcnkaWvYG+zBvvJO1htIfoORqpvXSA7qCnKpMddzn8w+D4bf5 XND4rntc5D+oKQBS6asyPfePz2kV97vOwpEA38fFTb5kUmIr86LgQuPDV5R6gNVvhv3X zuyQ== 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=4b6zM17cF3RrWL3jUN3e39U/QFtejbDytYKYLpCpWYI=; b=z/ShjbV7pMlBsrYYb+NywSX8Jjvb22nCXsV4lJRyRgskRR4FT8H2fNrwila4tMNx+I QwNgH77meYSdW093b8uvh8Fgn7DYPCKH9VxQDaIqZzLkNKupn7lo6jq/vOXkaX83gjkN K6hxDKy9c2PmokmQAfXQqwMDB7vzRTdmAIrX4f+ibtujCoi3FUKfYmK7h2ltc8w0O/iS P/vTkZdw8HUN3BYgdGyokQvgDSJbHinaEMywsk5T/QR+hLW6czIUIiZSGK/Wm16y+IHT yX1DIgPR3ceAdDLzQzvP1jSGbzFBX3kkZgFy3athe3DxxUY78IpYFu0UMpJyzZfkYHJ9 fW3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=mFHQeBFA; 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 n10si1265386oom.17.2021.10.28.21.51.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Oct 2021 21:51:44 -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=mFHQeBFA; 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]:50460 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mgJrj-0003Ks-OM for patch@linaro.org; Fri, 29 Oct 2021 00:51:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51294) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mgJaU-0004IX-Sx for qemu-devel@nongnu.org; Fri, 29 Oct 2021 00:33:54 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:55961) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mgJaQ-0007xj-1U for qemu-devel@nongnu.org; Fri, 29 Oct 2021 00:33:54 -0400 Received: by mail-pj1-x1031.google.com with SMTP id om14so6331129pjb.5 for ; Thu, 28 Oct 2021 21:33:49 -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=4b6zM17cF3RrWL3jUN3e39U/QFtejbDytYKYLpCpWYI=; b=mFHQeBFA3mI0H+0vAaAzFU1wp6YwYLLGh+ZuYoyB+LurHBbYyhF/N4gVkiNXSGL18c wGriJZrtyTLcybqkHxWud8jcoCylvRxSrG9d+L1h0QWa9qa1zeMUYJr497GNF+vCRvkz osv4qn7+i3MppLG2AyS17hIn7cT/QmFkKLc0pCau7mFeyb9TQWIt3c3JRJHZ8Q0QsHwj uuTb0bUGyDvgm1LDU8OlBWUwXONcO3KhsFwLKS14hO7lPFh5sVQM727rmxgCZjDmUPrO z0REgy8GmZ7JyJLMgZtv6h/Kqj+dvewk5W++vHN7yr8t28zKU3CvwcML9ON3ZssZrmzi DuIQ== 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=4b6zM17cF3RrWL3jUN3e39U/QFtejbDytYKYLpCpWYI=; b=CZWat9cXa9NGy/T/cdfI15SDXuiXEVmuZkPbMdQAJt/LMiOl3krXuToiKArpPcHAo+ BcnFa9U1ZMdlkYC8JsIAl8Njflcba271OkRPMM7snjuk4Cg1jTTdUHVqz68Dl3fQwFoQ 2sc6pFg0o0x/thKhq2UC+Cp+K49mntmzQs65cD406I/hXdmMBNbbhSGSZ1qYNS3OI9j9 y4HH28Z5D2rqoQxAUxvlA76DtIlvNm22I3znxCSm6BcLvXQgugNiUStEXewDbSQLb+I0 Cv0cRru5CQJQCmv8oG0Zr8NYkUjhxZeZcPWpiviYgqZmH8d3NlgXgfjsmh1rE/ksokcW /PBA== X-Gm-Message-State: AOAM531W8q1UCzlyamYSbD7wvsDbKNXcTR3NTMN3DIHojg3JVti25DwF 1cV45WwYfVnf6PFPMvpQfVYgHuOP4TaCkQ== X-Received: by 2002:a17:902:d88c:b0:13f:f584:f630 with SMTP id b12-20020a170902d88c00b0013ff584f630mr7651504plz.58.1635482028725; Thu, 28 Oct 2021 21:33:48 -0700 (PDT) Received: from localhost.localdomain (174-21-75-75.tukw.qwest.net. [174.21.75.75]) by smtp.gmail.com with ESMTPSA id i11sm4120257pgp.18.2021.10.28.21.33.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 21:33:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL v2 21/60] tcg/optimize: Split out fold_setcond2 Date: Thu, 28 Oct 2021 21:32:50 -0700 Message-Id: <20211029043329.1518029-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211029043329.1518029-1-richard.henderson@linaro.org> References: <20211029043329.1518029-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.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 , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reduce some code duplication by folding the NE and EQ cases. Reviewed-by: Alex Bennée Reviewed-by: Luis Pires Signed-off-by: Richard Henderson --- tcg/optimize.c | 145 ++++++++++++++++++++++++------------------------- 1 file changed, 72 insertions(+), 73 deletions(-) -- 2.25.1 diff --git a/tcg/optimize.c b/tcg/optimize.c index 5c3f8e8fcd..80e43deb8e 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -854,6 +854,75 @@ static bool fold_remainder(OptContext *ctx, TCGOp *op) return fold_const2(ctx, op); } +static bool fold_setcond2(OptContext *ctx, TCGOp *op) +{ + TCGCond cond = op->args[5]; + int i = do_constant_folding_cond2(&op->args[1], &op->args[3], cond); + int inv = 0; + + if (i >= 0) { + goto do_setcond_const; + } + + switch (cond) { + case TCG_COND_LT: + case TCG_COND_GE: + /* + * Simplify LT/GE comparisons vs zero to a single compare + * vs the high word of the input. + */ + if (arg_is_const(op->args[3]) && arg_info(op->args[3])->val == 0 && + arg_is_const(op->args[4]) && arg_info(op->args[4])->val == 0) { + goto do_setcond_high; + } + break; + + case TCG_COND_NE: + inv = 1; + QEMU_FALLTHROUGH; + case TCG_COND_EQ: + /* + * Simplify EQ/NE comparisons where one of the pairs + * can be simplified. + */ + i = do_constant_folding_cond(INDEX_op_setcond_i32, op->args[1], + op->args[3], cond); + switch (i ^ inv) { + case 0: + goto do_setcond_const; + case 1: + goto do_setcond_high; + } + + i = do_constant_folding_cond(INDEX_op_setcond_i32, op->args[2], + op->args[4], cond); + switch (i ^ inv) { + case 0: + goto do_setcond_const; + case 1: + op->args[2] = op->args[3]; + op->args[3] = cond; + op->opc = INDEX_op_setcond_i32; + break; + } + break; + + default: + break; + + do_setcond_high: + op->args[1] = op->args[2]; + op->args[2] = op->args[4]; + op->args[3] = cond; + op->opc = INDEX_op_setcond_i32; + break; + } + return false; + + do_setcond_const: + return tcg_opt_gen_movi(ctx, op, op->args[0], i); +} + static bool fold_shift(OptContext *ctx, TCGOp *op) { return fold_const2(ctx, op); @@ -1653,79 +1722,6 @@ void tcg_optimize(TCGContext *s) } break; - case INDEX_op_setcond2_i32: - i = do_constant_folding_cond2(&op->args[1], &op->args[3], - op->args[5]); - if (i >= 0) { - do_setcond_const: - tcg_opt_gen_movi(&ctx, op, op->args[0], i); - continue; - } - if ((op->args[5] == TCG_COND_LT || op->args[5] == TCG_COND_GE) - && arg_is_const(op->args[3]) - && arg_info(op->args[3])->val == 0 - && arg_is_const(op->args[4]) - && arg_info(op->args[4])->val == 0) { - /* Simplify LT/GE comparisons vs zero to a single compare - vs the high word of the input. */ - do_setcond_high: - reset_temp(op->args[0]); - arg_info(op->args[0])->z_mask = 1; - op->opc = INDEX_op_setcond_i32; - op->args[1] = op->args[2]; - op->args[2] = op->args[4]; - op->args[3] = op->args[5]; - break; - } - if (op->args[5] == TCG_COND_EQ) { - /* Simplify EQ comparisons where one of the pairs - can be simplified. */ - i = do_constant_folding_cond(INDEX_op_setcond_i32, - op->args[1], op->args[3], - TCG_COND_EQ); - if (i == 0) { - goto do_setcond_const; - } else if (i > 0) { - goto do_setcond_high; - } - i = do_constant_folding_cond(INDEX_op_setcond_i32, - op->args[2], op->args[4], - TCG_COND_EQ); - if (i == 0) { - goto do_setcond_high; - } else if (i < 0) { - break; - } - do_setcond_low: - reset_temp(op->args[0]); - arg_info(op->args[0])->z_mask = 1; - op->opc = INDEX_op_setcond_i32; - op->args[2] = op->args[3]; - op->args[3] = op->args[5]; - break; - } - if (op->args[5] == TCG_COND_NE) { - /* Simplify NE comparisons where one of the pairs - can be simplified. */ - i = do_constant_folding_cond(INDEX_op_setcond_i32, - op->args[1], op->args[3], - TCG_COND_NE); - if (i == 0) { - goto do_setcond_high; - } else if (i > 0) { - goto do_setcond_const; - } - i = do_constant_folding_cond(INDEX_op_setcond_i32, - op->args[2], op->args[4], - TCG_COND_NE); - if (i == 0) { - goto do_setcond_low; - } else if (i > 0) { - goto do_setcond_const; - } - } - break; - default: break; @@ -1813,6 +1809,9 @@ void tcg_optimize(TCGContext *s) CASE_OP_32_64(shr): done = fold_shift(&ctx, op); break; + case INDEX_op_setcond2_i32: + done = fold_setcond2(&ctx, op); + break; CASE_OP_32_64_VEC(sub): done = fold_sub(&ctx, op); break;