From patchwork Fri Jun 22 09:13:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 139591 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp635379lji; Fri, 22 Jun 2018 02:14:53 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJqb/WLhrahy5KgWwalq7r61+Du4JPxl6g+6Dw1PUK85QRPelxloc0EFAxtICK6nXzQHU4i X-Received: by 2002:a65:61a7:: with SMTP id i7-v6mr687820pgv.219.1529658893516; Fri, 22 Jun 2018 02:14:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529658893; cv=none; d=google.com; s=arc-20160816; b=s69HCN+1kpsnzZIhbFQy+P43gfdc3SZepRmgIt6MJUEqq1sPUCGTOFg0rqyV7KUGTS VHHj4/NK7wjmLbiCtDjDIQrAZxIYUpA3qSkLzSfJidsZH16MicPdSOTa22P0rIPbU+kc cX4pBcNrDBlGaMGPxa9Vae6O7pdTcfl92vDAHASWJBwuxYcAmlbfSoG2C5+aACQYjKDs bhcTYcGZefecWKuBM//BYAEOBitOY6mzniTv8q2FB1IG6mByCNqnPTdgWUXFOZlpqYX8 tw36225Q/6QtasLdpdMyZSZPSnfdwrlP5W4TKuNsPoPzI7DHt5NJD/Nf/lcVOdiGxh4f 8ulQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:mime-version:delivered-to:sender :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=RQMvy3Wgcq12u5Vz+YlOgtT7Ay5JkUWCh8sDE7tq8vY=; b=PZlltblQ+1iKgrW+bETq4YXyeRb4bP92g1+Mqgu8hEuAj8osTBef9IERSa2dW1PPZ1 Nmq9R8T6Aur0aKwamo5TptYA24k/H8tf+NBoEKQHvlxHbXik68QroG6OADnNvjABJLwA k1g62N8O0q/C23qTLOTkh65HgVCNp3eU8pVoC+EiWsSzlUkjdxeug1V2M2NfabkFGyWo wUvNN8S1QFJAnOiyvB8uv7l0qJFnBq9+Bo5z275xJR9B/M4S9PkmQtvdidiu0jU/eY9p cpTPC+ngY6mw/K9mcBcOkQ4XjCURAPzeVr1PwntLKkYSMwfYRbfygR73RW47ZfPqx7GT +8kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uz9wQz3N; spf=pass (google.com: domain of gcc-patches-return-480263-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gcc-patches-return-480263-patch=linaro.org@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id 5-v6si7307554plc.203.2018.06.22.02.14.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Jun 2018 02:14:53 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-480263-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uz9wQz3N; spf=pass (google.com: domain of gcc-patches-return-480263-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gcc-patches-return-480263-patch=linaro.org@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=Fjw8LCql1BxFAZXHrVymzQeHdtr/vFjEdiPl3smx+A9S1n jItXpRr+lKyf51AypMN4E5Le1lk7emebt8m9al3LeZ9zWIVy6gNrOdcr67wOmmg8 BNDNKLxUvdmOOuABuyEtut+C2uW6bqybTSb1uQZluFbpwpJpW0JWBJ3X//O40= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=IdDmf0cQazpJxLSGJ5BzFi4rtNI=; b=uz9wQz3NM3F0jakjaffC afc6JeNWdVrls7jF8tRjXm2yks+Z+otgqOuQbLp38/Bu64HaTew/0Yhti+2I4UV3 gAEg5zjhlyeyTrGxpZsCbsh/IgbzdxkyzVfLNAnoSFuvv4Tc07wcDCvwilOKv/Yk X9xdHcMXO3rr+7R4g6ME3mE= Received: (qmail 38760 invoked by alias); 22 Jun 2018 09:14:40 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 38556 invoked by uid 89); 22 Jun 2018 09:14:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=build_zero_cst X-HELO: mail-lj1-f180.google.com Received: from mail-lj1-f180.google.com (HELO mail-lj1-f180.google.com) (209.85.208.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 22 Jun 2018 09:14:37 +0000 Received: by mail-lj1-f180.google.com with SMTP id o26-v6so972990ljg.3 for ; Fri, 22 Jun 2018 02:14:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=zcHBClI6oeFF0DTLW4Tqbrl5jDaLSLogp+HEfxqIHu8=; b=RHeq57RwiKTySCE0oQbbnzO2ns1GLJGVROFnbi5E88Mq5abbvVjNIpjxjALPi3lVtZ cVLkgdZ71w4cqpIaoTdsvK4ZZYV35CmWPW/kCEqGmnS+73nl2DHjUSL7BjjkDygxq07K 25COEhuHYXiJmVzjWATks81nYxt1LXa1VxNgn53XXsXo3KltJPs6kDBi0d4Z4AmrHZCR bM9zTc3zdw0Vn7/g3GtOpaWejiDqAc9hWuwrffUx6AHhQ5jumO79z8XMkuWdR00EYfeb a+0uKvJePKWsxhFx+9wOPtOVTyNgijkSNADkfEDfixpIofRMfBalzv5/d9tXxv1XBTp0 CI9Q== X-Gm-Message-State: APt69E11p2UouJa6Ce5iaiVEj3hWN5aaKJCO0I/O2TGUM3mr0BwKwyUU 7lglNhXTHfjzvr0VTC1eOUw5iLNFRVDqDtVCe3zwbDnoTlY= X-Received: by 2002:a2e:61a:: with SMTP id 26-v6mr635275ljg.91.1529658867717; Fri, 22 Jun 2018 02:14:27 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a2e:1302:0:0:0:0:0 with HTTP; Fri, 22 Jun 2018 02:13:47 -0700 (PDT) From: Kugan Vivekanandarajah Date: Fri, 22 Jun 2018 19:13:47 +1000 Message-ID: Subject: [PATCH 2/3][POPCOUNT] Check if zero check is done before entering the loop To: GCC Patches X-IsSubscribed: yes gcc/ChangeLog: 2018-06-22 Kugan Vivekanandarajah * tree-ssa-loop-niter.c (number_of_iterations_popcount): If popcount argument is checked for zero before entering loop, avoid checking again. >From 4f2a6ad5a49eec0a1cae15e033329f889f9137b9 Mon Sep 17 00:00:00 2001 From: Kugan Vivekanandarajah Date: Fri, 22 Jun 2018 14:11:28 +1000 Subject: [PATCH 2/3] in niter dont check for zero when it is alrealy checked Change-Id: I98982537bca14cb99a85d0da70d33a6c044385fd --- gcc/tree-ssa-loop-niter.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c index 9365915..2299aca 100644 --- a/gcc/tree-ssa-loop-niter.c +++ b/gcc/tree-ssa-loop-niter.c @@ -2503,6 +2503,7 @@ number_of_iterations_popcount (loop_p loop, edge exit, HOST_WIDE_INT max; adjust = true; tree fn = NULL_TREE; + bool check_zero = true; /* Check loop terminating branch is like if (b != 0). */ @@ -2590,7 +2591,37 @@ number_of_iterations_popcount (loop_p loop, edge exit, niter->niter = iter; niter->assumptions = boolean_true_node; - if (adjust) + if (adjust + && EDGE_COUNT (loop->header->preds) == 2) + { + /* Sometimes, src of the popcount is checked for + zero before entering the loop. In this case we + dont need to check for zero again. */ + edge pred_edge = EDGE_PRED (loop->header, 0); + gimple *stmt = last_stmt (pred_edge->src); + + /* If there is an empty pre-header, go one block + above. */ + if (!stmt + && EDGE_COUNT (pred_edge->src->preds) == 1) + { + pred_edge = EDGE_PRED (pred_edge->src, 0); + stmt = last_stmt (pred_edge->src); + } + + /* If we have the src != 0 check and if we are entering + the loop when the condition is true, we can skip zero + check. */ + if (stmt + && gimple_code (stmt) == GIMPLE_COND + && gimple_cond_code (stmt) == NE_EXPR + && pred_edge->flags & EDGE_TRUE_VALUE + && TREE_CODE (gimple_cond_lhs (stmt)) == SSA_NAME + && (gimple_phi_arg_def (phi, loop_preheader_edge (loop)->dest_idx) + == gimple_cond_lhs (stmt))) + check_zero = false; + } + if (adjust && check_zero) niter->may_be_zero = fold_build2 (EQ_EXPR, boolean_type_node, src, build_zero_cst (TREE_TYPE (src))); -- 2.7.4