Skip to content

Commit 061f4c0

Browse files
committed
[DirectX] Scalarize the dx.saturate intrinsic
The DXIL Saturate op only takes scalars. Fixes llvm#134378.
1 parent 77cfa38 commit 061f4c0

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

llvm/lib/Target/DirectX/DirectXTargetTransformInfo.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ bool DirectXTTIImpl::isTargetIntrinsicTriviallyScalarizable(
4444
case Intrinsic::dx_firstbituhigh:
4545
case Intrinsic::dx_frac:
4646
case Intrinsic::dx_rsqrt:
47+
case Intrinsic::dx_saturate:
4748
case Intrinsic::dx_splitdouble:
4849
case Intrinsic::dx_wave_readlane:
4950
case Intrinsic::dx_wave_reduce_max:

llvm/test/CodeGen/DirectX/saturate.ll

+31-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
1+
; RUN: opt -S -scalarizer -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
22
; Make sure the intrinsic dx.saturate is to appropriate DXIL op for half/float/double data types.
33

44
; CHECK-LABEL: test_saturate_half
@@ -28,9 +28,35 @@ entry:
2828
ret double %hlsl.saturate
2929
}
3030

31-
; CHECK: attributes #[[#ATTR]] = {{{.*}} memory(none) {{.*}}}
31+
; CHECK-LABEL: test_saturate_half4
32+
define noundef <4 x half> @test_saturate_half4(<4 x half> noundef %p0) {
33+
entry:
34+
; CHECK: call half @dx.op.unary.f16(i32 7, half
35+
; CHECK: call half @dx.op.unary.f16(i32 7, half
36+
; CHECK: call half @dx.op.unary.f16(i32 7, half
37+
; CHECK: call half @dx.op.unary.f16(i32 7, half
38+
%hlsl.saturate = call <4 x half> @llvm.dx.saturate.v4f16(<4 x half> %p0)
39+
ret <4 x half> %hlsl.saturate
40+
}
41+
42+
; CHECK-LABEL: test_saturate_float3
43+
define noundef <3 x float> @test_saturate_float3(<3 x float> noundef %p0) {
44+
entry:
45+
; CHECK: call float @dx.op.unary.f32(i32 7, float
46+
; CHECK: call float @dx.op.unary.f32(i32 7, float
47+
; CHECK: call float @dx.op.unary.f32(i32 7, float
48+
%hlsl.saturate = call <3 x float> @llvm.dx.saturate.v3f32(<3 x float> %p0)
49+
ret <3 x float> %hlsl.saturate
50+
}
3251

33-
declare half @llvm.dx.saturate.f16(half)
34-
declare float @llvm.dx.saturate.f32(float)
35-
declare double @llvm.dx.saturate.f64(double)
52+
; CHECK-LABEL: test_saturate_double2
53+
define noundef <2 x double> @test_saturate_double2(<2 x double> noundef %p0) {
54+
entry:
55+
; CHECK: call double @dx.op.unary.f64(i32 7, double
56+
; CHECK: call double @dx.op.unary.f64(i32 7, double
57+
%hlsl.saturate = call <2 x double> @llvm.dx.saturate.v4f64(<2 x double> %p0)
58+
ret <2 x double> %hlsl.saturate
59+
}
3660

61+
62+
; CHECK: attributes #[[#ATTR]] = {{{.*}} memory(none) {{.*}}}

0 commit comments

Comments
 (0)