From patchwork Mon Jul 13 11:02:45 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: 494510 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 5567C1402B3 for ; Mon, 13 Jul 2015 21:03:10 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=pS3b2BuQ; 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:subject:content-type; q= dns; s=default; b=aoAwDCDvGm2YOigadcwnilcbmPQCn4JPvMfbwgYUedzgSM v9/+eqUqc5xwU7rmRnEKZD4qd83ECQIlIEMwwcG2wUObuS9L44bK9gS8fmsx0Dzo M3goK2MydQDdYKfmCCfAXgqGZD/JM9/GMiQHdAQy/sNpkpB3TwP/zOvVh927s= 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:subject:content-type; s= default; bh=tNds8Qa6AddmI8RfKhZ9sbX6r0Q=; b=pS3b2BuQHENOMGwq5+no 0M0Iy2iSz1bz7BW3p13n4aCbZ23lYeP/BfbxotilngZY6v65yhnwRahdAJvizOZH 4Jvx7oavHcj2IrVXChlMq39pVbEwqhw28Y+u/I2Ksf9i+7X77EhcvbCpSFxhkyVh WI4m5jZa5WkoCJI76wbhc80= Received: (qmail 128243 invoked by alias); 13 Jul 2015 11:03:03 -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 128230 invoked by uid 89); 13 Jul 2015 11:03:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: fencepost.gnu.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (208.118.235.10) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Mon, 13 Jul 2015 11:03:01 +0000 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52351) by fencepost.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1ZEbVj-0008Dp-DJ for gcc-patches@gnu.org; Mon, 13 Jul 2015 07:02:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZEbVe-0005ZV-UH for gcc-patches@gnu.org; Mon, 13 Jul 2015 07:02:58 -0400 Received: from relay1.mentorg.com ([192.94.38.131]:36059) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZEbVe-0005ZL-PS for gcc-patches@gnu.org; Mon, 13 Jul 2015 07:02:54 -0400 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 1ZEbVd-0004E3-TW from Tom_deVries@mentor.com for gcc-patches@gnu.org; Mon, 13 Jul 2015 04:02:54 -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, 13 Jul 2015 12:02:51 +0100 Message-ID: <55A39AD5.1020006@mentor.com> Date: Mon, 13 Jul 2015 13:02:45 +0200 From: Tom de Vries User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: "gcc-patches@gnu.org" Subject: [PATCH, PR46193] Handle mix/max pointer reductions in parloops X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 192.94.38.131 Hi, this patch fixes PR46193. It handles min and max reductions of pointer type in parloops. Bootstrapped and reg-tested on x86_64. OK for trunk? Thanks, - Tom Handle mix/max pointer reductions in parloops 2015-07-13 Tom de Vries PR tree-optimization/46193 * omp-low.c (omp_reduction_init): Handle pointer type for min or max clause. * gcc.dg/autopar/pr46193.c: New test. * testsuite/libgomp.c/pr46193.c: New test. --- gcc/omp-low.c | 4 ++ gcc/testsuite/gcc.dg/autopar/pr46193.c | 38 +++++++++++++++++++ libgomp/testsuite/libgomp.c/pr46193.c | 67 ++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/autopar/pr46193.c create mode 100644 libgomp/testsuite/libgomp.c/pr46193.c diff --git a/gcc/omp-low.c b/gcc/omp-low.c index 2e2070a..20d0010 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -3423,6 +3423,8 @@ omp_reduction_init (tree clause, tree type) real_maxval (&min, 1, TYPE_MODE (type)); return build_real (type, min); } + else if (POINTER_TYPE_P (type)) + return lower_bound_in_type (type, type); else { gcc_assert (INTEGRAL_TYPE_P (type)); @@ -3439,6 +3441,8 @@ omp_reduction_init (tree clause, tree type) real_maxval (&max, 0, TYPE_MODE (type)); return build_real (type, max); } + else if (POINTER_TYPE_P (type)) + return upper_bound_in_type (type, type); else { gcc_assert (INTEGRAL_TYPE_P (type)); diff --git a/gcc/testsuite/gcc.dg/autopar/pr46193.c b/gcc/testsuite/gcc.dg/autopar/pr46193.c new file mode 100644 index 0000000..544a5da --- /dev/null +++ b/gcc/testsuite/gcc.dg/autopar/pr46193.c @@ -0,0 +1,38 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ftree-parallelize-loops=2 -fdump-tree-parloops-details" } */ + +extern void abort (void); + +char * +foo (int count, char **list) +{ + char *minaddr = list[0]; + int i; + + for (i = 0; i < count; i++) + { + char *addr = list[i]; + if (addr < minaddr) + minaddr = addr; + } + + return minaddr; +} + +char * +foo2 (int count, char **list) +{ + char *maxaddr = list[0]; + int i; + + for (i = 0; i < count; i++) + { + char *addr = list[i]; + if (addr > maxaddr) + maxaddr = addr; + } + + return maxaddr; +} + +/* { dg-final { scan-tree-dump-times "parallelizing inner loop" 2 "parloops" } } */ diff --git a/libgomp/testsuite/libgomp.c/pr46193.c b/libgomp/testsuite/libgomp.c/pr46193.c new file mode 100644 index 0000000..1e27faf --- /dev/null +++ b/libgomp/testsuite/libgomp.c/pr46193.c @@ -0,0 +1,67 @@ +/* { dg-do run } */ +/* { dg-additional-options "-ftree-parallelize-loops=2" } */ + +extern void abort (void); + +char * +foo (int count, char **list) +{ + char *minaddr = list[0]; + int i; + + for (i = 0; i < count; i++) + { + char *addr = list[i]; + if (addr < minaddr) + minaddr = addr; + } + + return minaddr; +} + +char * +foo2 (int count, char **list) +{ + char *maxaddr = list[0]; + int i; + + for (i = 0; i < count; i++) + { + char *addr = list[i]; + if (addr > maxaddr) + maxaddr = addr; + } + + return maxaddr; +} + +#define N 5 + +static void +init (char **list) +{ + int i; + for (i = 0; i < N; ++i) + list[i] = (char *)&list[i]; +} + +int +main (void) +{ + char *list[N]; + char * res; + + init (list); + + res = foo (N, list); + + if (res != (char *)&list[0]) + abort (); + + res = foo2 (N, list); + + if (res != (char *)&list[N-1]) + abort (); + + return 0; +} -- 1.9.1