[clang] [llvm] [HLSL][DirectX][SPIRV] Implement the `fma` API (PR #185304)

via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 10 07:07:29 PDT 2026


================
@@ -3930,6 +3818,36 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
     TheCall->setType(ArgTyA);
     break;
   }
+  case Builtin::BI__builtin_hlsl_elementwise_fma: {
+    if (SemaRef.checkArgCount(TheCall, 3) ||
+        CheckAllArgsHaveSameType(&SemaRef, TheCall)) {
+      return true;
+    }
+    const llvm::Triple &TT = getASTContext().getTargetInfo().getTriple();
+    // This check is here because emitting a general error for both backends
+    // here (like for exmaple "Accepts only floating points") won't end really
+    // good. after that we still need to check if the types satisfy
+    // backends constrains, so we better check everything now rather than
+    // confusing user with 2 different error messages
+
+    if (TT.isSPIRV()) {
+      // SPIR-V accept any float (besides matrices)
+      if (CheckAllArgTypesAreCorrect(&SemaRef, TheCall,
+                                     CheckFloatOrHalfOrDoubleRepresentation))
+        return true;
+    } else if (TT.isDXIL()) {
+      // while DirectX accepts only double
+      if (CheckAllArgTypesAreCorrect(&SemaRef, TheCall,
+                                     CheckAnyDoubleRepresentation))
+        return true;
+    }
----------------
NeKon69 wrote:

I didn't quite understand what you mean here.. Do i just make it any float (including matrices) for SPIRV and then only doubles for DXIL? or is there supposed to be some condition to support SPIRV's doubles?

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


More information about the cfe-commits mailing list