From patchwork Sat Dec 29 10:56:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1019319 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-493183-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Zg9ilZjb"; dkim-atps=neutral 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 43RgVZ184Zz9s2P for ; Sat, 29 Dec 2018 21:56:19 +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:reply-to:mime-version:content-type; q=dns; s=default; b=ThLRhKPh7DeMZuftf4u7DAxg34A6Zs9XGsfYOLEM0m8 d5bhap/S5mfSkYgEOr8Waxigc/0XdW6LoNPTM1bDAZRIhy49EMEHLLL/oU0CKzuL JRpyUh8oh696+7IEWUcJv2MDh4ZZcMzfcpXLqd1uLO3u7FhFmLLSJKbI6aVvgiIk = 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:reply-to:mime-version:content-type; s=default; bh=2fa9tSn7xrZQ4I1zGzrlT9YgX0k=; b=Zg9ilZjb7EXi8wvbF TlHcBbgaovBrfmjrI7Fb4gq6SJK/IxNpVyZBeMMVd5/Khm29fvKZmWBMFpRool1s 9hRNCaA9epwnBKy7MdTPp7HDyCavFEqzjo0C0a+Jt8wkUcyCIky5IeToB8IEICUh 35OgOfJck3VOzrLNA+k+vYZ/3Y= Received: (qmail 82658 invoked by alias); 29 Dec 2018 10:56:12 -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 82649 invoked by uid 89); 29 Dec 2018 10:56:12 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=10000000, xa, reduction X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 29 Dec 2018 10:56:10 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 990BBC0495BA for ; Sat, 29 Dec 2018 10:56:09 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3F79C60C5C for ; Sat, 29 Dec 2018 10:56:09 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id wBTAu78P010000 for ; Sat, 29 Dec 2018 11:56:07 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id wBTAu6xi009999 for gcc-patches@gcc.gnu.org; Sat, 29 Dec 2018 11:56:06 +0100 Date: Sat, 29 Dec 2018 11:56:06 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [committed] Fix OpenMP 5.0 task reduction lowering (PR ipa/88586) Message-ID: <20181229105606.GB30353@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-IsSubscribed: yes Hi! The following testcase ICEs with -fopenmp -flto, because two fields in task reduction structure had NULL DECL_CONTEXT. Fixed thusly, additionally I've added type alignment adjustments that insert_field_into_struct normally does; I couldn't use that function though, because I don't want the reordering of fields that those functions do. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2018-12-29 Jakub Jelinek PR ipa/88586 * omp-low.c (lower_omp_task_reductions): Set DECL_CONTEXT on field and ifield. Update TYPE_ALIGN from alignment of field, ifield or bfield. * g++.dg/gomp/pr88586.C: New test. Jakub --- gcc/omp-low.c.jj 2018-12-02 13:47:35.082132060 +0100 +++ gcc/omp-low.c 2018-12-28 11:40:47.214649851 +0100 @@ -7011,6 +7011,12 @@ lower_omp_task_reductions (omp_context * *last = field; DECL_CHAIN (field) = ifield; last = &DECL_CHAIN (ifield); + DECL_CONTEXT (field) = record_type; + if (TYPE_ALIGN (record_type) < DECL_ALIGN (field)) + SET_TYPE_ALIGN (record_type, DECL_ALIGN (field)); + DECL_CONTEXT (ifield) = record_type; + if (TYPE_ALIGN (record_type) < DECL_ALIGN (ifield)) + SET_TYPE_ALIGN (record_type, DECL_ALIGN (ifield)); } for (int pass = 0; pass < 2; pass++) { @@ -7036,12 +7042,16 @@ lower_omp_task_reductions (omp_context * else SET_DECL_ALIGN (field, TYPE_ALIGN (type)); DECL_CONTEXT (field) = record_type; + if (TYPE_ALIGN (record_type) < DECL_ALIGN (field)) + SET_TYPE_ALIGN (record_type, DECL_ALIGN (field)); *last = field; last = &DECL_CHAIN (field); tree bfield = build_decl (OMP_CLAUSE_LOCATION (c), FIELD_DECL, NULL_TREE, boolean_type_node); DECL_CONTEXT (bfield) = record_type; + if (TYPE_ALIGN (record_type) < DECL_ALIGN (bfield)) + SET_TYPE_ALIGN (record_type, DECL_ALIGN (bfield)); *last = bfield; last = &DECL_CHAIN (bfield); } --- gcc/testsuite/g++.dg/gomp/pr88586.C.jj 2018-12-28 11:48:01.085562936 +0100 +++ gcc/testsuite/g++.dg/gomp/pr88586.C 2018-12-28 11:47:54.031678152 +0100 @@ -0,0 +1,77 @@ +// PR ipa/88586 +// { dg-do compile { target lto } } +// { dg-options "-fopenmp -flto" } + +extern "C" int omp_get_cancellation (); +extern "C" int omp_get_thread_num (); +extern "C" void abort (); + +struct A { A (); ~A (); A (const A &); static int cnt1, cnt2, cnt3; int a; }; +int A::cnt1; +int A::cnt2; +int A::cnt3; +A::A () : a (0) +{ + #pragma omp atomic + cnt1++; +} +A::A (const A &x) : a (x.a) +{ + #pragma omp atomic + cnt2++; +} +A::~A () +{ + #pragma omp atomic + cnt3++; +} +#pragma omp declare reduction (+: A: omp_out.a += omp_in.a) + +void +foo (int x) +{ + A a, b[2]; + int d = 1; + long int e[2] = { 1L, 1L }; + int c = 0; + #pragma omp parallel + { + if (x && omp_get_thread_num () == 0) + { + for (int i = 0; i < 10000000; ++i) + asm volatile (""); + c = 1; + #pragma omp cancel parallel + } + #pragma omp for reduction (task, +: a, b) reduction (task, *: d, e) + for (int i = 0; i < 64; i++) + #pragma omp task in_reduction (+: a, b) in_reduction (*: d, e) + { + a.a++; + b[0].a += 2; + b[1].a += 3; + d *= ((i & 7) == 0) + 1; + e[0] *= ((i & 7) == 3) + 1; + e[1] *= ((i & 3) == 2) + 1; + } + if (x && omp_get_cancellation ()) + abort (); + } + if (!c) + { + if (a.a != 64 || b[0].a != 128 || b[1].a != 192) + abort (); + if (d != 256 || e[0] != 256L || e[1] != 65536L) + abort (); + } +} + +int +main () +{ + int c1 = A::cnt1, c2 = A::cnt2, c3 = A::cnt3; + volatile int zero = 0; + foo (zero); + if (A::cnt1 + A::cnt2 - c1 - c2 != A::cnt3 - c3) + abort (); +}