From patchwork Wed Nov 24 09:42:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 48056 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9C12F3857C44 for ; Wed, 24 Nov 2021 09:42:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9C12F3857C44 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637746961; bh=M/vGtSIa0y+cruZpK+tfW9pdHLxcybMn5wVCBrnJ/PM=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=SW+DpUZKfDA+h1BpeV1z4GkZlSuT2efvvVTNXrLrUa/08XU3Z+onPUF6DntSYWzK/ kpJstSwsyAkq5xJahPReDA/zXw9+UDO9oSy/6DFRnKlSlU52eetLgVNsKRvyeLMXMq GaEpOgQVPAspU58z9ZgyyYzbWeSo8qq2AG/t2UDs= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id D324F385841B for ; Wed, 24 Nov 2021 09:42:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D324F385841B 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-176-QaKnDF41M86SEEeljtQGBw-1; Wed, 24 Nov 2021 04:42:08 -0500 X-MC-Unique: QaKnDF41M86SEEeljtQGBw-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 42E311006AA0; Wed, 24 Nov 2021 09:42:07 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.23]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BCCCA79458; Wed, 24 Nov 2021 09:42:06 +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 1AO9g3aG3996224 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 24 Nov 2021 10:42:04 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 1AO9g3Uu3996223; Wed, 24 Nov 2021 10:42:03 +0100 Date: Wed, 24 Nov 2021 10:42:02 +0100 To: gcc-patches@gcc.gnu.org Subject: [committed] openmp: Fix up handling of kind(host) and kind(nohost) in ACCEL_COMPILERs [PR103384] Message-ID: <20211124094202.GM2646553@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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 Cc: Tobias Burnus Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! As the testcase shows, we weren't handling kind(host) and kind(nohost) properly in the ACCEL_COMPILERs, the code written in there is valid for the host compiler only, where if we are maybe offloaded, we defer resolution after IPA, otherwise return 0 for kind(nohost) and accept it for kind(host). Note, omp_maybe_offloaded is false after IPA. If ACCEL_COMPILER is defined, it is the other way around, but also we know we are after IPA. Bootstrapped/regtested on x86_64-linux and i686-linux and tested with offloading to nvptx-none where the new testcase fails without the patch, committed to trunk. 2021-11-24 Jakub Jelinek PR middle-end/103384 gcc/ * omp-general.c (omp_context_selector_matches): For ACCEL_COMPILER, return 0 for kind(host) and continue for kind(nohost). libgomp/ * testsuite/libgomp.c/declare-variant-2.c: New test. Jakub --- gcc/omp-general.c.jj 2021-10-15 11:59:16.135683948 +0200 +++ gcc/omp-general.c 2021-11-23 15:45:32.761468592 +0100 @@ -1487,16 +1487,22 @@ omp_context_selector_matches (tree ctx) continue; if (!strcmp (prop, "host")) { +#ifdef ACCEL_COMPILER + return 0; +#else if (omp_maybe_offloaded ()) ret = -1; continue; +#endif } if (!strcmp (prop, "nohost")) { +#ifndef ACCEL_COMPILER if (omp_maybe_offloaded ()) ret = -1; else return 0; +#endif continue; } int r = 0; --- libgomp/testsuite/libgomp.c/declare-variant-2.c.jj 2021-11-24 10:14:11.689619756 +0100 +++ libgomp/testsuite/libgomp.c/declare-variant-2.c 2021-11-24 10:20:37.956110726 +0100 @@ -0,0 +1,45 @@ +/* { dg-do run } */ + +#include +#include + +void +foo_host (void) +{ + if (!omp_is_initial_device ()) + abort (); +} + +#pragma omp declare variant (foo_host) match (device={kind(host)}) +void +foo (void) +{ + if (omp_is_initial_device ()) + abort (); +} + +void +bar_nohost (void) +{ + if (omp_is_initial_device ()) + abort (); +} + +#pragma omp declare variant (bar_nohost) match (device={kind(nohost)}) +void +bar (void) +{ + if (!omp_is_initial_device ()) + abort (); +} + +int +main () +{ + #pragma omp target + { + foo (); + bar (); + } + return 0; +}