From patchwork Tue Feb 15 09:26:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1592987 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=EPqaItPJ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JybML4Ny6z9sFk for ; Tue, 15 Feb 2022 20:26:53 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6191A385840D for ; Tue, 15 Feb 2022 09:26:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6191A385840D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1644917211; bh=7et/PQiaexS0YwP0b5vNxCRyHI7I+JpuX+yrM5DX9/g=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=EPqaItPJZnqxeI9ntgroivMqaNecJlitvYVcyFIagK30B642LkXG5PnalU2I0u/Et AQCleCfLi8lvEwrTLNDKZQpM+oj/ZJOps630zli0y4d4EcGFTobliYWl+jYxsE4ehq kjieXacu00dD/SOeRCOPqOp+YsQ/YLFqE/NfeXKU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 3FE683858D20 for ; Tue, 15 Feb 2022 09:26:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3FE683858D20 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-323-bVFhHrnZPyOmyP0z8Sb4Vg-1; Tue, 15 Feb 2022 04:26:28 -0500 X-MC-Unique: bVFhHrnZPyOmyP0z8Sb4Vg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8334B835B47 for ; Tue, 15 Feb 2022 09:26:27 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.125]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 29D4E16555 for ; Tue, 15 Feb 2022 09:26:26 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 21F9QO5G1943289 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT) for ; Tue, 15 Feb 2022 10:26:24 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 21F9QNi31943288 for gcc-patches@gcc.gnu.org; Tue, 15 Feb 2022 10:26:23 +0100 Date: Tue, 15 Feb 2022 10:26:23 +0100 To: gcc-patches@gcc.gnu.org Subject: [committed] openmp: Make finalize_task_copyfn order reproduceable [PR104517] Message-ID: <20220215092623.GK2646553@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi! The following testcase fails -fcompare-debug, because finalize_task_copyfn was invoked from splay tree destruction, whose order can in some cases depend on -g/-g0. The fix is to queue the task stmts that need copyfn in a vector and run finalize_task_copyfn on elements of that vector. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2022-02-15 Jakub Jelinek PR debug/104517 * omp-low.cc (task_cpyfns): New variable. (delete_omp_context): Don't call finalize_task_copyfn from here. (create_task_copyfn): Push task_stmt into task_cpyfns. (execute_lower_omp): Call finalize_task_copyfn here on entries from task_cpyfns vector and release the vector. * gcc.dg/gomp/pr104517.c: New test. Jakub --- gcc/omp-low.cc.jj 2022-02-11 00:19:22.343064464 +0100 +++ gcc/omp-low.cc 2022-02-14 13:45:57.311931078 +0100 @@ -191,6 +191,7 @@ static int target_nesting_level; static bitmap task_shared_vars; static bitmap global_nonaddressable_vars; static vec taskreg_contexts; +static vec task_cpyfns; static void scan_omp (gimple_seq *, omp_context *); static tree scan_omp_1_op (tree *, int *, void *); @@ -1082,9 +1083,6 @@ delete_omp_context (splay_tree_value val DECL_ABSTRACT_ORIGIN (t) = NULL; } - if (is_task_ctx (ctx)) - finalize_task_copyfn (as_a (ctx->stmt)); - if (ctx->task_reduction_map) { ctx->task_reductions.release (); @@ -11951,6 +11949,7 @@ create_task_copyfn (gomp_task *task_stmt size_t looptempno = 0; child_fn = gimple_omp_task_copy_fn (task_stmt); + task_cpyfns.safe_push (task_stmt); child_cfun = DECL_STRUCT_FUNCTION (child_fn); gcc_assert (child_cfun->cfg == NULL); DECL_SAVED_TREE (child_fn) = alloc_stmt_list (); @@ -14475,6 +14474,10 @@ execute_lower_omp (void) && (TREE_CODE (TREE_TYPE (DECL_ARGUMENTS (current_function_decl))) == POINTER_TYPE)) remove_member_access_dummy_vars (DECL_INITIAL (current_function_decl)); + + for (auto task_stmt : task_cpyfns) + finalize_task_copyfn (task_stmt); + task_cpyfns.release (); return 0; } --- gcc/testsuite/gcc.dg/gomp/pr104517.c.jj 2022-02-14 13:43:20.097123092 +0100 +++ gcc/testsuite/gcc.dg/gomp/pr104517.c 2022-02-14 13:42:57.810433826 +0100 @@ -0,0 +1,54 @@ +/* PR debug/104517 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -fcompare-debug -fopenmp -fno-tree-ter -save-temps" } */ + +enum { + omp_default_mem_alloc, + omp_large_cap_mem_alloc, + omp_const_mem_alloc, + omp_high_bw_mem_alloc +} omp_allocator_handle_t; + +int t, bar_nte, bar_tl, bar_i3, bar_dd; + +#pragma omp threadprivate(t) +#pragma omp declare target +int f, l, ll, r, r2; +#pragma omp end declare target + +void +bar (int *idp, int s, int nth, int g, int nta, int fi, int pp, int *q, + int ntm) +{ + int p = 0, i2 = 0, i1 = 0, m = 0, d = 0; + +#pragma omp target parallel for \ + device(p) firstprivate (f) allocate (f) in_reduction(+:r2) + for (int i = 0; i < 4; i++) + ll++; + +#pragma omp target parallel for \ + device(d) map (m) \ + if (target: p) firstprivate (f) defaultmap(tofrom: scalar) is_device_ptr (idp) \ + if (parallel: i2) reduction(+:r) num_threads (nth) linear (ll) \ + schedule(static) collapse(1) nowait depend(inout: d) allocate (f) \ + in_reduction(+:r2) + for (int i = 0; i < 4; i++) + ll++; + +#pragma omp taskloop simd firstprivate(f) lastprivate(s) grainsize(g) \ + collapse(1) untied if (i1) final(fi) mergeable nogroup \ + priority(pp) linear(ll) aligned(q) allocate(f) + for (int i = 0; i < 4; i++) + ll++; + +#pragma omp taskloop simd firstprivate(f) lastprivate(s) num_tasks(nta) \ + collapse(1) if (i1) final(fi) priority(pp) safelen(8) simdlen(4) \ + linear(ll) aligned(q) nontemporal(ntm) order(concurrent) allocate(f) + for (int i = 0; i < 4; i++) + ll++; + +#pragma omp parallel master firstprivate(f) shared(nth) proc_bind(spread) \ + copyin(t) allocate(f) + ; +}