[gcc/devel/omp/gcc-16] vect: WORKAROUND vectorizer bug

Sandra Loosemore via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:10f73e73eb0c16ff5febc69ad270cf7ab03e46d7

commit 10f73e73eb0c16ff5febc69ad270cf7ab03e46d7
Author: Andrew Stubbs <[email protected]>
Date:   Fri Oct 21 14:19:31 2022 +0100

    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:
---
 gcc/tree-vect-data-refs.cc | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc
index ae556d85c7f9..dac25031c7b8 100644
--- a/gcc/tree-vect-data-refs.cc
+++ b/gcc/tree-vect-data-refs.cc
@@ -5504,7 +5504,21 @@ vect_analyze_data_refs (vec_info *vinfo, 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 ())
             {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.