xref: /llvm-project/llvm/test/CodeGen/DirectX/trunc.ll (revision 011b618644113996e2c0a8e57db40f89d20878e3)
1c05e29bfSFarzon Lotfi; RUN: opt -S -scalarizer -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
262d6bebaSHelena Kotas
362d6bebaSHelena Kotas; Make sure dxil operation function calls for trunc are generated for float and half.
462d6bebaSHelena Kotas
562d6bebaSHelena Kotasdefine noundef float @trunc_float(float noundef %a) {
662d6bebaSHelena Kotasentry:
7*011b6186SFinn Plummer; CHECK:call float @dx.op.unary.f32(i32 29, float %{{.*}}) #[[#ATTR:]]
862d6bebaSHelena Kotas  %elt.trunc = call float @llvm.trunc.f32(float %a)
962d6bebaSHelena Kotas  ret float %elt.trunc
1062d6bebaSHelena Kotas}
1162d6bebaSHelena Kotas
1262d6bebaSHelena Kotasdefine noundef half @trunc_half(half noundef %a) {
1362d6bebaSHelena Kotasentry:
14*011b6186SFinn Plummer; CHECK:call half @dx.op.unary.f16(i32 29, half %{{.*}}) #[[#ATTR]]
1562d6bebaSHelena Kotas  %elt.trunc = call half @llvm.trunc.f16(half %a)
1662d6bebaSHelena Kotas  ret half %elt.trunc
1762d6bebaSHelena Kotas}
1862d6bebaSHelena Kotas
19c05e29bfSFarzon Lotfidefine noundef <4 x float> @trunc_float4(<4 x float> noundef %a) #0 {
20c05e29bfSFarzon Lotfientry:
21c05e29bfSFarzon Lotfi  ; CHECK: [[ee0:%.*]] = extractelement <4 x float> %a, i64 0
22*011b6186SFinn Plummer  ; CHECK: [[ie0:%.*]] = call float @dx.op.unary.f32(i32 29, float [[ee0]]) #[[#ATTR]]
23c05e29bfSFarzon Lotfi  ; CHECK: [[ee1:%.*]] = extractelement <4 x float> %a, i64 1
24*011b6186SFinn Plummer  ; CHECK: [[ie1:%.*]] = call float @dx.op.unary.f32(i32 29, float [[ee1]]) #[[#ATTR]]
25c05e29bfSFarzon Lotfi  ; CHECK: [[ee2:%.*]] = extractelement <4 x float> %a, i64 2
26*011b6186SFinn Plummer  ; CHECK: [[ie2:%.*]] = call float @dx.op.unary.f32(i32 29, float [[ee2]]) #[[#ATTR]]
27c05e29bfSFarzon Lotfi  ; CHECK: [[ee3:%.*]] = extractelement <4 x float> %a, i64 3
28*011b6186SFinn Plummer  ; CHECK: [[ie3:%.*]] = call float @dx.op.unary.f32(i32 29, float [[ee3]]) #[[#ATTR]]
29c05e29bfSFarzon Lotfi  ; CHECK: insertelement <4 x float> poison, float [[ie0]], i64 0
30c05e29bfSFarzon Lotfi  ; CHECK: insertelement <4 x float> %{{.*}}, float [[ie1]], i64 1
31c05e29bfSFarzon Lotfi  ; CHECK: insertelement <4 x float> %{{.*}}, float [[ie2]], i64 2
32c05e29bfSFarzon Lotfi  ; CHECK: insertelement <4 x float> %{{.*}}, float [[ie3]], i64 3
33c05e29bfSFarzon Lotfi  %2 = call <4 x float> @llvm.trunc.v4f32(<4 x float> %a)
34c05e29bfSFarzon Lotfi  ret <4 x float> %2
35c05e29bfSFarzon Lotfi}
36c05e29bfSFarzon Lotfi
37*011b6186SFinn Plummer; CHECK: attributes #[[#ATTR]] = {{{.*}} memory(none) {{.*}}}
38*011b6186SFinn Plummer
3962d6bebaSHelena Kotasdeclare half @llvm.trunc.f16(half)
4062d6bebaSHelena Kotasdeclare float @llvm.trunc.f32(float)
41c05e29bfSFarzon Lotfideclare <4 x float> @llvm.trunc.v4f32(<4 x float>)
42