From patchwork Mon Oct 24 16:50:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Stubbs X-Patchwork-Id: 59361 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 20F5A38561AA for ; Mon, 24 Oct 2022 16:51:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id 164423858284 for ; Mon, 24 Oct 2022 16:50:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 164423858284 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.95,209,1661846400"; d="scan'208";a="85153627" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 24 Oct 2022 08:50:45 -0800 IronPort-SDR: QOCQhLEKPkdBpsd57JlSvb1Jm4iIvC4CgKQL4s1RrN+A6ft/Yk0Hy59bL/dG+GlzD0jCGKbqZT S3YXMqE0LgGw06v6i48T6xjzPIFYFXMjOcOSv+PTt663PIZhL1MLd2cNRM+6BFdwphd6zFtomw 9RQdY7zAuzViTk9zEq0AsRtLD2S0aW9YOsc8LjECboZVeXfbch3dQnELa7/eEZEebR8FcAVaxb z1C3Sepiwwj1kRg7dh5tRiEmYMEtJiFmwZ19n+9N5P1UxgJ89Kkz8euu7hMtxfJNvImT1WMqf5 tZc= Message-ID: <264e9c27-cef4-b2a5-8758-a8b621428e01@codesourcery.com> Date: Mon, 24 Oct 2022 17:50:40 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Content-Language: en-GB From: Andrew Stubbs Subject: [OG12 commit] vect: WORKAROUND vectorizer bug To: "gcc-patches@gcc.gnu.org" X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-14.mgc.mentorg.com (139.181.222.14) To svr-ies-mbx-11.mgc.mentorg.com (139.181.222.11) X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" I've committed this to the OG12 branch to remove some test failures. We probably ought to have something on mainline also, but a proper fix would be better. Without this. the libgomp.oacc-c-c++-common/private-variables.c testcase fails to compile due to an ICE. The OpenACC worker broadcasting code is creating SLP optimizable loads and stores in amdgcn address-space-4. Previously this was "ok" as SLP didn't work with less that 64-lane vectors, but the newly implemented smaller vectors are working as intended and optimizing this. Unfortunately the vectorizer is losing the address-space data from the intermediate types, and it all falls apart during expand when it tries the convert a 32-bit address into a 64-bit address and that's not something that works. At first sight it looks like we could possibly make that work with POINTERS_EXTEND_UNSIGNED, but that only changes the error message. Fundamentally we need to make sure that various instances of "vectype" have the correct address space, but my attempts to do so showed that that's a larger task than I have time for right now. This patch simply prevents the vectorizer working in the case where it would break. This should not be a regression because this code didn't vectorize at all, previously. Andrew vect: WORKAROUND vectorizer bug This patch disables vectorization of memory accesses to non-default address spaces where the pointer size is different to the usual pointer size. This condition typically occurs in OpenACC programs on amdgcn, where LDS memory is used for broadcasting gang-private variables between threads. In particular, see libgomp.oacc-c-c++-common/private-variables.c The problem is that the address space information is dropped from the various types in the middle-end and eventually it triggers an ICE trying to do an address conversion. That ICE can be avoided by defining POINTERS_EXTEND_UNSIGNED, but that just produces wrong RTL code later on. A correct solution would ensure that all the vectypes have the correct address spaces, but I don't have time for that right now. gcc/ChangeLog: * tree-vect-data-refs.cc (vect_analyze_data_refs): Workaround an address-space bug. diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc index 09223baf718..70b671ed94a 100644 --- a/gcc/tree-vect-data-refs.cc +++ b/gcc/tree-vect-data-refs.cc @@ -4598,7 +4598,21 @@ vect_analyze_data_refs (vec_info *vinfo, poly_uint64 *min_vf, bool *fatal) /* Set vectype for STMT. */ scalar_type = TREE_TYPE (DR_REF (dr)); tree vectype = get_vectype_for_scalar_type (vinfo, scalar_type); - if (!vectype) + + /* FIXME: If the object is in an address-space in which the pointer size + is different to the default address space then vectorizing here will + lead to an ICE down the road because the address space information + gets lost. This work-around fixes the problem until we have a proper + solution. */ + tree base_object = DR_REF (dr); + tree op = (TREE_CODE (base_object) == COMPONENT_REF + || TREE_CODE (base_object) == ARRAY_REF + ? TREE_OPERAND (base_object, 0) : base_object); + addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (op)); + bool addr_space_bug = (!ADDR_SPACE_GENERIC_P (as) + && targetm.addr_space.pointer_mode (as) != Pmode); + + if (!vectype || addr_space_bug) { if (dump_enabled_p ()) {