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