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

via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 10 08:50:31 PDT 2026


================
@@ -1028,6 +979,22 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
         retType, CGM.getHLSLRuntime().getIsNaNIntrinsic(),
         ArrayRef<Value *>{Op0}, nullptr, "hlsl.isnan");
   }
+  case Builtin::BI__builtin_hlsl_elementwise_fma: {
+    Value *M = EmitScalarExpr(E->getArg(0));
+    Value *A = EmitScalarExpr(E->getArg(1));
+    Value *B = EmitScalarExpr(E->getArg(2));
+    if (CGM.getTarget().getTriple().isDXIL())
+      return Builder.CreateIntrinsic(M->getType(), Intrinsic::dx_fma,
+                                     ArrayRef<Value *>{M, A, B}, nullptr,
+                                     "dx.fma");
+
+    if (CGM.getTarget().getTriple().isSPIRV())
+      return Builder.CreateIntrinsic(M->getType(), Intrinsic::spv_fma,
+                                     ArrayRef<Value *>{M, A, B}, nullptr,
+                                     "spv.fma");
+
+    break;
+  }
----------------
NeKon69 wrote:

Ok i've hit an issue right now, since i changed to ` __builtin_elementwise_fma` as per your suggestion now my code also falls under the 
```
  case Builtin::BI__builtin_elementwise_fma:
    if (BuiltinElementwiseTernaryMath(TheCall))
      return ExprError();
    break;  
```

in `SemaChecking.cpp` which is problematic because it rejects matrices... what should i do?

`error: 1st argument must be a scalar or vector of floating-point types (was 'double2x2' (aka 'matrix<double, 2, 2>'))`

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


More information about the cfe-commits mailing list