From patchwork Tue Jan 27 10:47:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Enkovich X-Patchwork-Id: 433303 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3E583140172 for ; Tue, 27 Jan 2015 21:48:36 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:references:mime-version:content-type :in-reply-to; q=dns; s=default; b=kOQPfZYjy5yYTy0R4JSVBZ96skfsvk qP60YMee3IK8nsYY6LwYjB5gFucOMmqsRU3noLY2f8p8e+djLchkfw6IrBMIj5jL BpHKfxxN3cCHprCm7XGhaFgzT8qpVg/LteHMREmU+utfkdqORBehqs17l4UNFN7n VJSGF9rpu6Qp4= 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:date :from:to:subject:message-id:references:mime-version:content-type :in-reply-to; s=default; bh=byYmz5TrJefKQT9cJii1Od4GzSc=; b=u1+u QB4r6QZQyZvBR4XI7bYliRfhuybPsTyE6szd0VtOaPidqiNwypkOOxJyrIym++dQ Fg3hPMtGg1AgeTlINuG98ZNZw8jRBRO2PY6Q/Dn/dDC2uirC9UHHJi1pTp1CiFGG BaSpjgzO6E1Xli+Fco98+o9oSKLI9Q/I/Hfe2kg= Received: (qmail 7455 invoked by alias); 27 Jan 2015 10:48:08 -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 7194 invoked by uid 89); 27 Jan 2015 10:47:46 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.0 required=5.0 tests=AWL, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-qa0-f51.google.com Received: from mail-qa0-f51.google.com (HELO mail-qa0-f51.google.com) (209.85.216.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 27 Jan 2015 10:47:44 +0000 Received: by mail-qa0-f51.google.com with SMTP id f12so10765041qad.10 for ; Tue, 27 Jan 2015 02:47:41 -0800 (PST) X-Received: by 10.224.79.144 with SMTP id p16mr843433qak.84.1422355661137; Tue, 27 Jan 2015 02:47:41 -0800 (PST) Received: from msticlxl57.ims.intel.com (fmdmzpr03-ext.fm.intel.com. [192.55.54.38]) by mx.google.com with ESMTPSA id q4sm760780qad.3.2015.01.27.02.47.38 for (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Jan 2015 02:47:40 -0800 (PST) Date: Tue, 27 Jan 2015 13:47:29 +0300 From: Ilya Enkovich To: gcc-patches@gcc.gnu.org Subject: Re: [PATCH, PR tree-optimization/64277] Improve loop iterations count estimation Message-ID: <20150127104729.GC47190@msticlxl57.ims.intel.com> References: <20150127094046.GB47190@msticlxl57.ims.intel.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20150127094046.GB47190@msticlxl57.ims.intel.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes On 27 Jan 12:40, Ilya Enkovich wrote: > Hi, > > This patch was supposed to fix PR tree-optimization/64277. Tracker is now fixed by warnings disabling but I think patch is still useful to avoid dead code generated by complete unroll. > > Bootstrapped and tested on x86_64-unknown-linux-gnu. > > Thanks, > Ilya > -- > gcc/ > > 2015-01-27 Ilya Enkovich > > * tree-ssa-loop-niter.c (record_nonwrapping_iv): Use base > range info when possible to refine estimation. > > gcc/testsuite/ > > 2015-01-27 Ilya Enkovich > > * gcc.dg/pr64277.c: New. > > Here is a new version fixed according to comments in the tracker. I also fixed a test to scan cunroll dumps. Does it look OK? What are possible branches for this patch? Thanks, Ilya diff --git a/gcc/testsuite/gcc.dg/pr64277.c b/gcc/testsuite/gcc.dg/pr64277.c new file mode 100644 index 0000000..c6ef331 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr64277.c @@ -0,0 +1,23 @@ +/* PR tree-optimization/64277 */ +/* { dg-do compile } */ +/* { dg-options "-O3 -Wall -Werror -fdump-tree-cunroll-details" } */ +/* { dg-final { scan-tree-dump "loop with 5 iterations completely unrolled" "cunroll" } } */ +/* { dg-final { scan-tree-dump "loop with 6 iterations completely unrolled" "cunroll" } } */ +/* { dg-final { cleanup-tree-dump "cunroll" } } */ + +int f1[10]; +void test1 (short a[], short m, unsigned short l) +{ + int i = l; + for (i = i + 5; i < m; i++) + f1[i] = a[i]++; +} + +void test2 (short a[], short m, short l) +{ + int i; + if (m > 5) + m = 5; + for (i = m; i > l; i--) + f1[i] = a[i]++; +} diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c index 919f5c0..1cd297d 100644 --- a/gcc/tree-ssa-loop-niter.c +++ b/gcc/tree-ssa-loop-niter.c @@ -2754,6 +2754,7 @@ record_nonwrapping_iv (struct loop *loop, tree base, tree step, gimple stmt, { tree niter_bound, extreme, delta; tree type = TREE_TYPE (base), unsigned_type; + tree orig_base = base; if (TREE_CODE (step) != INTEGER_CST || integer_zerop (step)) return; @@ -2777,16 +2778,30 @@ record_nonwrapping_iv (struct loop *loop, tree base, tree step, gimple stmt, if (tree_int_cst_sign_bit (step)) { + wide_int min, max; extreme = fold_convert (unsigned_type, low); - if (TREE_CODE (base) != INTEGER_CST) + if (TREE_CODE (orig_base) == SSA_NAME + && TREE_CODE (high) == INTEGER_CST + && INTEGRAL_TYPE_P (TREE_TYPE (orig_base)) + && get_range_info (orig_base, &min, &max) == VR_RANGE + && wi::gts_p (wide_int (high), max)) + base = wide_int_to_tree (unsigned_type, max); + else if (TREE_CODE (base) != INTEGER_CST) base = fold_convert (unsigned_type, high); delta = fold_build2 (MINUS_EXPR, unsigned_type, base, extreme); step = fold_build1 (NEGATE_EXPR, unsigned_type, step); } else { + wide_int min, max; extreme = fold_convert (unsigned_type, high); - if (TREE_CODE (base) != INTEGER_CST) + if (TREE_CODE (orig_base) == SSA_NAME + && TREE_CODE (low) == INTEGER_CST + && INTEGRAL_TYPE_P (TREE_TYPE (orig_base)) + && get_range_info (orig_base, &min, &max) == VR_RANGE + && wi::gts_p (min, wide_int (low))) + base = wide_int_to_tree (unsigned_type, min); + else if (TREE_CODE (base) != INTEGER_CST) base = fold_convert (unsigned_type, low); delta = fold_build2 (MINUS_EXPR, unsigned_type, extreme, base); }