[clang] [llvm] [HLSL][SPIRV]Add SPIRV generation for HLSL dot (PR #104656)

Farzon Lotfi via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 19 12:34:11 PDT 2024


================
@@ -1446,6 +1452,90 @@ bool SPIRVInstructionSelector::selectRsqrt(Register ResVReg,
       .constrainAllUses(TII, TRI, RBI);
 }
 
+// Select the OpDot instruction for the given float dot
+bool SPIRVInstructionSelector::selectFloatDot(Register ResVReg,
+                                              const SPIRVType *ResType,
+                                              MachineInstr &I) const {
+  assert(I.getNumOperands() == 4);
+  assert(I.getOperand(2).isReg());
+  assert(I.getOperand(3).isReg());
+
+  [[maybe_unused]] SPIRVType *VecType =
+      GR.getSPIRVTypeForVReg(I.getOperand(2).getReg());
+
+  assert(GR.getScalarOrVectorComponentCount(VecType) > 1 &&
+         "dot product requires a vector of at least 2 components");
+
----------------
farzonl wrote:

should we also add an assert to make sure its a float vector? I know we have guarantees about that via `Intrinsic::spv_fdot` but I was concerned about misuse of the `selectFloatDot` function if say someone else wants to come along and use it for opencl? Its a nit pick so feel free to ignore.

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


More information about the llvm-commits mailing list