From patchwork Tue Jul 30 07:34:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1138824 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-505791-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="ljqzWrbe"; 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 45ySxC1fh9z9s3Z for ; Tue, 30 Jul 2019 17:34:20 +1000 (AEST) 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=O3Zqaqrl9c/cEVaBLgZ6bjR3UeT8RCBt56dnvqGjNwy XY9h79KWgtaOzOUxllx0/z/p7gKUD1A452CGZecCzjfq1sq66uwUZ8ASYb5X6dk2 WtkKtXw7lOzXBVzSUQY1z7W8XUioAr8SNoGF2ebLcnhvTsY71+bYSH154GimMWGo = 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=LoVwWNimFttlAqCyT4e7qWRkzsI=; b=ljqzWrbeiWRssvXjz vXhrsim1tgHjMRx2wKyOPSNJI+fz3fbgtkZQJO9b4kBLRCuS0GABGZlSAW2U8zSI /Lxr0Swswhk0FqEKwuc6fFm+vB6QvjA02XsS/Nf3DmzavJnVepjI4YhIf617+TAR vZf9jBRk3xv5e/qqybLyLQINVA= Received: (qmail 6118 invoked by alias); 30 Jul 2019 07:34:14 -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 6102 invoked by uid 89); 30 Jul 2019 07:34:14 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=duration 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; Tue, 30 Jul 2019 07:34:12 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8CBAF2F8BE3 for ; Tue, 30 Jul 2019 07:34:11 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-108.ams2.redhat.com [10.36.116.108]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 346515C1A1 for ; Tue, 30 Jul 2019 07:34:11 +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 x6U7Y9eb022599 for ; Tue, 30 Jul 2019 09:34:09 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id x6U7Y71a022598 for gcc-patches@gcc.gnu.org; Tue, 30 Jul 2019 09:34:07 +0200 Date: Tue, 30 Jul 2019 09:34:07 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [committed] Fix omp lowering when global vars turn to be addressable while lowering (PR middle-end/91216) Message-ID: <20190730073407.GL15878@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.11.3 (2019-02-01) X-IsSubscribed: yes Hi! We ICE on the following testcase, because the reduction is expanded as __atomic_* operation on the address of the global variable which makes the global var, previously not TREE_ADDRESSABLE, suddenly TREE_ADDRESSABLE during the lowering, but after scanning when we decided how to pass certain vars. If the variable is then privatized again, the scanning and lowering disagrees on how to pass it. I believe this can happen only for global vars and the following patch fixes it by remembering the global vars for which we saw once they aren't addressable and repeating that even in cases where they are later addressable. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk, queued for backporting. 2019-07-30 Jakub Jelinek PR middle-end/91216 * omp-low.c (global_nonaddressable_vars): New variable. (use_pointer_for_field): For global decls, if they are non-addressable, remember it in the global_nonaddressable_vars bitmap, if they are addressable and in the global_nonaddressable_vars bitmap, ignore their TREE_ADDRESSABLE bit. (omp_copy_decl_2): Clear TREE_ADDRESSABLE also on private copies of vars in global_nonaddressable_vars bitmap. (execute_lower_omp): Free global_nonaddressable_vars bitmap. * gcc.dg/gomp/pr91216.c: New test. Jakub --- gcc/omp-low.c.jj 2019-07-20 13:18:54.477980721 +0200 +++ gcc/omp-low.c 2019-07-29 18:49:04.838065123 +0200 @@ -162,6 +162,7 @@ static splay_tree all_contexts; static int taskreg_nesting_level; static int target_nesting_level; static bitmap task_shared_vars; +static bitmap global_nonaddressable_vars; static vec taskreg_contexts; static void scan_omp (gimple_seq *, omp_context *); @@ -426,7 +427,26 @@ use_pointer_for_field (tree decl, omp_co /* Do not use copy-in/copy-out for variables that have their address taken. */ - if (TREE_ADDRESSABLE (decl)) + if (is_global_var (decl)) + { + /* For file scope vars, track whether we've seen them as + non-addressable initially and in that case, keep the same + answer for the duration of the pass, even when they are made + addressable later on e.g. through reduction expansion. Global + variables which weren't addressable before the pass will not + have their privatized copies address taken. See PR91216. */ + if (!TREE_ADDRESSABLE (decl)) + { + if (!global_nonaddressable_vars) + global_nonaddressable_vars = BITMAP_ALLOC (NULL); + bitmap_set_bit (global_nonaddressable_vars, DECL_UID (decl)); + } + else if (!global_nonaddressable_vars + || !bitmap_bit_p (global_nonaddressable_vars, + DECL_UID (decl))) + return true; + } + else if (TREE_ADDRESSABLE (decl)) return true; /* lower_send_shared_vars only uses copy-in, but not copy-out @@ -504,8 +524,10 @@ omp_copy_decl_2 (tree var, tree name, tr it's address. But we don't need to take address of privatizations from that var. */ if (TREE_ADDRESSABLE (var) - && task_shared_vars - && bitmap_bit_p (task_shared_vars, DECL_UID (var))) + && ((task_shared_vars + && bitmap_bit_p (task_shared_vars, DECL_UID (var))) + || (global_nonaddressable_vars + && bitmap_bit_p (global_nonaddressable_vars, DECL_UID (var))))) TREE_ADDRESSABLE (copy) = 0; ctx->block_vars = copy; @@ -12730,6 +12752,7 @@ execute_lower_omp (void) all_contexts = NULL; } BITMAP_FREE (task_shared_vars); + BITMAP_FREE (global_nonaddressable_vars); /* If current function is a method, remove artificial dummy VAR_DECL created for non-static data member privatization, they aren't needed for --- gcc/testsuite/gcc.dg/gomp/pr91216.c.jj 2019-07-29 18:57:02.915209678 +0200 +++ gcc/testsuite/gcc.dg/gomp/pr91216.c 2019-07-29 18:56:53.930338628 +0200 @@ -0,0 +1,20 @@ +/* PR middle-end/91216 */ + +int r; + +void +foo (int *a) +{ + int i; + #pragma omp for reduction(+:r) + for (i = 0; i < 64; i++) + a[i] = i; + #pragma omp for private (r) + for (i = 0; i < 64; i++) + { + r = 0; + #pragma omp parallel shared(r) + #pragma omp master + r = r + 1; + } +}