[libcxx-commits] [libcxx] [libcxx] Adjust inline assembly constraints for the AMDGPU target (PR #101747)
Joseph Huber via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Aug 5 09:43:54 PDT 2024
https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/101747
>From be681d36302900b67e02b4b87507e9b6aec2a8e2 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Fri, 2 Aug 2024 14:00:42 -0500
Subject: [PATCH 1/2] [libc] Adjust inline assembly constraints for the AMDGPU
target
Summary:
These assembly constraints are illegal / invalid on the AMDGPU target.
The `r` constraint is only valid on inputs and the `m` constraint isn't
accepted at all. The NVPTX target can handle them because it uses a more
permissive virtual machine (PTX is an IR). Simply add exceptions on the
target to make these work.
---
libcxx/test/support/test_macros.h | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/libcxx/test/support/test_macros.h b/libcxx/test/support/test_macros.h
index 15fc5b69b5207..d05d580826fe2 100644
--- a/libcxx/test/support/test_macros.h
+++ b/libcxx/test/support/test_macros.h
@@ -291,17 +291,27 @@ struct is_same<T, T> { enum {value = 1}; };
// when optimizations are enabled.
template <class Tp>
inline Tp const& DoNotOptimize(Tp const& value) {
- asm volatile("" : : "r,m"(value) : "memory");
- return value;
+ // The `m` constraint is invalid in the AMDGPU backend.
+# if defined(__AMDGPU__) || defined(__NVPTX__)
+ asm volatile("" : : "r"(value) : "memory");
+# else
+ asm volatile("" : : "r,m"(value) : "memory");
+# endif
+ return value;
}
template <class Tp>
inline Tp& DoNotOptimize(Tp& value) {
-#if defined(__clang__)
+ // The `m` and `r` output constraint is invalid in the AMDGPU backend as well
+ // as i8 / i1 arguments, so we just capture the pointer instead.
+# if defined(__AMDGPU__)
+ Tp *tmp = &value;
+ asm volatile("" : "+v"(tmp) : : "memory");
+# elif defined(__clang__)
asm volatile("" : "+r,m"(value) : : "memory");
-#else
+# else
asm volatile("" : "+m,r"(value) : : "memory");
-#endif
+# endif
return value;
}
#else
>From 927a2d7d27dabc3084f6ca9bd1780a57327f8794 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Mon, 5 Aug 2024 11:43:46 -0500
Subject: [PATCH 2/2] Update test_macros.h
---
libcxx/test/support/test_macros.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcxx/test/support/test_macros.h b/libcxx/test/support/test_macros.h
index d05d580826fe2..e96208c85d1d2 100644
--- a/libcxx/test/support/test_macros.h
+++ b/libcxx/test/support/test_macros.h
@@ -305,7 +305,7 @@ inline Tp& DoNotOptimize(Tp& value) {
// The `m` and `r` output constraint is invalid in the AMDGPU backend as well
// as i8 / i1 arguments, so we just capture the pointer instead.
# if defined(__AMDGPU__)
- Tp *tmp = &value;
+ Tp* tmp = &value;
asm volatile("" : "+v"(tmp) : : "memory");
# elif defined(__clang__)
asm volatile("" : "+r,m"(value) : : "memory");
More information about the libcxx-commits
mailing list