[clang] [llvm] [HLSL][DirectX] Implement HLSL `mul` function and DXIL lowering of `llvm.matrix.multiply` (PR #184882)

Deric C. via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 5 16:49:38 PST 2026


================
@@ -1054,6 +1055,68 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
     Value *Mul = Builder.CreateNUWMul(M, A);
     return Builder.CreateNUWAdd(Mul, B);
   }
+  case Builtin::BI__builtin_hlsl_mul: {
+    Value *Op0 = EmitScalarExpr(E->getArg(0));
+    Value *Op1 = EmitScalarExpr(E->getArg(1));
+    QualType QTy0 = E->getArg(0)->getType();
+    QualType QTy1 = E->getArg(1)->getType();
+
+    bool IsVec0 = QTy0->isVectorType();
+    bool IsVec1 = QTy1->isVectorType();
+    bool IsMat0 = QTy0->isConstantMatrixType();
+    bool IsMat1 = QTy1->isConstantMatrixType();
+
+    if (IsVec0 && IsVec1) {
+      // Case 5: vector * vector -> scalar (dot product)
----------------
Icohedron wrote:

Implemented in HLSL headers in `hlsl_intrinsics.h` instead of codegen for the built-in. This is a change requested by @farzonl to simplify the codegen logic for the built-in by reducing the number of cases it has to handle.

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


More information about the cfe-commits mailing list