From patchwork Wed Nov 9 22:13:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pat Haugen X-Patchwork-Id: 81575 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp430260qge; Wed, 9 Nov 2016 14:14:08 -0800 (PST) X-Received: by 10.99.127.72 with SMTP id p8mr30267821pgn.183.1478729647793; Wed, 09 Nov 2016 14:14:07 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id x5si1364861pgj.136.2016.11.09.14.14.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Nov 2016 14:14:07 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-440907-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; spf=pass (google.com: domain of gcc-patches-return-440907-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-440907-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:cc:date:mime-version:content-type:message-id; q=dns; s=default; b=glmIYnKOCegau3Bvbip20wqdGDYDiQTYn1CTMZtD2SK09CWyAl wzUBpu1dd0GRbG1OqMzAj1S3z+AbxjLzrP9Gk/IjU8MqL46tVVg+jQLkmm8UumO1 L6I4oHSk+zd+JUhQ8Qg0RiHbuKACuZQ1611dWoQxDQNz0gKCsdfkBIRjY= 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:from :subject:to:cc:date:mime-version:content-type:message-id; s= default; bh=9V1hhUP9v0I7PHLNJAUI9qsDOAw=; b=kkNU6XGjqjbpF7I5dVM8 eGaDWaIEVGrIHo9+QGe95gw1GIN64aE53gkUpAPzGgNakFxhvQv0IZWeCV4pBm7f FUkZpEfV9EmZIhA6mQL1CX+GSVJ7MwS2tNv3mmac620/NsQ/NZA2H59m35Br5Xvu StK5oXXxUal9sAg+YskF5GY= Received: (qmail 122629 invoked by alias); 9 Nov 2016 22:13:52 -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 122615 invoked by uid 89); 9 Nov 2016 22:13:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.4 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW, RCVD_IN_SEMBACKSCATTER autolearn=no version=3.3.2 spammy=loopunrollc, loop-unroll.c, UD:loop-unroll.c, Hx-languages-length:2238 X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 09 Nov 2016 22:13:41 +0000 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uA9MDPF0085462 for ; Wed, 9 Nov 2016 17:13:39 -0500 Received: from e17.ny.us.ibm.com (e17.ny.us.ibm.com [129.33.205.207]) by mx0a-001b2d01.pphosted.com with ESMTP id 26m6j7f61b-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 09 Nov 2016 17:13:39 -0500 Received: from localhost by e17.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 9 Nov 2016 17:13:38 -0500 Received: from d01dlp01.pok.ibm.com (9.56.250.166) by e17.ny.us.ibm.com (146.89.104.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 9 Nov 2016 17:13:36 -0500 Received: from b01cxnp22034.gho.pok.ibm.com (b01cxnp22034.gho.pok.ibm.com [9.57.198.24]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id E314338C8039; Wed, 9 Nov 2016 17:13:35 -0500 (EST) Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id uA9MDT1X32636990; Wed, 9 Nov 2016 22:13:36 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 161D5AE04B; Wed, 9 Nov 2016 17:13:36 -0500 (EST) Received: from oc1687012634.ibm.com (unknown [9.10.86.142]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP id E986DAE034; Wed, 9 Nov 2016 17:13:35 -0500 (EST) From: Pat Haugen Subject: [PATCH] PR78241, fix loop unroller when niter expr is not reliable To: GCC Patches Cc: Jeff Law Date: Wed, 9 Nov 2016 16:13:35 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16110922-0040-0000-0000-000001D29FA3 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006049; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000189; SDB=6.00778788; UDB=6.00375137; IPR=6.00556148; BA=6.00004866; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00013277; XFM=3.00000011; UTC=2016-11-09 22:13:38 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16110922-0041-0000-0000-000005C5A18A Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-11-09_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1611090406 X-IsSubscribed: yes The following fixes a problem introduced by my earlier loop unroller patch, https://gcc.gnu.org/ml/gcc-patches/2016-09/msg01612.html. In instances where the niter expr is not reliable we need to still emit an initial peel copy of the loop. Bootstrap/regtest on powerpc64le with no new regressions. Ok for trunk? -Pat 2016-11-09 Pat Haugen PR rtl-optimization/78241 * loop-unroll.c (unroll_loop_runtime_iterations): Don't adjust 'niter', but emit initial peel copy if niter expr is not reliable. testsuite/ChangeLog: 2016-11-09 Pat Haugen * gcc.dg/pr78241.c: New test. Index: gcc/loop-unroll.c =================================================================== --- gcc/loop-unroll.c (revision 241821) +++ gcc/loop-unroll.c (working copy) @@ -918,9 +918,10 @@ unroll_loop_runtime_iterations (struct l if (tmp != niter) emit_move_insn (niter, tmp); - /* For loops that exit at end, add one to niter to account for first pass - through loop body before reaching exit test. */ - if (exit_at_end) + /* For loops that exit at end and whose number of iterations is reliable, + add one to niter to account for first pass through loop body before + reaching exit test. */ + if (exit_at_end && !desc->noloop_assumptions) { niter = expand_simple_binop (desc->mode, PLUS, niter, const1_rtx, @@ -946,7 +947,7 @@ unroll_loop_runtime_iterations (struct l auto_sbitmap wont_exit (max_unroll + 2); - if (extra_zero_check) + if (extra_zero_check || desc->noloop_assumptions) { /* Peel the first copy of loop body. Leave the exit test if the number of iterations is not reliable. Also record the place of the extra zero Index: gcc/testsuite/gcc.dg/pr78241.c =================================================================== --- gcc/testsuite/gcc.dg/pr78241.c (revision 0) +++ gcc/testsuite/gcc.dg/pr78241.c (working copy) @@ -0,0 +1,20 @@ +/* { dg-do run } */ +/* { dg-options "-Og -funroll-loops" } */ + +static __attribute__((noinline, noclone)) unsigned +foo (unsigned x) +{ + do + x++; + while (x <= 15); + return x; +} + +int main () +{ + unsigned x = foo (-2); + if (x != (unsigned)-1) + __builtin_abort(); + return 0; +} +