xref: /llvm-project/llvm/test/CodeGen/Hexagon/fp16.ll (revision 2208c97c1bec2512d4e47b6223db6d95a7037956)
1; RUN: llc -mtriple=hexagon < %s | FileCheck %s
2
3; This test validates the following facts for half-precision floating point
4; conversions.
5; Generate correct libcall names for conversion from fp16 to fp32.
6; (__extendhfsf2).
7;  The extension from fp16 to fp64 is implicitly handled by __extendhfsf2 and convert_sf2d.
8; (fp16->fp32->fp64).
9; Generate correcct libcall names for conversion from fp32/fp64 to fp16
10; (__truncsfhf2 and __truncdfhf2)
11; Verify that we generate loads and stores of halfword.
12
13; Validate that we generate correct lib calls to convert fp16
14
15;CHECK-LABEL: @test1
16;CHECK: call __extendhfsf2
17;CHECK: r0 = memuh
18define dso_local float @test1(ptr nocapture readonly %a) local_unnamed_addr #0 {
19entry:
20  %0 = load i16, ptr %a, align 2
21  %1 = tail call float @llvm.convert.from.fp16.f32(i16 %0)
22  ret float %1
23}
24
25;CHECK-LABEL: @test2
26;CHECK: call __extendhfsf2
27;CHECK: r0 = memuh
28;CHECK: convert_sf2d
29define dso_local double @test2(ptr nocapture readonly %a) local_unnamed_addr #0 {
30entry:
31  %0 = load i16, ptr %a, align 2
32  %1 = tail call double @llvm.convert.from.fp16.f64(i16 %0)
33  ret double %1
34}
35
36;CHECK-LABEL: @test3
37;CHECK: call __truncsfhf2
38;CHECK: memh{{.*}}= r0
39define dso_local void @test3(float %src, ptr nocapture %dst) local_unnamed_addr #0 {
40entry:
41  %0 = tail call i16 @llvm.convert.to.fp16.f32(float %src)
42  store i16 %0, ptr %dst, align 2
43  ret void
44}
45
46;CHECK-LABEL: @test4
47;CHECK: call __truncdfhf2
48;CHECK: memh{{.*}}= r0
49define dso_local void @test4(double %src, ptr nocapture %dst) local_unnamed_addr #0 {
50entry:
51  %0 = tail call i16 @llvm.convert.to.fp16.f64(double %src)
52  store i16 %0, ptr %dst, align 2
53  ret void
54}
55
56;CHECK-LABEL: @test5
57;CHECK: call __extendhfsf2
58;CHECK: call __extendhfsf2
59;CHECK: sfadd
60define dso_local float @test5(ptr nocapture readonly %a, ptr nocapture readonly %b) local_unnamed_addr #0 {
61entry:
62  %0 = load i16, ptr %a, align 2
63  %1 = tail call float @llvm.convert.from.fp16.f32(i16 %0)
64  %2 = load i16, ptr %b, align 2
65  %3 = tail call float @llvm.convert.from.fp16.f32(i16 %2)
66  %add = fadd float %1, %3
67  ret float %add
68}
69
70declare float @llvm.convert.from.fp16.f32(i16) #1
71declare double @llvm.convert.from.fp16.f64(i16) #1
72declare i16 @llvm.convert.to.fp16.f32(float) #1
73declare i16 @llvm.convert.to.fp16.f64(double) #1
74
75attributes #0 = { nounwind readonly }
76attributes #1 = { nounwind readnone }
77