xref: /llvm-project/llvm/test/CodeGen/DirectX/fabs.ll (revision c05e29bff036060f0811b887a92715104abdceb5)
1; RUN: opt -S -scalarizer -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
2
3; Make sure dxil operation function calls for abs are generated for float, half, and double.
4
5
6; CHECK-LABEL: fabs_half
7define noundef half @fabs_half(half noundef %a) {
8entry:
9  ; CHECK: call half @dx.op.unary.f16(i32 6, half %{{.*}})
10  %elt.abs = call half @llvm.fabs.f16(half %a)
11  ret half %elt.abs
12}
13
14; CHECK-LABEL: fabs_float
15define noundef float @fabs_float(float noundef %a) {
16entry:
17; CHECK: call float @dx.op.unary.f32(i32 6, float %{{.*}})
18  %elt.abs = call float @llvm.fabs.f32(float %a)
19  ret float %elt.abs
20}
21
22; CHECK-LABEL: fabs_double
23define noundef double @fabs_double(double noundef %a) {
24entry:
25; CHECK: call double @dx.op.unary.f64(i32 6, double %{{.*}})
26  %elt.abs = call double @llvm.fabs.f64(double %a)
27  ret double %elt.abs
28}
29
30; CHECK-LABEL: fabs_float4
31define noundef <4 x float> @fabs_float4(<4 x float> noundef %a) {
32entry:
33  ; CHECK: [[ee0:%.*]] = extractelement <4 x float> %a, i64 0
34  ; CHECK: [[ie0:%.*]] = call float @dx.op.unary.f32(i32 6, float [[ee0]])
35  ; CHECK: [[ee1:%.*]] = extractelement <4 x float> %a, i64 1
36  ; CHECK: [[ie1:%.*]] = call float @dx.op.unary.f32(i32 6, float [[ee1]])
37  ; CHECK: [[ee2:%.*]] = extractelement <4 x float> %a, i64 2
38  ; CHECK: [[ie2:%.*]] = call float @dx.op.unary.f32(i32 6, float [[ee2]])
39  ; CHECK: [[ee3:%.*]] = extractelement <4 x float> %a, i64 3
40  ; CHECK: [[ie3:%.*]] = call float @dx.op.unary.f32(i32 6, float [[ee3]])
41  ; CHECK: insertelement <4 x float> poison, float [[ie0]], i64 0
42  ; CHECK: insertelement <4 x float> %{{.*}}, float [[ie1]], i64 1
43  ; CHECK: insertelement <4 x float> %{{.*}}, float [[ie2]], i64 2
44  ; CHECK: insertelement <4 x float> %{{.*}}, float [[ie3]], i64 3
45  %2 = call <4 x float> @llvm.fabs.v4f32(<4 x float> %a)
46  ret <4 x float> %2
47}
48
49declare half @llvm.fabs.f16(half)
50declare float @llvm.fabs.f32(float)
51declare double @llvm.fabs.f64(double)
52declare <4 x float> @llvm.fabs.v4f32(<4 x float>)
53