[clang] [llvm] [HLSL] Implement support for HLSL intrinsic - saturate (PR #104619)
Farzon Lotfi via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 19 12:48:49 PDT 2024
================
@@ -0,0 +1,69 @@
+; RUN: opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
+; Make sure the intrinsic dx.saturate is to appropriate DXIL op for half/float/double data types.
+
+target datalayout = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64"
+target triple = "dxilv1.6-unknown-shadermodel6.6-library"
+
+; CHECK-LABEL: test_saturate_half
+define noundef half @test_saturate_half(half noundef %p0) #0 {
+entry:
+ %p0.addr = alloca half, align 2
+ store half %p0, ptr %p0.addr, align 2, !tbaa !4
+ %0 = load half, ptr %p0.addr, align 2, !tbaa !4
+ ; CHECK: %1 = call half @dx.op.unary.f16(i32 7, half %0)
+ %hlsl.saturate = call half @llvm.dx.saturate.f16(half %0)
+ ; CHECK: ret half %1
+ ret half %hlsl.saturate
+}
+
+; Function Attrs: nocallback nofree nosync nounwind willreturn
+declare half @llvm.dx.saturate.f16(half) #1
+
+; CHECK-LABEL: test_saturate_float
+define noundef float @test_saturate_float(float noundef %p0) #0 {
+entry:
+ %p0.addr = alloca float, align 4
+ store float %p0, ptr %p0.addr, align 4, !tbaa !9
+ %0 = load float, ptr %p0.addr, align 4, !tbaa !9
+ ; CHECK: %1 = call float @dx.op.unary.f32(i32 7, float %0)
+ %hlsl.saturate = call float @llvm.dx.saturate.f32(float %0)
+ ; CHECK: ret float %1
+ ret float %hlsl.saturate
+}
+
+; Function Attrs: nocallback nofree nosync nounwind willreturn
+declare float @llvm.dx.saturate.f32(float) #1
+
+; CHECK-LABEL: test_saturate_double
+define noundef double @test_saturate_double(double noundef %p0) #0 {
+entry:
+ %p0.addr = alloca double, align 8
+ store double %p0, ptr %p0.addr, align 8, !tbaa !11
+ %0 = load double, ptr %p0.addr, align 8, !tbaa !11
+ ; CHECK: %1 = call double @dx.op.unary.f64(i32 7, double %0)
+ %hlsl.saturate = call double @llvm.dx.saturate.f64(double %0)
+ ; CHECK: ret double %1
+ ret double %hlsl.saturate
+}
+
+; Function Attrs: nocallback nofree nosync nounwind willreturn
+declare double @llvm.dx.saturate.f64(double) #1
+
+attributes #0 = { convergent nounwind "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
----------------
farzonl wrote:
delete lines 52-69?
https://github.com/llvm/llvm-project/pull/104619
More information about the cfe-commits
mailing list