From patchwork Thu May 4 06:47:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 98512 Delivered-To: patch@linaro.org Received: by 10.140.89.200 with SMTP id v66csp431827qgd; Wed, 3 May 2017 23:48:09 -0700 (PDT) X-Received: by 10.98.147.26 with SMTP id b26mr8913493pfe.65.1493880489349; Wed, 03 May 2017 23:48:09 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id x84si1305395pfi.125.2017.05.03.23.48.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 May 2017 23:48:09 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-452742-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-452742-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-452742-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:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=HlXc+4bbMoGqMVKjikMb/UJ5lOJtPzoGdr/ujS86Lu23HYLQOh0FZ CAvHRzSsg5HmqJ8i4G90n6uNXBJuwlvd6prG67f3CUUts168hqENROuqI4R8ML1U KlVkWC2xy1axjINhb6n2eEm3fjvYj6JNJ0i2yZYJs6DUmXlHzFlzl8= 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 :to:subject:date:message-id:mime-version:content-type; s= default; bh=oQk/G4YAM47kZgLcHAytCH5ytd4=; b=AU1NeZAr55cVtUbiuhV9 t0QmCwEDkKB/292s44vCw8qH+hZKDFPx3PY+C9zpxBrRac0aAXN6OpBHu+GLAAdN 6mSzbe6+sUFUgqifAnjp9XIJw551qsCa+r73NLht3D2kvVe4x+IVSzgWJmdPDH10 Bwlo5hLvj9Cf1pqVGthTnVM= Received: (qmail 21338 invoked by alias); 4 May 2017 06:47:53 -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 19204 invoked by uid 89); 4 May 2017 06:47:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=explained X-HELO: mail-wm0-f43.google.com Received: from mail-wm0-f43.google.com (HELO mail-wm0-f43.google.com) (74.125.82.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 04 May 2017 06:47:50 +0000 Received: by mail-wm0-f43.google.com with SMTP id 142so698627wma.1 for ; Wed, 03 May 2017 23:47:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:user-agent:date :message-id:mime-version; bh=KJpMBaSQrAGEj9GSqej2IoAZUKYr2eld/mm7jMW727E=; b=KU94UT1FylJ/QSetsMCrJngHCirAa16fJMgCNMl/4HPUmc3nvrh51LlG3YbPYojxQz yJ3QR7xrHQeR1SYfHpFMADaLXA844fs/nmhdzusGqyJUt1XsNRKXmHk18O/WYLSYv9+m r8YFa7OWEBGPwgaQDuUJ8avQO3XKtzzw3kG5M/8gtgNMTYe9lJlulm5bg7dwjw3Qcxwl ghpJpgLXoW0IYEivziB/G6d+wOQhsN4nZSK6hIKqHV4BWBLNXy/vZX5U+n7pCCN573sl JUanaNuIQw95nmO+aVHQ2o2iHA2rg0tI63Nb292oFhHRKNa/3hwTh+JVj2xk/ssFRk/K 4JMw== X-Gm-Message-State: AN3rC/4qzg1ly39UOf2hko36UEZN1mv+wlvX8v7rNhlseyfFVE2PSiOL 6pOWrQ0IdDD/6JgW8nw0aG+j X-Received: by 10.28.142.4 with SMTP id q4mr411385wmd.112.1493880470823; Wed, 03 May 2017 23:47:50 -0700 (PDT) Received: from localhost (92.40.249.24.threembb.co.uk. [92.40.249.24]) by smtp.gmail.com with ESMTPSA id y16sm2218526wry.46.2017.05.03.23.47.49 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 03 May 2017 23:47:50 -0700 (PDT) From: Richard Sandiford X-Google-Original-From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Cap niter_for_unrolled_loop to upper bound User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Date: Thu, 04 May 2017 07:47:48 +0100 Message-ID: <87k25x3yp7.fsf@linaro.org> MIME-Version: 1.0 For the reasons explained in PR77536, niter_for_unrolled_loop assumes 5 iterations in the absence of profiling information, although it doesn't increase beyond the estimate for the original loop. This left a hole in which the new estimate could be less than the old one but still greater than the limit imposed by CEIL (nb_iterations_upper_bound, unroll factor). Tested on aarch64-linux-gnu and x86_64-linux-gnu. OK to install? Thanks, Richard gcc/ 2017-05-04 Richard Sandiford * tree-ssa-loop-manip.c (niter_for_unrolled_loop): Add commentary to explain the use of truncating division. Cap the number of iterations to the maximum given by nb_iterations_upper_bound, if defined. gcc/testsuite/ * gcc.dg/vect/vect-profile-1.c: New test. Index: gcc/tree-ssa-loop-manip.c =================================================================== --- gcc/tree-ssa-loop-manip.c 2017-05-03 08:46:26.068861808 +0100 +++ gcc/tree-ssa-loop-manip.c 2017-05-04 07:41:56.686034705 +0100 @@ -1104,6 +1104,9 @@ niter_for_unrolled_loop (struct loop *lo gcc_assert (factor != 0); bool profile_p = false; gcov_type est_niter = expected_loop_iterations_unbounded (loop, &profile_p); + /* Note that this is really CEIL (est_niter + 1, factor) - 1, where the + "+ 1" converts latch iterations to loop iterations and the "- 1" + converts back. */ gcov_type new_est_niter = est_niter / factor; /* Without profile feedback, loops for which we do not know a better estimate @@ -1120,6 +1123,15 @@ niter_for_unrolled_loop (struct loop *lo new_est_niter = 5; } + if (loop->any_upper_bound) + { + /* As above, this is really CEIL (upper_bound + 1, factor) - 1. */ + widest_int bound = wi::udiv_floor (loop->nb_iterations_upper_bound, + factor); + if (wi::ltu_p (bound, new_est_niter)) + new_est_niter = bound.to_uhwi (); + } + return new_est_niter; } Index: gcc/testsuite/gcc.dg/vect/vect-profile-1.c =================================================================== --- /dev/null 2017-05-04 07:24:39.449302696 +0100 +++ gcc/testsuite/gcc.dg/vect/vect-profile-1.c 2017-05-04 07:41:56.685075916 +0100 @@ -0,0 +1,35 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target vect_int } */ +/* { dg-additional-options "-fdump-tree-vect-details-blocks" } */ + +/* At least one of these should correspond to a full vector. */ + +void +f1 (int *x) +{ + for (int j = 0; j < 2; ++j) + x[j] += 1; +} + +void +f2 (int *x) +{ + for (int j = 0; j < 4; ++j) + x[j] += 1; +} + +void +f3 (int *x) +{ + for (int j = 0; j < 8; ++j) + x[j] += 1; +} + +void +f4 (int *x) +{ + for (int j = 0; j < 16; ++j) + x[j] += 1; +} + +/* { dg-final { scan-tree-dump {goto ; \[0+.0*%\]} vect } } */