[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)

David Peixotto via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 8 13:46:32 PST 2024


================
@@ -17895,6 +17898,52 @@ llvm::Value *CodeGenFunction::EmitScalarOrConstFoldImmArg(unsigned ICEArguments,
   return Arg;
 }
 
+Value *CodeGenFunction::EmitDXILBuiltinExpr(unsigned BuiltinID,
+                                            const CallExpr *E) {
+  switch (BuiltinID) {
+  case Builtin::BI__builtin_hlsl_dot: {
+    Value *Op0 = EmitScalarExpr(E->getArg(0));
+    Value *Op1 = EmitScalarExpr(E->getArg(1));
+    llvm::Type *T0 = Op0->getType();
+    llvm::Type *T1 = Op1->getType();
+    if (!T0->isVectorTy() && !T1->isVectorTy()) {
+      if (T0->isFloatingPointTy()) {
+        return Builder.CreateFMul(Op0, Op1, "dx.dot");
+      }
+
+      if (T0->isIntegerTy()) {
+        return Builder.CreateMul(Op0, Op1, "dx.dot");
+      }
+      ErrorUnsupported(
+          E,
+          "Dot product on a scalar is only supported on integers and floats.");
+    }
+
+    if (T0->isVectorTy() && T1->isVectorTy()) {
+
+      if (T0->getScalarType() != T1->getScalarType()) {
+        ErrorUnsupported(E,
----------------
dmpots wrote:

I would expect to see tests for these error conditions to exercise this code.

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


More information about the cfe-commits mailing list