[llvm-branch-commits] [clang] [llvm] [HLSL] Add `InterlockedCompareStoreFloatBitwise` function and resource methods (PR #222166)

Helena Kotas via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Sep 22 14:52:01 PDT 2026


================
@@ -945,13 +945,18 @@ static void defineHLSLInterlockedFunc(Sema &S, NamespaceDecl *NS,
 
 // Synthesize the compare-and-swap overload sets: {int, uint, int64_t,
 // uint64_t} x {groupshared, device}. Each function has one form only.
+// The float-bitwise operations have their own names and take float only.
 static void defineHLSLInterlockedCompareFunc(Sema &S, NamespaceDecl *NS,
                                              StringRef FuncName,
                                              StringRef BuiltinName,
-                                             AtomicOverloadShape Shape) {
+                                             AtomicOverloadShape Shape,
+                                             bool FloatOnly = false) {
   ASTContext &AST = S.getASTContext();
-  QualType Elems[] = {AST.IntTy, AST.UnsignedIntTy, AST.LongTy,
-                      AST.UnsignedLongTy};
+  QualType IntElems[] = {AST.IntTy, AST.UnsignedIntTy, AST.LongTy,
+                         AST.UnsignedLongTy};
+  QualType FloatElems[] = {AST.FloatTy};
+  ArrayRef<QualType> Elems =
+      FloatOnly ? ArrayRef<QualType>(FloatElems) : ArrayRef<QualType>(IntElems);
----------------
hekota wrote:

I am not a fan of creating arrays or other constructs that are not used. I think it would be better to have a standalone function for the float type:
```
static void defineHLSLInterlockedCompareFuncFloat(Sema &S, NamespaceDecl *NS,
                                             StringRef FuncName,
                                             StringRef BuiltinName,
                                             AtomicOverloadShape Shape) {
  ASTContext &AST = S.getASTContext();
  for (LangAS AS : {LangAS::hlsl_groupshared, LangAS::hlsl_device})
    buildAtomicOverload(S, NS, FuncName, BuiltinName, AST.FloatTy, AS, Shape);
}
```

https://github.com/llvm/llvm-project/pull/222166


More information about the llvm-branch-commits mailing list