The default address space in the GCN backend is distinct from the
flat/global address space that it normally coincides with so that it can
be changed. But, as a result, address space conversion must be aware of
this difference and handle the default address space explicitly.
Currently, it fails to do so, and so it reaches a gcc_unreachable.
This patch fixes that by resolving the default address space into
whatever address space it effectively is.
gcc/ChangeLog:
PR target/124044
* config/gcn/gcn.cc (gcn_addr_space_resolve_default): New
function. Converts from ADDR_SPACE_DEFAULT to
DEFAULT_ADDR_SPACE.
(gcn_addr_space_convert): Resolve from_type and to_type address
spaces.
gcc/testsuite/ChangeLog:
* gcc.target/gcn/pr124044.c: New test.
---
gcc/config/gcn/gcn.cc | 15 +++++++++++++--
gcc/testsuite/gcc.target/gcn/pr124044.c | 16 ++++++++++++++++
2 files changed, 29 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/gcn/pr124044.c
diff --git a/gcc/config/gcn/gcn.cc b/gcc/config/gcn/gcn.cc
index 8277fd15a78e..a8cadb8651f6 100644
--- a/gcc/config/gcn/gcn.cc
+++ b/gcc/config/gcn/gcn.cc
@@ -1874,6 +1874,15 @@ gcn_addr_space_subset_p (addr_space_t subset,
addr_space_t superset)
return false;
}
+static addr_space_t
+gcn_addr_space_resolve_default (addr_space_t as)
+{
+ if (as != ADDR_SPACE_DEFAULT)
+ return as;
+
+ return DEFAULT_ADDR_SPACE;
+}
+
/* Convert from one address space to another. */
static rtx
@@ -1882,8 +1891,10 @@ gcn_addr_space_convert (rtx op, tree from_type, tree
to_type)
gcc_assert (POINTER_TYPE_P (from_type));
gcc_assert (POINTER_TYPE_P (to_type));
- addr_space_t as_from = TYPE_ADDR_SPACE (TREE_TYPE (from_type));
- addr_space_t as_to = TYPE_ADDR_SPACE (TREE_TYPE (to_type));
+ addr_space_t as_from = (gcn_addr_space_resolve_default
+ (TYPE_ADDR_SPACE (TREE_TYPE (from_type))));
+ addr_space_t as_to = (gcn_addr_space_resolve_default
+ (TYPE_ADDR_SPACE (TREE_TYPE (to_type))));
if (AS_LDS_P (as_from) && AS_FLAT_P (as_to))
{
diff --git a/gcc/testsuite/gcc.target/gcn/pr124044.c
b/gcc/testsuite/gcc.target/gcn/pr124044.c
new file mode 100644
index 000000000000..450170f56fe5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/gcn/pr124044.c
@@ -0,0 +1,16 @@
+/* { dg-do compile }
+ { dg-options "-O -Wall" } */
+/* PR target/124044 */
+
+void *
+foo (void __flat* ptr)
+{ return ptr; }
+
+void __flat *
+foo2 (void* ptr)
+{ return ptr; }
+
+/* This test relies on flat addressing being used for pointers without a
+ specified address space. */
+/* { dg-final { scan-assembler-not "using global addressing" } }
+ { dg-final { scan-assembler-times "using flat addressing" 2 } } */
--
2.53.0