From patchwork Fri Jun 22 09:12:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 139590 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp634627lji; Fri, 22 Jun 2018 02:14:01 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJKRZiUM8eqtO4KBYR5BRHRDXvpamwuUkMfplSIaWnHN6jS2P2fz5R48pfn8U492vVrdkl/ X-Received: by 2002:a65:6657:: with SMTP id z23-v6mr682671pgv.257.1529658841583; Fri, 22 Jun 2018 02:14:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529658841; cv=none; d=google.com; s=arc-20160816; b=p+VTJTVK7Bm1BiBdy+1dOPSz2xop4FR3aqVKo57EK72wN26LbDmqiFEAZtV740ZjSy ahbTkuia31ac0j4JVdSyZQXghs5HE5+vRwMTYYoN3H8BW5yxZeBns1Dj+iDc2E2TkAxr JMfD8EWruqAOSud+kDQQsELxw9Cfu+NUwTMtZr+CXFxQ3utq/zsUflvr/FCGYi4b/IPu JjNA+y6XBuxQdvFGIPJPjUybQ147kx5NVPghmpIrc9y1f+nxdQbU6svTkOzZXsxzCg2A zdAi8/gLQKBMoX8hUwX9tWLAjqD6N3WYLKFMiaHVLF1bNBOWyeh3NmYEtmCqCkcC45Do Z46Q== 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=GmdOh4DO5aSFQE5Fq9usYdF5SS2k0QJWzkoZ524J/Ao=; b=GaCBQdsi0JTjY4ive1ki6cUdFVALSQLiI+3wa8I1WqstRHzZL0T8TnZOLGhj4dVyBz 6X17lMhRX0oSbSQSBjvfBMfFEHYV8P9EOl8xyD8lsKlf3a8/o92x6UnDeHxnNu+fKUK6 75M68lFu3PvyJEz2mmY6cFc9DNsu+7DrPIb24oqV2REbpd/tCA7/bn96jBgPl7ZWAOcf vxzUBifArQkE8uwvYmB0dm2q99bZPSktTsdRkrbVpQQa2P7BRtGqS0nVNnKMf6tdABXc TlOPnvg+LWzU1dnhG6TO9/S3wzDAJucUjD6lcLGqXBk9xBS3nALu6DnwTfN5vyO40rnW Xsuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hmoYdP2G; spf=pass (google.com: domain of gcc-patches-return-480262-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gcc-patches-return-480262-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 m89-v6si6991062pfj.192.2018.06.22.02.14.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Jun 2018 02:14:01 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-480262-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=hmoYdP2G; spf=pass (google.com: domain of gcc-patches-return-480262-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gcc-patches-return-480262-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=fX5/3v62sVTeVylNi+e5Wz+iEJ2uBz0gPjdL99XhSON8de J9Kr9NQytLjpICnEGfrnjy/8Ga00arJRwENn6r3MTCvxAvJcxrv3HT71s67GOfR+ OQlNNzSMxFXBCVemZfxs1swKgHpu+mAw/UjUZyGPHedjsW/88FYLfHLFVcOTY= 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=N1Bif0TrLRdXpFzg42gisdVuFBo=; b=hmoYdP2GrMIWPK6+CGcA ve/UGUWlREuHa6zYH+Mn0zC8wQRuiPAZNDhgKn9BJo/BCvlze3NOKzO2M2oJ2xEJ oZajjlIEnkxACwR0Uef3gwwPrkVFgV94FtxhLTbjZ8giJVIrZ2F1Nu47LB40RJq5 1/QlGJVmftoLxjBHw6R+5vU= Received: (qmail 35349 invoked by alias); 22 Jun 2018 09:13:41 -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 35237 invoked by uid 89); 22 Jun 2018 09:13:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=HX-Received:sk:v7-v6mr, Hx-languages-length:1136 X-HELO: mail-lf0-f41.google.com Received: from mail-lf0-f41.google.com (HELO mail-lf0-f41.google.com) (209.85.215.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 22 Jun 2018 09:13:38 +0000 Received: by mail-lf0-f41.google.com with SMTP id j26-v6so191218lfb.11 for ; Fri, 22 Jun 2018 02:13:37 -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=Nj5TYtbWK4/2cUBwBfIndBZOQeyFBgEXEd5UuPhYoqc=; b=Mnf36afk9kggeHQe7TsT40qcd7vahm1iN79j1LxNaDxUzXClqC1O5FaRuNVK7HiVZ/ fBpLFDUsukFnAnKaxFmvB+NNONELbspNYwY6R8YDNYOPWOBu4D4rUzNYPmFdKzU997EO e10E0EQZvMWyqlDn0goMY4CyFQ28zYjAGDVPF/fzo5LklK+7vxnT5fdRu3BnMNEvx2lb 3cOOfV9oIHFI4GBbAiQyMYCr2p31hI/v6d99Ah+2+5XfHs/ZPMeAzN6wo3X9TmR5keWb UPF24r9VeDAuVSEUlWENAYP2RqacHbgXuk97YDFQMphqRhQ41k/ZP2NGczZ0iCn6iC3o vZZw== X-Gm-Message-State: APt69E20em92/wMfDDS7VwHwUKuSlZQddRGN2xx2sM7+P+EsCYd+IQxX N3u473MAJzWtZXx42ZiccMh+kV3ejjJaR2BZqr6Fkisr7T0= X-Received: by 2002:a2e:5047:: with SMTP id v7-v6mr697470ljd.122.1529658815889; Fri, 22 Jun 2018 02:13:35 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a2e:1302:0:0:0:0:0 with HTTP; Fri, 22 Jun 2018 02:12:55 -0700 (PDT) From: Kugan Vivekanandarajah Date: Fri, 22 Jun 2018 19:12:55 +1000 Message-ID: Subject: [PATCH 1/3][POPCOUNT] Handle COND_EXPR in expression_expensive_p To: GCC Patches X-IsSubscribed: yes [PATCH 1/3][POPCOUNT] Handle COND_EXPR in expression_expensive_p gcc/ChangeLog: 2018-06-22 Kugan Vivekanandarajah * tree-scalar-evolution.c (expression_expensive_p): Handle COND_EXPR. >From aa38b98dd97567c6032c261f19b3705abc2233b0 Mon Sep 17 00:00:00 2001 From: Kugan Vivekanandarajah Date: Fri, 22 Jun 2018 14:10:26 +1000 Subject: [PATCH 1/3] generate popcount when checked for zero Change-Id: I7255bf35e28222f7418852cb232246edf1fb5a39 --- gcc/tree-scalar-evolution.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gcc/tree-scalar-evolution.c b/gcc/tree-scalar-evolution.c index 4b0ec02..db419a4 100644 --- a/gcc/tree-scalar-evolution.c +++ b/gcc/tree-scalar-evolution.c @@ -3508,6 +3508,11 @@ expression_expensive_p (tree expr) return false; } + if (code == COND_EXPR) + return (expression_expensive_p (TREE_OPERAND (expr, 0)) + || expression_expensive_p (TREE_OPERAND (expr, 1)) + || expression_expensive_p (TREE_OPERAND (expr, 2))); + switch (TREE_CODE_CLASS (code)) { case tcc_binary: -- 2.7.4 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 From patchwork Fri Jun 22 09:14:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 139592 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp637001lji; Fri, 22 Jun 2018 02:16:49 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIErI6iwym1K48BuR/1gYaWOYbxshYUPTuT6IW05D30Z7TWcZwQghPSrdm0s/QY/s/ad8NF X-Received: by 2002:a17:902:64cf:: with SMTP id y15-v6mr833649pli.53.1529659009445; Fri, 22 Jun 2018 02:16:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529659009; cv=none; d=google.com; s=arc-20160816; b=kUc7+w/6Qwp+TQQN7oJR/w/h21Z+YZUgOlhp7NqGCgEKiXtII2cshtgRq47JR5493g SykhzD4EZy+buWfFNg9zrXcKQrgQE/3I+NWVplNll18IICP7s3e9BXcqZbuqqxWYt0ON yLgF+kCSJVxr12fBeVfIr+liW+gVPI9KUfb/l7F2Z5PrDU1FzWQAvurjQ21Qm2IQg64i Xdcqmc41oDgW27FtBu+6p/XpLn8Ht6cockydUZB/UT5T+t8WtLZweUw6Fsv7ydPgb7I4 C5Wq6CC43+0qtA70vg7CUe1mb3h/Af4cWpvhvttAsw63HPna2aJKXH3OwGlDWD8dRiJA YUBA== 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=VYVlq4l5t9L5O+AbE3cXSC0cZWhK9SGNz1s8CVTmIPM=; b=nzmzJb1Gj4Le4e5X8ntAtkUzZBqZ/r8Z7GJd7EgDR8NleNOSi6yeiJ72N1dy5XH+Hn 2kSS6W/+wXw7sG4ETCXuSvgBx33brKv7zbsGbIWctTMqwkBKyVQSTShVDWH0re3KRHtE ErL/gm6YGg0S63PrF1N6wDgFl3hb75cXfjJk7rlPu+37BKGPwIB38NyKm0vJN1cxcj6e jdU2PWh/ssixm5BV4k6gnmxEFT9ZuEyuef3hXNcwlMnb+XV0OQyKQprUN3JJhhaMFjKa YkZX8d4IpHcRwKVXszk+jgdr8zbcPOEAOC5cexnaOw4Ul8JkzCjRL+RXI3KirLNBoFqm P0Dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="q/pUtJuk"; spf=pass (google.com: domain of gcc-patches-return-480264-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gcc-patches-return-480264-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 z3-v6si6886003plb.246.2018.06.22.02.16.49 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Jun 2018 02:16:49 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-480264-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="q/pUtJuk"; spf=pass (google.com: domain of gcc-patches-return-480264-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gcc-patches-return-480264-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=KH4FbD2j8AfiMfWe3dBgrtNgR7UctnuAZJDpCoprDl0M1R 1xZzmoM55+jrlvr8cdt8IY4ocVLNi7sLsnzEwHQACxtIirxLUfMHjUxRN033Huz9 zlHS6Rom0z9EiqUQDaqTy5qWo9oLb0i1cdt7pC8sy79feSeSW+RsCOpGSAXsU= 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=uXsGDzSjpg8LtyRfSwu0xcc0IpI=; b=q/pUtJuk9bWLT9Nax500 mGu52makljVGRySF6jXd2H2Vb/4aQvy2gxTVdUcjNEXcyf6ckIkmSIded/FZHRUz mB3Wl2kHjzzuwPeoZ8LiOPrrL9qJWMNtyYZGfsRcP808tBPd2NrbytDlAtHF+FUu D4P0nKj9PhPvgYlzV1yNsxU= Received: (qmail 41451 invoked by alias); 22 Jun 2018 09:16:36 -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 40997 invoked by uid 89); 22 Jun 2018 09:15:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=fndecl, gimple_get_lhs X-HELO: mail-lf0-f48.google.com Received: from mail-lf0-f48.google.com (HELO mail-lf0-f48.google.com) (209.85.215.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 22 Jun 2018 09:15:37 +0000 Received: by mail-lf0-f48.google.com with SMTP id j26-v6so197890lfb.11 for ; Fri, 22 Jun 2018 02:15:27 -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=ILW7lrmXaPhVg2Tz3VOPSaa4LYBGffXQFZN2pXntKM8=; b=e9vTRYXv74hdplWestS5kOdJcd0buJeNYx9Dt5P3mCuwnm3rmA4WAl8CduBKalULrD JGX4ZSRq1F5tGEtDajd98nT0RZKm+wlK9SV9vtE30XvKcOUIJxA2jnDmJLKjWxz9o62o +n7JtZsAcVgxw+BvyGODNTzUTKt7yOkdrp2nqnqVFgrwGQmDZYUR28fOq+kL+rqx82Bc bMMvfb4XZ8/I99AjUzHXbycB9/L25LAzbyJMsjWYf2TjQVEidXcL2Vlxxj0mGpkPPent qEYY1w3V93Cvg5BAmzqimG0B3c0oDZXmxzYsPHHI9a7NaBrpxjgsSneWOsMC8c24YCNO 6izw== X-Gm-Message-State: APt69E01CDPlw/TaCtlPZJPXdSj8vOKFde0gFLwTUXsgR1usoNEUyFHy hKkveptf5RWSde4Bvbbcf+HEmcV+yQNJlf/xRYPRhviVTIk= X-Received: by 2002:a19:8fd4:: with SMTP id s81-v6mr197662lfk.118.1529658925366; Fri, 22 Jun 2018 02:15:25 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a2e:1302:0:0:0:0:0 with HTTP; Fri, 22 Jun 2018 02:14:44 -0700 (PDT) From: Kugan Vivekanandarajah Date: Fri, 22 Jun 2018 19:14:44 +1000 Message-ID: Subject: [PATCH 3/3][POPCOUNT] Remove unnecessary if condition in phiopt To: GCC Patches X-IsSubscribed: yes gcc/ChangeLog: 2018-06-22 Kugan Vivekanandarajah * tree-ssa-phiopt.c (cond_removal_in_popcount_pattern): New. (tree_ssa_phiopt_worker): Call cond_removal_in_popcount_pattern. gcc/testsuite/ChangeLog: 2018-06-22 Kugan Vivekanandarajah * gcc.dg/tree-ssa/popcount3.c: New test. >From fa2cca6b186b70668a3334c23ea4b906dac454d4 Mon Sep 17 00:00:00 2001 From: Kugan Vivekanandarajah Date: Fri, 22 Jun 2018 14:16:21 +1000 Subject: [PATCH 3/3] improve phiopt for builtin popcount Change-Id: Id1a5997c78fc3ceded3ed7fb0c544ce2bd1a2b34 --- gcc/testsuite/gcc.dg/tree-ssa/popcount3.c | 15 ++++ gcc/tree-ssa-phiopt.c | 113 ++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/popcount3.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/popcount3.c b/gcc/testsuite/gcc.dg/tree-ssa/popcount3.c new file mode 100644 index 0000000..293beb9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/popcount3.c @@ -0,0 +1,15 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fdump-tree-phiopt3 -fdump-tree-optimized" } */ + +int PopCount (long b) { + int c = 0; + + while (b) { + b &= b - 1; + c++; + } + return c; +} + +/* { dg-final { scan-tree-dump-times "__builtin_popcount" 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "if" 0 "phiopt3" } } */ diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c index 8e94f6a..1db5226 100644 --- a/gcc/tree-ssa-phiopt.c +++ b/gcc/tree-ssa-phiopt.c @@ -57,6 +57,8 @@ static bool minmax_replacement (basic_block, basic_block, edge, edge, gimple *, tree, tree); static bool abs_replacement (basic_block, basic_block, edge, edge, gimple *, tree, tree); +static bool cond_removal_in_popcount_pattern (basic_block, basic_block, + edge, edge, gimple *, tree, tree); static bool cond_store_replacement (basic_block, basic_block, edge, edge, hash_set *); static bool cond_if_else_store_replacement (basic_block, basic_block, basic_block); @@ -332,6 +334,9 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads) cfgchanged = true; else if (abs_replacement (bb, bb1, e1, e2, phi, arg0, arg1)) cfgchanged = true; + else if (cond_removal_in_popcount_pattern (bb, bb1, e1, e2, + phi, arg0, arg1)) + cfgchanged = true; else if (minmax_replacement (bb, bb1, e1, e2, phi, arg0, arg1)) cfgchanged = true; } @@ -1516,6 +1521,114 @@ minmax_replacement (basic_block cond_bb, basic_block middle_bb, return true; } +/* Convert + + + if (b_4(D) != 0) + goto + else + goto + + + _2 = (unsigned long) b_4(D); + _9 = __builtin_popcountl (_2); + + + c_12 = PHI <0(2), _9(3)> + + Into + + _2 = (unsigned long) b_4(D); + _9 = __builtin_popcountl (_2); + + + c_12 = PHI <_9(2)> +*/ + +static bool +cond_removal_in_popcount_pattern (basic_block cond_bb, basic_block middle_bb, + edge e0 ATTRIBUTE_UNUSED, edge e1 ATTRIBUTE_UNUSED, + gimple *phi, tree arg0, tree arg1) +{ + gimple *cond; + gimple_stmt_iterator gsi; + gimple *popcount; + gimple *cast; + tree rhs, lhs, arg; + unsigned stmt_count = 0; + + /* Check that + _2 = (unsigned long) b_4(D); + _9 = __builtin_popcountl (_2); + are the only stmts in the middle_bb. */ + + for (gsi = gsi_start_bb (middle_bb); !gsi_end_p (gsi); gsi_next (&gsi)) + { + gimple *stmt = gsi_stmt (gsi); + if (is_gimple_debug (stmt)) + continue; + stmt_count++; + } + if (stmt_count != 2) + return false; + + cast = first_stmt (middle_bb); + popcount = last_stmt (middle_bb); + if (popcount == NULL || cast == NULL) + return false; + + /* Check that we have a popcount builtin. */ + if (!is_gimple_call (popcount) + || !gimple_call_builtin_p (popcount, BUILT_IN_NORMAL)) + return false; + tree fndecl = gimple_call_fndecl (popcount); + if ((DECL_FUNCTION_CODE (fndecl) != BUILT_IN_POPCOUNT) + && (DECL_FUNCTION_CODE (fndecl) != BUILT_IN_POPCOUNTL) + && (DECL_FUNCTION_CODE (fndecl) != BUILT_IN_POPCOUNTLL)) + return false; + + /* Check that we have a cast prior to that. */ + if (gimple_code (cast) != GIMPLE_ASSIGN + || gimple_assign_rhs_code (cast) != NOP_EXPR) + return false; + + rhs = gimple_assign_rhs1 (cast); + lhs = gimple_get_lhs (popcount); + arg = gimple_call_arg (popcount, 0); + + /* Result of the cast stmt is the argument to the builtin. */ + if (arg != gimple_assign_lhs (cast)) + return false; + + if (lhs != arg0 + && lhs != arg1) + return false; + + cond = last_stmt (cond_bb); + + /* Cond_bb has a check for b_4 != 0 before calling the popcount + builtin. */ + if (gimple_code (cond) != GIMPLE_COND + || gimple_cond_code (cond) != NE_EXPR + || TREE_CODE (gimple_cond_lhs (cond)) != SSA_NAME + || rhs != gimple_cond_lhs (cond)) + return false; + + /* Remove the popcount builtin and cast stmt. */ + gsi = gsi_for_stmt (popcount); + gsi_remove (&gsi, true); + gsi = gsi_for_stmt (cast); + gsi_remove (&gsi, true); + + /* And insert the popcount builtin and cast stmt before the cond_bb. */ + gsi = gsi_last_bb (cond_bb); + gsi_insert_before (&gsi, popcount, GSI_NEW_STMT); + gsi_insert_before (&gsi, cast, GSI_NEW_STMT); + + /* Now update the PHI and remove unneeded bbs. */ + replace_phi_edge_with_variable (cond_bb, e1, phi, lhs); + return true; +} /* The function absolute_replacement does the main work of doing the absolute replacement. Return true if the replacement is done. Otherwise return -- 2.7.4