[clang] [llvm] [HLSL][SPIRV] Added clamp intrinsic (PR #113394)
Farzon Lotfi via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 23 16:56:53 PDT 2024
================
@@ -18661,14 +18661,30 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
Value *OpMax = EmitScalarExpr(E->getArg(2));
QualType Ty = E->getArg(0)->getType();
- bool IsUnsigned = false;
if (auto *VecTy = Ty->getAs<VectorType>())
Ty = VecTy->getElementType();
- IsUnsigned = Ty->isUnsignedIntegerType();
- return Builder.CreateIntrinsic(
- /*ReturnType=*/OpX->getType(),
- IsUnsigned ? Intrinsic::dx_uclamp : Intrinsic::dx_clamp,
- ArrayRef<Value *>{OpX, OpMin, OpMax}, nullptr, "dx.clamp");
+ bool IsUnsigned = Ty->isUnsignedIntegerType();
+ switch (CGM.getTarget().getTriple().getArch()) {
+ case llvm::Triple::dxil: {
+ return Builder.CreateIntrinsic(
+ /*ReturnType=*/OpX->getType(),
+ IsUnsigned ? Intrinsic::dx_uclamp : Intrinsic::dx_clamp,
+ ArrayRef<Value *>{OpX, OpMin, OpMax}, nullptr, "dx.clamp");
+ } break;
+ case llvm::Triple::spirv: {
----------------
farzonl wrote:
The pattern we want to use is:
```cpp
return Builder.CreateIntrinsic(
/*ReturnType=*/OpX->getType(),
IsUnsigned ? CGM.getHLSLRuntime().getUClampntrinsic() : CGM.getHLSLRuntime().getSClampntrinsic(),
ArrayRef<Value *>{OpX, OpMin, OpMax}, nullptr, "hlsl.clamp");
```
https://github.com/llvm/llvm-project/pull/113394
More information about the cfe-commits
mailing list