[clang] [llvm] [HLSL][SPIRV] Added clamp intrinsic (PR #113394)

Farzon Lotfi via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 23 17:00:50 PDT 2024


================
@@ -2559,6 +2559,12 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register ResVReg,
   } break;
   case Intrinsic::spv_saturate:
     return selectSaturate(ResVReg, ResType, I);
+  case Intrinsic::spv_fclamp:
+    return selectExtInst(ResVReg, ResType, I, CL::fclamp, GL::FClamp);
----------------
farzonl wrote:

I don't beleive fclamp is correct for HLSL. I beleive HLSL uses NClamp since max and min are NMin and NMax.  
We had to fix a bug like this in the past.
https://github.com/llvm/llvm-project/issues/87072

Either we make a spv_nclamp and use that in CGBuiltins.cpp or we just change this line to:
```suggestion
    return selectExtInst(ResVReg, ResType, I, CL::nclamp, GL::NClamp);
```

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


More information about the cfe-commits mailing list