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