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

Alexander Johnston via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 19 04:42:21 PST 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());
+}
+
----------------
Alexander-Johnston wrote:

Renamed the selector for the DpdCoarse insts to `selectDerivativeInst` and sent the fwidth to it as well, as they all have the same pattern and require conversion to and from float when they are used with a half. This rule follows for all the other derivative instructions so far as I can tell.

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


More information about the llvm-commits mailing list