From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 60652 invoked by alias); 30 Mar 2016 12:27:58 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 60623 invoked by uid 89); 30 Mar 2016 12:27:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.7 required=5.0 tests=AWL,BAYES_00,KAM_ASCII_DIVIDERS,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy= X-HELO: nikam.ms.mff.cuni.cz Received: from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 30 Mar 2016 12:27:55 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 9D6CD545D07; Wed, 30 Mar 2016 14:27:51 +0200 (CEST) Date: Wed, 30 Mar 2016 12:36:00 -0000 From: Jan Hubicka To: Richard Biener Cc: Jan Hubicka , gcc-patches@gcc.gnu.org Subject: Re: Do not give realistic estimates for loop with array accesses Message-ID: <20160330122751.GA97459@kam.mff.cuni.cz> References: <20160330100018.GA54780@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-SW-Source: 2016-03/txt/msg01588.txt.bz2 > > You are only changing one place in this file. You are right. I am attaching the updated patch which I am re-testing now. > > The vectorizer already checks this (albeit indirectly): > > HOST_WIDE_INT max_niter > = max_stmt_executions_int (LOOP_VINFO_LOOP (loop_vinfo)); > if ((LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo) > && (LOOP_VINFO_INT_NITERS (loop_vinfo) < vectorization_factor)) > || (max_niter != -1 > && (unsigned HOST_WIDE_INT) max_niter < vectorization_factor)) > { > if (dump_enabled_p ()) > dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, > "not vectorized: iteration count smaller than " > "vectorization factor.\n"); > return false; > } Yes, but one tests only vectorization_factor and other min_profitable_estimate which probably should be greater than vectorization_factor. The check above should therefore become redundant. My reading of the code is that min_profiltable_estimate is computed after the check above, so it is probably an useful shortcut and the message is also bit more informative. I updated the later test to use max_niter variable once it is computed. OK with those changes assuming testing passes? Honza * tree-ssa-loop-niter.c (idx_infer_loop_bounds): We can't get realistic estimates here. * tree-ssa-loop-unswitch.c (tree_unswitch_single_loop): Use also max_loop_iterations_int. (tree_unswitch_outer_loop): Likewise. * tree-ssa-loop-ivopts.c (avg_loop_niter): Likewise. * tree-vect-loop.c (vect_analyze_loop_2): Likewise. Index: tree-ssa-loop-ivopts.c =================================================================== --- tree-ssa-loop-ivopts.c (revision 234516) +++ tree-ssa-loop-ivopts.c (working copy) @@ -121,7 +121,11 @@ avg_loop_niter (struct loop *loop) { HOST_WIDE_INT niter = estimated_stmt_executions_int (loop); if (niter == -1) - return AVG_LOOP_NITER (loop); + { + niter = max_stmt_executions_int (loop); + if (niter == -1 || niter > AVG_LOOP_NITER (loop)) + return AVG_LOOP_NITER (loop); + } return niter; } Index: tree-ssa-loop-niter.c =================================================================== --- tree-ssa-loop-niter.c (revision 234516) +++ tree-ssa-loop-niter.c (working copy) @@ -3115,7 +3115,6 @@ idx_infer_loop_bounds (tree base, tree * tree low, high, type, next; bool sign, upper = true, at_end = false; struct loop *loop = data->loop; - bool reliable = true; if (TREE_CODE (base) != ARRAY_REF) return true; @@ -3187,14 +3186,14 @@ idx_infer_loop_bounds (tree base, tree * && tree_int_cst_compare (next, high) <= 0) return true; - /* If access is not executed on every iteration, we must ensure that overlow may - not make the access valid later. */ + /* If access is not executed on every iteration, we must ensure that overlow + may not make the access valid later. */ if (!dominated_by_p (CDI_DOMINATORS, loop->latch, gimple_bb (data->stmt)) && scev_probably_wraps_p (initial_condition_in_loop_num (ev, loop->num), step, data->stmt, loop, true)) - reliable = false; + upper = false; - record_nonwrapping_iv (loop, init, step, data->stmt, low, high, reliable, upper); + record_nonwrapping_iv (loop, init, step, data->stmt, low, high, false, upper); return true; } Index: tree-ssa-loop-unswitch.c =================================================================== --- tree-ssa-loop-unswitch.c (revision 234516) +++ tree-ssa-loop-unswitch.c (working copy) @@ -223,6 +223,8 @@ tree_unswitch_single_loop (struct loop * /* If the loop is not expected to iterate, there is no need for unswitching. */ iterations = estimated_loop_iterations_int (loop); + if (iterations < 0) + iterations = max_loop_iterations_int (loop); if (iterations >= 0 && iterations <= 1) { if (dump_file && (dump_flags & TDF_DETAILS)) @@ -439,6 +441,8 @@ tree_unswitch_outer_loop (struct loop *l /* If the loop is not expected to iterate, there is no need for unswitching. */ iterations = estimated_loop_iterations_int (loop); + if (iterations < 0) + iterations = max_loop_iterations_int (loop); if (iterations >= 0 && iterations <= 1) { if (dump_file && (dump_flags & TDF_DETAILS)) Index: tree-vect-loop.c =================================================================== --- tree-vect-loop.c (revision 234516) +++ tree-vect-loop.c (working copy) @@ -2063,6 +2063,8 @@ start_over: estimated_niter = estimated_stmt_executions_int (LOOP_VINFO_LOOP (loop_vinfo)); + if (estimated_niter != -1) + estimated_niter = max_niter; if (estimated_niter != -1 && ((unsigned HOST_WIDE_INT) estimated_niter <= MAX (th, (unsigned)min_profitable_estimate)))