xref: /llvm-project/llvm/test/CodeGen/DirectX/normalize.ll (revision b55c52c047a167f42abbde9a33356cfb96b82c7f)
11b2d11deSJoshua Batista; RUN: opt -S  -dxil-intrinsic-expansion  < %s | FileCheck %s --check-prefixes=CHECK,EXPCHECK
2*7d0ca601SFarzon Lotfi; RUN: opt -S  -dxil-intrinsic-expansion -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library < %s | FileCheck %s --check-prefixes=CHECK,DOPCHECK
31b2d11deSJoshua Batista
41b2d11deSJoshua Batista; Make sure dxil operation function calls for normalize are generated for half/float.
51b2d11deSJoshua Batista
61b2d11deSJoshua Batistadeclare half @llvm.dx.normalize.f16(half)
71b2d11deSJoshua Batistadeclare <2 x half> @llvm.dx.normalize.v2f16(<2 x half>)
81b2d11deSJoshua Batistadeclare <3 x half> @llvm.dx.normalize.v3f16(<3 x half>)
91b2d11deSJoshua Batistadeclare <4 x half> @llvm.dx.normalize.v4f16(<4 x half>)
101b2d11deSJoshua Batista
111b2d11deSJoshua Batistadeclare float @llvm.dx.normalize.f32(float)
121b2d11deSJoshua Batistadeclare <2 x float> @llvm.dx.normalize.v2f32(<2 x float>)
131b2d11deSJoshua Batistadeclare <3 x float> @llvm.dx.normalize.v3f32(<3 x float>)
141b2d11deSJoshua Batistadeclare <4 x float> @llvm.dx.normalize.v4f32(<4 x float>)
151b2d11deSJoshua Batista
161b2d11deSJoshua Batistadefine noundef half @test_normalize_half(half noundef %p0) {
171b2d11deSJoshua Batistaentry:
181b2d11deSJoshua Batista  ; CHECK: fdiv half %p0, %p0
191b2d11deSJoshua Batista  %hlsl.normalize = call half @llvm.dx.normalize.f16(half %p0)
201b2d11deSJoshua Batista  ret half %hlsl.normalize
211b2d11deSJoshua Batista}
221b2d11deSJoshua Batista
231b2d11deSJoshua Batistadefine noundef <2 x half> @test_normalize_half2(<2 x half> noundef %p0) {
241b2d11deSJoshua Batistaentry:
251b2d11deSJoshua Batista  ; EXPCHECK: [[doth2:%.*]] = call half @llvm.dx.dot2.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}})
261b2d11deSJoshua Batista  ; DOPCHECK: [[doth2:%.*]] = call half @dx.op.dot2.f16(i32 54, half %{{.*}}, half %{{.*}}, half %{{.*}}, half %{{.*}})
271b2d11deSJoshua Batista  ; EXPCHECK: [[rsqrt:%.*]] = call half @llvm.dx.rsqrt.f16(half [[doth2]])
281b2d11deSJoshua Batista  ; DOPCHECK: [[rsqrt:%.*]] = call half @dx.op.unary.f16(i32 25, half [[doth2]])
291b2d11deSJoshua Batista  ; CHECK: [[splatinserth2:%.*]] = insertelement <2 x half> poison, half [[rsqrt]], i64 0
301b2d11deSJoshua Batista  ; CHECK: [[splat:%.*]] = shufflevector <2 x half> [[splatinserth2]], <2 x half> poison, <2 x i32> zeroinitializer
311b2d11deSJoshua Batista  ; CHECK: fmul <2 x half> %p0, [[splat]]
321b2d11deSJoshua Batista
331b2d11deSJoshua Batista  %hlsl.normalize = call <2 x half> @llvm.dx.normalize.v2f16(<2 x half> %p0)
341b2d11deSJoshua Batista  ret <2 x half> %hlsl.normalize
351b2d11deSJoshua Batista}
361b2d11deSJoshua Batista
371b2d11deSJoshua Batistadefine noundef <3 x half> @test_normalize_half3(<3 x half> noundef %p0) {
381b2d11deSJoshua Batistaentry:
391b2d11deSJoshua Batista  ; EXPCHECK: [[doth3:%.*]] = call half @llvm.dx.dot3.v3f16(<3 x half> %{{.*}}, <3 x half> %{{.*}})
401b2d11deSJoshua Batista  ; DOPCHECK: [[doth3:%.*]] = call half @dx.op.dot3.f16(i32 55, half %{{.*}}, half %{{.*}}, half %{{.*}}, half %{{.*}})
411b2d11deSJoshua Batista  ; EXPCHECK: [[rsqrt:%.*]] = call half @llvm.dx.rsqrt.f16(half [[doth3]])
421b2d11deSJoshua Batista  ; DOPCHECK: [[rsqrt:%.*]] = call half @dx.op.unary.f16(i32 25, half [[doth3]])
431b2d11deSJoshua Batista  ; CHECK: [[splatinserth3:%.*]] = insertelement <3 x half> poison, half [[rsqrt]], i64 0
441b2d11deSJoshua Batista  ; CHECK: [[splat:%.*]] shufflevector <3 x half> [[splatinserth3]], <3 x half> poison, <3 x i32> zeroinitializer
451b2d11deSJoshua Batista  ; CHECK: fmul <3 x half> %p0, %.splat
461b2d11deSJoshua Batista
471b2d11deSJoshua Batista  %hlsl.normalize = call <3 x half> @llvm.dx.normalize.v3f16(<3 x half> %p0)
481b2d11deSJoshua Batista  ret <3 x half> %hlsl.normalize
491b2d11deSJoshua Batista}
501b2d11deSJoshua Batista
511b2d11deSJoshua Batistadefine noundef <4 x half> @test_normalize_half4(<4 x half> noundef %p0) {
521b2d11deSJoshua Batistaentry:
531b2d11deSJoshua Batista  ; EXPCHECK: [[doth4:%.*]] = call half @llvm.dx.dot4.v4f16(<4 x half> %{{.*}}, <4 x half> %{{.*}})
541b2d11deSJoshua Batista  ; DOPCHECK: [[doth4:%.*]] = call half @dx.op.dot4.f16(i32 56, half %{{.*}}, half %{{.*}}, half %{{.*}}, half %{{.*}})
551b2d11deSJoshua Batista  ; EXPCHECK: [[rsqrt:%.*]] = call half @llvm.dx.rsqrt.f16(half [[doth4]])
561b2d11deSJoshua Batista  ; DOPCHECK: [[rsqrt:%.*]] = call half @dx.op.unary.f16(i32 25, half [[doth4]])
571b2d11deSJoshua Batista  ; CHECK: [[splatinserth4:%.*]] = insertelement <4 x half> poison, half [[rsqrt]], i64 0
581b2d11deSJoshua Batista  ; CHECK: [[splat:%.*]] shufflevector <4 x half> [[splatinserth4]], <4 x half> poison, <4 x i32> zeroinitializer
591b2d11deSJoshua Batista  ; CHECK: fmul <4 x half> %p0, %.splat
601b2d11deSJoshua Batista
611b2d11deSJoshua Batista  %hlsl.normalize = call <4 x half> @llvm.dx.normalize.v4f16(<4 x half> %p0)
621b2d11deSJoshua Batista  ret <4 x half> %hlsl.normalize
631b2d11deSJoshua Batista}
641b2d11deSJoshua Batista
651b2d11deSJoshua Batistadefine noundef float @test_normalize_float(float noundef %p0) {
661b2d11deSJoshua Batistaentry:
671b2d11deSJoshua Batista  ; CHECK: fdiv float %p0, %p0
681b2d11deSJoshua Batista  %hlsl.normalize = call float @llvm.dx.normalize.f32(float %p0)
691b2d11deSJoshua Batista  ret float %hlsl.normalize
701b2d11deSJoshua Batista}
711b2d11deSJoshua Batista
721b2d11deSJoshua Batistadefine noundef <2 x float> @test_normalize_float2(<2 x float> noundef %p0) {
731b2d11deSJoshua Batistaentry:
741b2d11deSJoshua Batista  ; EXPCHECK: [[dotf2:%.*]] = call float @llvm.dx.dot2.v2f32(<2 x float> %{{.*}}, <2 x float> %{{.*}})
751b2d11deSJoshua Batista  ; DOPCHECK: [[dotf2:%.*]] = call float @dx.op.dot2.f32(i32 54, float %{{.*}}, float %{{.*}}, float %{{.*}}, float %{{.*}})
761b2d11deSJoshua Batista  ; EXPCHECK: [[rsqrt:%.*]] = call float @llvm.dx.rsqrt.f32(float [[dotf2]])
771b2d11deSJoshua Batista  ; DOPCHECK: [[rsqrt:%.*]] = call float @dx.op.unary.f32(i32 25, float [[dotf2]])
781b2d11deSJoshua Batista  ; CHECK: [[splatinsertf2:%.*]] = insertelement <2 x float> poison, float [[rsqrt]], i64 0
791b2d11deSJoshua Batista  ; CHECK: [[splat:%.*]] shufflevector <2 x float> [[splatinsertf2]], <2 x float> poison, <2 x i32> zeroinitializer
801b2d11deSJoshua Batista  ; CHECK: fmul <2 x float> %p0, %.splat
811b2d11deSJoshua Batista
821b2d11deSJoshua Batista  %hlsl.normalize = call <2 x float> @llvm.dx.normalize.v2f32(<2 x float> %p0)
831b2d11deSJoshua Batista  ret <2 x float> %hlsl.normalize
841b2d11deSJoshua Batista}
851b2d11deSJoshua Batista
861b2d11deSJoshua Batistadefine noundef <3 x float> @test_normalize_float3(<3 x float> noundef %p0) {
871b2d11deSJoshua Batistaentry:
881b2d11deSJoshua Batista  ; EXPCHECK: [[dotf3:%.*]] = call float @llvm.dx.dot3.v3f32(<3 x float> %{{.*}}, <3 x float> %{{.*}})
891b2d11deSJoshua Batista  ; DOPCHECK: [[dotf3:%.*]] = call float @dx.op.dot3.f32(i32 55, float %{{.*}}, float %{{.*}}, float %{{.*}}, float %{{.*}})
901b2d11deSJoshua Batista  ; EXPCHECK: [[rsqrt:%.*]] = call float @llvm.dx.rsqrt.f32(float [[dotf3]])
911b2d11deSJoshua Batista  ; DOPCHECK: [[rsqrt:%.*]] = call float @dx.op.unary.f32(i32 25, float [[dotf3]])
921b2d11deSJoshua Batista  ; CHECK: [[splatinsertf3:%.*]] = insertelement <3 x float> poison, float [[rsqrt]], i64 0
931b2d11deSJoshua Batista  ; CHECK: [[splat:%.*]] shufflevector <3 x float> [[splatinsertf3]], <3 x float> poison, <3 x i32> zeroinitializer
941b2d11deSJoshua Batista  ; CHECK: fmul <3 x float> %p0, %.splat
951b2d11deSJoshua Batista
961b2d11deSJoshua Batista  %hlsl.normalize = call <3 x float> @llvm.dx.normalize.v3f32(<3 x float> %p0)
971b2d11deSJoshua Batista  ret <3 x float> %hlsl.normalize
981b2d11deSJoshua Batista}
991b2d11deSJoshua Batista
1001b2d11deSJoshua Batistadefine noundef <4 x float> @test_normalize_float4(<4 x float> noundef %p0) {
1011b2d11deSJoshua Batistaentry:
1021b2d11deSJoshua Batista  ; EXPCHECK: [[dotf4:%.*]] = call float @llvm.dx.dot4.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}})
1031b2d11deSJoshua Batista  ; DOPCHECK: [[dotf4:%.*]] = call float @dx.op.dot4.f32(i32 56, float %{{.*}}, float %{{.*}}, float %{{.*}}, float %{{.*}})
1041b2d11deSJoshua Batista  ; EXPCHECK: [[rsqrt:%.*]] = call float @llvm.dx.rsqrt.f32(float [[dotf4]])
1051b2d11deSJoshua Batista  ; DOPCHECK: [[rsqrt:%.*]] = call float @dx.op.unary.f32(i32 25, float [[dotf4]])
1061b2d11deSJoshua Batista  ; CHECK: [[splatinsertf4:%.*]] = insertelement <4 x float> poison, float [[rsqrt]], i64 0
1071b2d11deSJoshua Batista  ; CHECK: [[splat:%.*]] shufflevector <4 x float> [[splatinsertf4]], <4 x float> poison, <4 x i32> zeroinitializer
1081b2d11deSJoshua Batista  ; CHECK: fmul <4 x float> %p0, %.splat
1091b2d11deSJoshua Batista
1101b2d11deSJoshua Batista  %hlsl.normalize = call <4 x float> @llvm.dx.normalize.v4f32(<4 x float> %p0)
1111b2d11deSJoshua Batista  ret <4 x float> %hlsl.normalize
1121b2d11deSJoshua Batista}
113