From patchwork Wed Jun 9 22:08:57 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fang, Changpeng" X-Patchwork-Id: 55129 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]) by ozlabs.org (Postfix) with SMTP id BC87EB6ED0 for ; Thu, 10 Jun 2010 08:12:07 +1000 (EST) Received: (qmail 16537 invoked by alias); 9 Jun 2010 22:12:05 -0000 Received: (qmail 16528 invoked by uid 22791); 9 Jun 2010 22:12:04 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from outbound-va3.frontbridge.com (HELO VA3EHSOBE009.bigfish.com) (216.32.180.16) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 09 Jun 2010 22:11:58 +0000 Received: from mail120-va3-R.bigfish.com (10.7.14.240) by VA3EHSOBE009.bigfish.com (10.7.40.29) with Microsoft SMTP Server id 8.1.340.0; Wed, 9 Jun 2010 22:11:56 +0000 Received: from mail120-va3 (localhost.localdomain [127.0.0.1]) by mail120-va3-R.bigfish.com (Postfix) with ESMTP id 165D5E8276; Wed, 9 Jun 2010 22:11:56 +0000 (UTC) X-SpamScore: -7 X-BigFish: VPS-7(zz1432Pzz1202hzzz32i2a8h34h43h61h) X-Spam-TCS-SCL: 0:0 Received: from mail120-va3 (localhost.localdomain [127.0.0.1]) by mail120-va3 (MessageSwitch) id 1276121515590033_27458; Wed, 9 Jun 2010 22:11:55 +0000 (UTC) Received: from VA3EHSMHS030.bigfish.com (unknown [10.7.14.247]) by mail120-va3.bigfish.com (Postfix) with ESMTP id 837E2B3804E; Wed, 9 Jun 2010 22:11:55 +0000 (UTC) Received: from ausb3extmailp01.amd.com (163.181.251.8) by VA3EHSMHS030.bigfish.com (10.7.99.40) with Microsoft SMTP Server (TLS) id 14.0.482.44; Wed, 9 Jun 2010 22:11:55 +0000 Received: from ausb3twp01.amd.com ([163.181.250.37]) by ausb3extmailp01.amd.com (Switch-3.2.7/Switch-3.2.7) with SMTP id o59LsWE9016426; Wed, 9 Jun 2010 16:54:35 -0500 X-M-MSG: Received: from sausexhtp02.amd.com (sausexhtp02.amd.com [163.181.3.152]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by ausb3twp01.amd.com (Tumbleweed MailGate 3.7.2) with ESMTP id 2152C10286F8; Wed, 9 Jun 2010 17:11:47 -0500 (CDT) Received: from SAUSEXMBP01.amd.com ([163.181.3.198]) by sausexhtp02.amd.com ([163.181.3.152]) with mapi; Wed, 9 Jun 2010 17:11:49 -0500 From: "Fang, Changpeng" To: Zdenek Dvorak CC: "gcc-patches@gcc.gnu.org" , "sebpop@gmail.com" Date: Wed, 9 Jun 2010 17:08:57 -0500 Subject: RE: [patch, PR44297] prefetch improvements to fix 465.tonto from non-constant step prefetching Message-ID: References: <20100607231237.GL19235@codesourcery.com> , <20100609072319.GA15197@kam.mff.cuni.cz> In-Reply-To: <20100609072319.GA15197@kam.mff.cuni.cz> MIME-Version: 1.0 X-Reverse-DNS: unknown 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 Hi, >this construction is a bit confusing. It would be better to replace >prefetch_count = estimate_prefetch_count (refs, 1); > if (prefetch_count == 0) > goto fail; > >with > > if (nothing_to_prefetch_p (refs)) > goto fail; > >where nothing_to_prefetch_p would just test whether there is any reference with >should_issue_prefetch_p. Also, the prefetch_count = estimate_prefetch_count (refs, unroll_factor); >line should be placed before the preceding statement (that dumps the value of prefetch_count), Done as you suggested (see the attachment). Thanks. Changpeng From bf90074c6aac420955744b7f889fca2024c31876 Mon Sep 17 00:00:00 2001 From: Changpeng Fang Date: Mon, 7 Jun 2010 14:57:27 -0700 Subject: [PATCH 2/2] Account prefetch_mod and unroll_factor for the computation of the prefetch count *tree-ssa-loop-prefetch.c (nothing_to_prefetch_p): New. Return true if no prefetch is going to be generated for a given group. (estimate_prefetch_count): Use prefetch_mod and unroll_factor to estimate the prefetch_count. (loop_prefetch_arrays): Call nothing_to_prefetch_p; estimate the prefetch count by considering the unroll_factor and prefetch_mod for is_loop_prefetching_profitable. --- gcc/tree-ssa-loop-prefetch.c | 36 +++++++++++++++++++++++++++++++----- 1 files changed, 31 insertions(+), 5 deletions(-) diff --git a/gcc/tree-ssa-loop-prefetch.c b/gcc/tree-ssa-loop-prefetch.c index d63ede1..cde5e18 100644 --- a/gcc/tree-ssa-loop-prefetch.c +++ b/gcc/tree-ssa-loop-prefetch.c @@ -987,18 +987,39 @@ schedule_prefetches (struct mem_ref_group *groups, unsigned unroll_factor, return any; } -/* Estimate the number of prefetches in the given GROUPS. */ +/* Return TRUE if no prefetch is going to be generated + in the given GROUPS. */ +static bool +nothing_to_prefetch_p (struct mem_ref_group *groups) +{ + struct mem_ref *ref; + + for (; groups; groups = groups->next) + for (ref = groups->refs; ref; ref = ref->next) + if (should_issue_prefetch_p (ref)) + return false; + + return true; +} + +/* Estimate the number of prefetches in the given GROUPS. + UNROLL_FACTOR is the factor by which LOOP was unrolled. */ static int -estimate_prefetch_count (struct mem_ref_group *groups) +estimate_prefetch_count (struct mem_ref_group *groups, unsigned unroll_factor) { struct mem_ref *ref; + unsigned n_prefetches; int prefetch_count = 0; for (; groups; groups = groups->next) for (ref = groups->refs; ref; ref = ref->next) if (should_issue_prefetch_p (ref)) - prefetch_count++; + { + n_prefetches = ((unroll_factor + ref->prefetch_mod - 1) + / ref->prefetch_mod); + prefetch_count += n_prefetches; + } return prefetch_count; } @@ -1709,8 +1730,7 @@ loop_prefetch_arrays (struct loop *loop) /* Step 2: estimate the reuse effects. */ prune_by_reuse (refs); - prefetch_count = estimate_prefetch_count (refs); - if (prefetch_count == 0) + if (nothing_to_prefetch_p (refs)) goto fail; determine_loop_nest_reuse (loop, refs, no_other_refs); @@ -1726,6 +1746,12 @@ loop_prefetch_arrays (struct loop *loop) ninsns = tree_num_loop_insns (loop, &eni_size_weights); unroll_factor = determine_unroll_factor (loop, refs, ninsns, &desc, est_niter); + + /* Estimate prefetch count for the unrolled loop. */ + prefetch_count = estimate_prefetch_count (refs, unroll_factor); + if (prefetch_count == 0) + goto fail; + if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, "Ahead %d, unroll factor %d, trip count " HOST_WIDE_INT_PRINT_DEC "\n" -- 1.6.3.3