xref: /llvm-project/llvm/test/CodeGen/DirectX/normalize.ll (revision b55c52c047a167f42abbde9a33356cfb96b82c7f)
1; RUN: opt -S  -dxil-intrinsic-expansion  < %s | FileCheck %s --check-prefixes=CHECK,EXPCHECK
2; RUN: opt -S  -dxil-intrinsic-expansion -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library < %s | FileCheck %s --check-prefixes=CHECK,DOPCHECK
3
4; Make sure dxil operation function calls for normalize are generated for half/float.
5
6declare half @llvm.dx.normalize.f16(half)
7declare <2 x half> @llvm.dx.normalize.v2f16(<2 x half>)
8declare <3 x half> @llvm.dx.normalize.v3f16(<3 x half>)
9declare <4 x half> @llvm.dx.normalize.v4f16(<4 x half>)
10
11declare float @llvm.dx.normalize.f32(float)
12declare <2 x float> @llvm.dx.normalize.v2f32(<2 x float>)
13declare <3 x float> @llvm.dx.normalize.v3f32(<3 x float>)
14declare <4 x float> @llvm.dx.normalize.v4f32(<4 x float>)
15
16define noundef half @test_normalize_half(half noundef %p0) {
17entry:
18  ; CHECK: fdiv half %p0, %p0
19  %hlsl.normalize = call half @llvm.dx.normalize.f16(half %p0)
20  ret half %hlsl.normalize
21}
22
23define noundef <2 x half> @test_normalize_half2(<2 x half> noundef %p0) {
24entry:
25  ; EXPCHECK: [[doth2:%.*]] = call half @llvm.dx.dot2.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}})
26  ; DOPCHECK: [[doth2:%.*]] = call half @dx.op.dot2.f16(i32 54, half %{{.*}}, half %{{.*}}, half %{{.*}}, half %{{.*}})
27  ; EXPCHECK: [[rsqrt:%.*]] = call half @llvm.dx.rsqrt.f16(half [[doth2]])
28  ; DOPCHECK: [[rsqrt:%.*]] = call half @dx.op.unary.f16(i32 25, half [[doth2]])
29  ; CHECK: [[splatinserth2:%.*]] = insertelement <2 x half> poison, half [[rsqrt]], i64 0
30  ; CHECK: [[splat:%.*]] = shufflevector <2 x half> [[splatinserth2]], <2 x half> poison, <2 x i32> zeroinitializer
31  ; CHECK: fmul <2 x half> %p0, [[splat]]
32
33  %hlsl.normalize = call <2 x half> @llvm.dx.normalize.v2f16(<2 x half> %p0)
34  ret <2 x half> %hlsl.normalize
35}
36
37define noundef <3 x half> @test_normalize_half3(<3 x half> noundef %p0) {
38entry:
39  ; EXPCHECK: [[doth3:%.*]] = call half @llvm.dx.dot3.v3f16(<3 x half> %{{.*}}, <3 x half> %{{.*}})
40  ; DOPCHECK: [[doth3:%.*]] = call half @dx.op.dot3.f16(i32 55, half %{{.*}}, half %{{.*}}, half %{{.*}}, half %{{.*}})
41  ; EXPCHECK: [[rsqrt:%.*]] = call half @llvm.dx.rsqrt.f16(half [[doth3]])
42  ; DOPCHECK: [[rsqrt:%.*]] = call half @dx.op.unary.f16(i32 25, half [[doth3]])
43  ; CHECK: [[splatinserth3:%.*]] = insertelement <3 x half> poison, half [[rsqrt]], i64 0
44  ; CHECK: [[splat:%.*]] shufflevector <3 x half> [[splatinserth3]], <3 x half> poison, <3 x i32> zeroinitializer
45  ; CHECK: fmul <3 x half> %p0, %.splat
46
47  %hlsl.normalize = call <3 x half> @llvm.dx.normalize.v3f16(<3 x half> %p0)
48  ret <3 x half> %hlsl.normalize
49}
50
51define noundef <4 x half> @test_normalize_half4(<4 x half> noundef %p0) {
52entry:
53  ; EXPCHECK: [[doth4:%.*]] = call half @llvm.dx.dot4.v4f16(<4 x half> %{{.*}}, <4 x half> %{{.*}})
54  ; DOPCHECK: [[doth4:%.*]] = call half @dx.op.dot4.f16(i32 56, half %{{.*}}, half %{{.*}}, half %{{.*}}, half %{{.*}})
55  ; EXPCHECK: [[rsqrt:%.*]] = call half @llvm.dx.rsqrt.f16(half [[doth4]])
56  ; DOPCHECK: [[rsqrt:%.*]] = call half @dx.op.unary.f16(i32 25, half [[doth4]])
57  ; CHECK: [[splatinserth4:%.*]] = insertelement <4 x half> poison, half [[rsqrt]], i64 0
58  ; CHECK: [[splat:%.*]] shufflevector <4 x half> [[splatinserth4]], <4 x half> poison, <4 x i32> zeroinitializer
59  ; CHECK: fmul <4 x half> %p0, %.splat
60
61  %hlsl.normalize = call <4 x half> @llvm.dx.normalize.v4f16(<4 x half> %p0)
62  ret <4 x half> %hlsl.normalize
63}
64
65define noundef float @test_normalize_float(float noundef %p0) {
66entry:
67  ; CHECK: fdiv float %p0, %p0
68  %hlsl.normalize = call float @llvm.dx.normalize.f32(float %p0)
69  ret float %hlsl.normalize
70}
71
72define noundef <2 x float> @test_normalize_float2(<2 x float> noundef %p0) {
73entry:
74  ; EXPCHECK: [[dotf2:%.*]] = call float @llvm.dx.dot2.v2f32(<2 x float> %{{.*}}, <2 x float> %{{.*}})
75  ; DOPCHECK: [[dotf2:%.*]] = call float @dx.op.dot2.f32(i32 54, float %{{.*}}, float %{{.*}}, float %{{.*}}, float %{{.*}})
76  ; EXPCHECK: [[rsqrt:%.*]] = call float @llvm.dx.rsqrt.f32(float [[dotf2]])
77  ; DOPCHECK: [[rsqrt:%.*]] = call float @dx.op.unary.f32(i32 25, float [[dotf2]])
78  ; CHECK: [[splatinsertf2:%.*]] = insertelement <2 x float> poison, float [[rsqrt]], i64 0
79  ; CHECK: [[splat:%.*]] shufflevector <2 x float> [[splatinsertf2]], <2 x float> poison, <2 x i32> zeroinitializer
80  ; CHECK: fmul <2 x float> %p0, %.splat
81
82  %hlsl.normalize = call <2 x float> @llvm.dx.normalize.v2f32(<2 x float> %p0)
83  ret <2 x float> %hlsl.normalize
84}
85
86define noundef <3 x float> @test_normalize_float3(<3 x float> noundef %p0) {
87entry:
88  ; EXPCHECK: [[dotf3:%.*]] = call float @llvm.dx.dot3.v3f32(<3 x float> %{{.*}}, <3 x float> %{{.*}})
89  ; DOPCHECK: [[dotf3:%.*]] = call float @dx.op.dot3.f32(i32 55, float %{{.*}}, float %{{.*}}, float %{{.*}}, float %{{.*}})
90  ; EXPCHECK: [[rsqrt:%.*]] = call float @llvm.dx.rsqrt.f32(float [[dotf3]])
91  ; DOPCHECK: [[rsqrt:%.*]] = call float @dx.op.unary.f32(i32 25, float [[dotf3]])
92  ; CHECK: [[splatinsertf3:%.*]] = insertelement <3 x float> poison, float [[rsqrt]], i64 0
93  ; CHECK: [[splat:%.*]] shufflevector <3 x float> [[splatinsertf3]], <3 x float> poison, <3 x i32> zeroinitializer
94  ; CHECK: fmul <3 x float> %p0, %.splat
95
96  %hlsl.normalize = call <3 x float> @llvm.dx.normalize.v3f32(<3 x float> %p0)
97  ret <3 x float> %hlsl.normalize
98}
99
100define noundef <4 x float> @test_normalize_float4(<4 x float> noundef %p0) {
101entry:
102  ; EXPCHECK: [[dotf4:%.*]] = call float @llvm.dx.dot4.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}})
103  ; DOPCHECK: [[dotf4:%.*]] = call float @dx.op.dot4.f32(i32 56, float %{{.*}}, float %{{.*}}, float %{{.*}}, float %{{.*}})
104  ; EXPCHECK: [[rsqrt:%.*]] = call float @llvm.dx.rsqrt.f32(float [[dotf4]])
105  ; DOPCHECK: [[rsqrt:%.*]] = call float @dx.op.unary.f32(i32 25, float [[dotf4]])
106  ; CHECK: [[splatinsertf4:%.*]] = insertelement <4 x float> poison, float [[rsqrt]], i64 0
107  ; CHECK: [[splat:%.*]] shufflevector <4 x float> [[splatinsertf4]], <4 x float> poison, <4 x i32> zeroinitializer
108  ; CHECK: fmul <4 x float> %p0, %.splat
109
110  %hlsl.normalize = call <4 x float> @llvm.dx.normalize.v4f32(<4 x float> %p0)
111  ret <4 x float> %hlsl.normalize
112}
113