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

Farzon Lotfi via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 19 05:04:45 PST 2025


================
@@ -3584,10 +3583,13 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register ResVReg,
     return selectExtInst(ResVReg, ResType, I, GL::UnpackHalf2x16);
   }
   case Intrinsic::spv_ddx_coarse: {
-    return selectDpdCoarse(ResVReg, ResType, I, SPIRV::OpDPdxCoarse);
+    return selectDerivativeInst(ResVReg, ResType, I, SPIRV::OpDPdxCoarse);
   }
   case Intrinsic::spv_ddy_coarse: {
-    return selectDpdCoarse(ResVReg, ResType, I, SPIRV::OpDPdyCoarse);
+    return selectDerivativeInst(ResVReg, ResType, I, SPIRV::OpDPdyCoarse);
+  }
+  case Intrinsic::spv_fwidth: {
+    return selectDerivativeInst(ResVReg, ResType, I, SPIRV::OpFwidth);
----------------
farzonl wrote:

This file is not very consistent but some of these single return case statements don't have curly braces `{}`. This might be an ambigous part of the style guide: https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements. I do beleive this counts as a single statement body so if possible drop the curly braces.

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


More information about the llvm-commits mailing list