[llvm] [SPIR-V] Fix OpenCL integer dot product lowering (PR #177258)
Dmitry Sidorov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 22 04:48:41 PST 2026
================
@@ -1198,4 +1198,58 @@ getSpirvLinkageTypeFor(const SPIRVSubtarget &ST, const GlobalValue &GV) {
return SPIRV::LinkageType::Export;
}
+bool generateIntegerDotExpansion(MachineIRBuilder &MIRBuilder, Register ResVReg,
+ Register Vec0, Register Vec1,
+ SPIRVGlobalRegistry *GR) {
+ // Expand integer dot product to element-wise multiply and sum:
+ // dot(a, b) = a[0]*b[0] + a[1]*b[1] + ... + a[n-1]*b[n-1]
+ MachineRegisterInfo *MRI = MIRBuilder.getMRI();
+ SPIRVType *VecType = GR->getSPIRVTypeForVReg(Vec0);
+ SPIRVType *ResType = GR->getSPIRVTypeForVReg(ResVReg);
+
+ assert(VecType && VecType->getOpcode() == SPIRV::OpTypeVector &&
+ "Expected vector type for integer dot product");
+ unsigned NumComponents = GR->getScalarOrVectorComponentCount(VecType);
+ assert(NumComponents > 1 && "dot product requires vector of at least 2");
+
+ // Multiply the vectors element-wise.
+ Register TmpVec = MRI->createVirtualRegister(GR->getRegClass(VecType));
+ MIRBuilder.buildInstr(SPIRV::OpIMulV)
----------------
MrSidims wrote:
Yeah, also I think we should also be using unsigned arithmetic instructions for unsigned dot product. Code was a bit rewritten, but basically the logic is the same as it was for spv.dot intrinsics expansion (code on the left). Let me put a TODO and fix this in a sperate patch.
https://github.com/llvm/llvm-project/pull/177258
More information about the llvm-commits
mailing list