[clang] [llvm] [HLSL] Implement HLSL `mul` function (PR #184882)

Farzon Lotfi via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 5 13:10:31 PST 2026


================
@@ -1006,6 +1007,96 @@ 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();
+    llvm::Type *T0 = Op0->getType();
+
+    bool IsScalar0 = QTy0->isScalarType();
+    bool IsVec0 = QTy0->isVectorType();
+    bool IsMat0 = QTy0->isConstantMatrixType();
+    bool IsScalar1 = QTy1->isScalarType();
+    bool IsVec1 = QTy1->isVectorType();
+    bool IsMat1 = QTy1->isConstantMatrixType();
+    bool IsFP =
+        QTy0->hasFloatingRepresentation() || QTy1->hasFloatingRepresentation();
----------------
farzonl wrote:

Deric could we do all the cases that don't result in  emitting `Intrinsic::matrix_multiply` in the header instead. I think that would make  many of these cases you have here go away.

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


More information about the cfe-commits mailing list