From patchwork Mon Aug 24 14:28:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 510054 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 B4112140549 for ; Tue, 25 Aug 2015 00:28:34 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=NzecM8GR; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=kDEuZSYss1Gnj+HkR 77IrNr4eaf8uh082Hc5SrqLIp7L+SnGjHAnazYvh4ZpvlsmB8lMR63iUqDaHrQZJ DAzfvjzbKP9+957rN/x5iVhEuCc8KFfv2F6YtsCPaJUwwFThvFEiOW+BGPPZM15Q l9JVGvnikTnu6nZ+UJSSmauMPk= 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 :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=pw8Le9NAHxPPH3waX+zhbhJ KCiA=; b=NzecM8GRxMpLp0KhVit9dq+RUsq1dBjsLJgjLXg1Rhka5EzcypC8vdL RJfsbveEnTQ1Kww66xb2k1I3JkSASKCbeSMOSB9xR1T+JsdAsDwTqPp21NKAaFh+ TB/30BQAjzdR0s/QIGF7L5GU/zYISbxgCtYusfEU4FeZ2EwRai6U= Received: (qmail 53451 invoked by alias); 24 Aug 2015 14:28:28 -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 53436 invoked by uid 89); 24 Aug 2015 14:28:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Aug 2015 14:28:26 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-01.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1ZTsjX-0007jG-LY from Tom_deVries@mentor.com ; Mon, 24 Aug 2015 07:28:24 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.3.224.2; Mon, 24 Aug 2015 15:28:21 +0100 Message-ID: <55DB2A03.90304@mentor.com> Date: Mon, 24 Aug 2015 16:28:19 +0200 From: Tom de Vries User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 MIME-Version: 1.0 To: Jakub Jelinek CC: "gcc-patches@gcc.gnu.org" Subject: Re: [PATCH][gomp4] Optimize expand_omp_for_static_chunk for chunk_size one References: <53D61631.8090605@mentor.com> <20150824094315.GG9425@tucnak.redhat.com> In-Reply-To: <20150824094315.GG9425@tucnak.redhat.com> On 24-08-15 11:43, Jakub Jelinek wrote: > On Mon, Jul 28, 2014 at 11:21:53AM +0200, Tom de Vries wrote: >> Jakub, >> >> we're using expand_omp_for_static_chunk with a chunk_size of one to expand the >> openacc loop construct. >> >> This results in an inner and outer loop being generated, with the inner loop >> having a trip count of one, which means that the inner loop can be simplified to >> just the inner loop body. However, subsequent optimizations do not manage to do >> this simplification. >> >> This patch sets the loop exit condition to true if the chunk_size is one, to >> ensure that the compiler will optimize away the inner loop. >> >> OK for gomp4 branch? >> >> Thanks, >> - Tom > >> 2014-07-25 Tom de Vries >> >> * omp-low.c (expand_omp_for_static_chunk): Remove inner loop if >> chunk_size is one. > > If that is still the case on the trunk, the patch is ok for trunk after > retesting it. Please mention the PR tree-optimization/65468 in the > ChangeLog entry and make sure there is some runtime testcase that tests > that code path (both OpenMP and OpenACC one). > Committed attached patch to trunk. I'll look into openacc testcase for trunk. Thanks, - Tom Optimize expand_omp_for_static_chunk for chunk_size one 2015-08-24 Tom de Vries PR tree-optimization/65468 * omp-low.c (expand_omp_for_static_chunk): Remove inner loop if chunk_size is one. * gcc.dg/gomp/static-chunk-size-one.c: New test. * testsuite/libgomp.c/static-chunk-size-one.c: New test. --- gcc/omp-low.c | 11 ++++++++--- gcc/testsuite/gcc.dg/gomp/static-chunk-size-one.c | 18 +++++++++++++++++ .../testsuite/libgomp.c/static-chunk-size-one.c | 23 ++++++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/gomp/static-chunk-size-one.c create mode 100644 libgomp/testsuite/libgomp.c/static-chunk-size-one.c diff --git a/gcc/omp-low.c b/gcc/omp-low.c index d181101..19f34ec 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -7204,9 +7204,14 @@ expand_omp_for_static_chunk (struct omp_region *region, assign_stmt = gimple_build_assign (vback, t); gsi_insert_before (&gsi, assign_stmt, GSI_SAME_STMT); - t = build2 (fd->loop.cond_code, boolean_type_node, - DECL_P (vback) && TREE_ADDRESSABLE (vback) - ? t : vback, e); + if (tree_int_cst_equal (fd->chunk_size, integer_one_node)) + t = build2 (EQ_EXPR, boolean_type_node, + build_int_cst (itype, 0), + build_int_cst (itype, 1)); + else + t = build2 (fd->loop.cond_code, boolean_type_node, + DECL_P (vback) && TREE_ADDRESSABLE (vback) + ? t : vback, e); gsi_insert_before (&gsi, gimple_build_cond_empty (t), GSI_SAME_STMT); } diff --git a/gcc/testsuite/gcc.dg/gomp/static-chunk-size-one.c b/gcc/testsuite/gcc.dg/gomp/static-chunk-size-one.c new file mode 100644 index 0000000..e82de77 --- /dev/null +++ b/gcc/testsuite/gcc.dg/gomp/static-chunk-size-one.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-fopenmp -O2 -fdump-tree-optimized -fno-tree-pre" } */ + +int +bar () +{ + int a = 0, i; + +#pragma omp parallel for num_threads (3) reduction (+:a) schedule(static, 1) + for (i = 0; i < 10; i++) + a += i; + + return a; +} + +/* Two phis for reduction, one in loop header, one in loop exit. One phi for iv + in loop header. */ +/* { dg-final { scan-tree-dump-times "PHI" 3 "optimized" } } */ diff --git a/libgomp/testsuite/libgomp.c/static-chunk-size-one.c b/libgomp/testsuite/libgomp.c/static-chunk-size-one.c new file mode 100644 index 0000000..9ed7b83 --- /dev/null +++ b/libgomp/testsuite/libgomp.c/static-chunk-size-one.c @@ -0,0 +1,23 @@ +extern void abort (); + +int +bar () +{ + int a = 0, i; + +#pragma omp parallel for num_threads (3) reduction (+:a) schedule(static, 1) + for (i = 0; i < 10; i++) + a += i; + + return a; +} + +int +main (void) +{ + int res; + res = bar (); + if (res != 45) + abort (); + return 0; +} -- 1.9.1