https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80262

            Bug ID: 80262
           Summary: address space gets lost in memory access
           Product: gcc
           Version: 6.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: stefan at reservoir dot com
  Target Milestone: ---

Created attachment 41086
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41086&action=edit
The source program

For an out-of-tree target that supports address spaces the address space is
lost during early sra in the following example when compiled with -O3:

---- cut ----
typedef int v4si __attribute__ (( __vector_size__ (16) ));

typedef struct {
  v4si v;
} S1;
S1 clearS1() { S1 s1 = { 0 }; return s1; }

typedef struct {
  S1 s2[4];
} S2;
void initS2(__ea S2* p, int i) {
  p->s2[i] = clearS1();
}
---- cut ----

At the end of forwprop1, in initS2 there still is the reference to p->s2[i],
but when esra creates a replacement for the result value of the inlined
clearS1, the memory reference is rewritten dropping the address space (see the
attached dumps).

Of course, I may have introduced this bug with my changes, maybe someone with a
target that supports address spaces can confirm this problem?

The problem appears to be due to the type returned by reference_alias_ptr_type
in this case: it builds a pointer to the TYPE_MAIN_VARIANT, thus dropping the
address space qualifier. The following patch may solve this problem:

---- cut ----
--- orig_gcc-6.3.0/gcc/alias.c  2016-12-07 22:47:48.000000000 +0000
+++ gcc/gcc/alias.c     2017-03-29 13:42:15.192688629 +0000
@@ -784,7 +784,13 @@
       || TREE_CODE (t) == TARGET_MEM_REF)
     return TREE_TYPE (TREE_OPERAND (t, 1));
   else
-    return build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (t)));
+    {
+      addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (t));
+      tree tem = TYPE_MAIN_VARIANT (TREE_TYPE (t));
+      if (!ADDR_SPACE_GENERIC_P (as))
+       tem = build_qualified_type (tem, ENCODE_QUAL_ADDR_SPACE (as));
+      return build_pointer_type (tem);
+    }
 }

 /* Return whether the pointer-types T1 and T2 used to determine
---- cut ----

Reply via email to