[clang] [llvm] [HLSL] Implement the `fwidth` intrinsic for DXIL and SPIR-V target (PR #161378)

Farzon Lotfi via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 15 11:20:14 PDT 2025


================
@@ -2615,6 +2618,15 @@ bool SPIRVInstructionSelector::selectDiscard(Register ResVReg,
       .constrainAllUses(TII, TRI, RBI);
 }
 
+bool SPIRVInstructionSelector::selectFwidth(Register ResVReg,
+                                            const SPIRVType *ResType,
+                                            MachineInstr &I) const {
+  return BuildMI(*I.getParent(), I, I.getDebugLoc(), TII.get(SPIRV::OpFwidth))
+      .addDef(ResVReg)
+      .addUse(GR.getSPIRVTypeID(ResType))
+      .addUse(I.getOperand(2).getReg());
+}
+
----------------
farzonl wrote:

This doesn't seem special enough to need it's own selector function but I guess thats how we have been doing all the non ext opcodes like `SPIRV::OpFwidth`. Maybe we should create a generic Selector for the SPIRV Opcodes. So we don't have to do so many custom select functions when the only interesting part is `SPIRV::OpFwidth`. Something close to what we did for `selectExtInst`.

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


More information about the cfe-commits mailing list