Andrea Di Biagio | a37a2fc | 2014-07-03 21:51:06 +0000 | [diff] [blame] | 1 | ; RUN: llc < %s -march=x86-64 -mtriple=x86_64-unknown-linux-gnu -mcpu=corei7 -mattr=-f16c | FileCheck %s -check-prefix=CHECK -check-prefix=LIBCALL |
| 2 | ; RUN: llc < %s -march=x86-64 -mtriple=x86_64-unknown-linux-gnu -mcpu=corei7 -mattr=+f16c | FileCheck %s -check-prefix=CHECK -check-prefix=F16C |
| 3 | ; RUN: llc < %s -march=x86-64 -mtriple=x86_64-unknown-linux-gnu -mcpu=corei7 -soft-float=1 -mattr=-f16c | FileCheck %s -check-prefix=CHECK -check-prefix=SOFTFLOAT |
| 4 | ; RUN: llc < %s -march=x86-64 -mtriple=x86_64-unknown-linux-gnu -mcpu=corei7 -soft-float=1 -mattr=+f16c | FileCheck %s -check-prefix=CHECK -check-prefix=SOFTFLOAT |
| 5 | |
| 6 | ; This is a test for float to half float conversions on x86-64. |
| 7 | ; |
| 8 | ; If flag -soft-float is set, or if there is no F16C support, then: |
| 9 | ; 1) half float to float conversions are |
| 10 | ; translated into calls to __gnu_h2f_ieee defined |
| 11 | ; by the compiler runtime library; |
| 12 | ; 2) float to half float conversions are translated into calls |
| 13 | ; to __gnu_f2h_ieee which expected to be defined by the |
| 14 | ; compiler runtime library. |
| 15 | ; |
| 16 | ; Otherwise (we have F16C support): |
| 17 | ; 1) half float to float conversion are translated using |
| 18 | ; vcvtph2ps instructions; |
| 19 | ; 2) float to half float conversions are translated using |
| 20 | ; vcvtps2ph instructions |
| 21 | |
| 22 | |
| 23 | define void @test1(float %src, i16* %dest) { |
Tim Northover | fd7e424 | 2014-07-17 10:51:23 +0000 | [diff] [blame] | 24 | %1 = tail call i16 @llvm.convert.to.fp16.f32(float %src) |
Andrea Di Biagio | a37a2fc | 2014-07-03 21:51:06 +0000 | [diff] [blame] | 25 | store i16 %1, i16* %dest, align 2 |
| 26 | ret void |
| 27 | } |
| 28 | ; CHECK-LABEL: test1 |
| 29 | ; LIBCALL: callq __gnu_f2h_ieee |
| 30 | ; SOFTFLOAT: callq __gnu_f2h_ieee |
| 31 | ; F16C: vcvtps2ph |
| 32 | ; CHECK: ret |
| 33 | |
| 34 | |
| 35 | define float @test2(i16* nocapture %src) { |
| 36 | %1 = load i16* %src, align 2 |
Tim Northover | fd7e424 | 2014-07-17 10:51:23 +0000 | [diff] [blame] | 37 | %2 = tail call float @llvm.convert.from.fp16.f32(i16 %1) |
Andrea Di Biagio | a37a2fc | 2014-07-03 21:51:06 +0000 | [diff] [blame] | 38 | ret float %2 |
| 39 | } |
| 40 | ; CHECK-LABEL: test2: |
| 41 | ; LIBCALL: jmp __gnu_h2f_ieee |
| 42 | ; SOFTFLOAT: callq __gnu_h2f_ieee |
| 43 | ; F16C: vcvtph2ps |
| 44 | ; F16C: ret |
| 45 | |
| 46 | |
| 47 | define float @test3(float %src) nounwind uwtable readnone { |
Tim Northover | fd7e424 | 2014-07-17 10:51:23 +0000 | [diff] [blame] | 48 | %1 = tail call i16 @llvm.convert.to.fp16.f32(float %src) |
| 49 | %2 = tail call float @llvm.convert.from.fp16.f32(i16 %1) |
Andrea Di Biagio | a37a2fc | 2014-07-03 21:51:06 +0000 | [diff] [blame] | 50 | ret float %2 |
| 51 | } |
| 52 | |
| 53 | ; CHECK-LABEL: test3: |
| 54 | ; LIBCALL: callq __gnu_f2h_ieee |
| 55 | ; LIBCALL: jmp __gnu_h2f_ieee |
| 56 | ; SOFTFLOAT: callq __gnu_f2h_ieee |
| 57 | ; SOFTFLOAT: callq __gnu_h2f_ieee |
| 58 | ; F16C: vcvtps2ph |
| 59 | ; F16C-NEXT: vcvtph2ps |
| 60 | ; F16C: ret |
| 61 | |
Tim Northover | 2131044 | 2014-07-17 11:04:04 +0000 | [diff] [blame] | 62 | define double @test4(i16* nocapture %src) { |
| 63 | %1 = load i16* %src, align 2 |
| 64 | %2 = tail call double @llvm.convert.from.fp16.f64(i16 %1) |
| 65 | ret double %2 |
| 66 | } |
| 67 | ; CHECK-LABEL: test4: |
| 68 | ; LIBCALL: callq __gnu_h2f_ieee |
| 69 | ; LIBCALL: cvtss2sd |
| 70 | ; SOFTFLOAT: callq __gnu_h2f_ieee |
| 71 | ; SOFTFLOAT: callq __extendsfdf2 |
| 72 | ; F16C: vcvtph2ps |
| 73 | ; F16C: vcvtss2sd |
| 74 | ; F16C: ret |
| 75 | |
Tim Northover | 84ce0a6 | 2014-07-17 11:12:12 +0000 | [diff] [blame^] | 76 | |
| 77 | define i16 @test5(double %src) { |
| 78 | %val = tail call i16 @llvm.convert.to.fp16.f64(double %src) |
| 79 | ret i16 %val |
| 80 | } |
| 81 | ; CHECK-LABEL: test5: |
| 82 | ; LIBCALL: jmp __truncdfhf2 |
| 83 | ; SOFTFLOAT: callq __truncdfhf2 |
| 84 | ; F16C: jmp __truncdfhf2 |
| 85 | |
Tim Northover | fd7e424 | 2014-07-17 10:51:23 +0000 | [diff] [blame] | 86 | declare float @llvm.convert.from.fp16.f32(i16) nounwind readnone |
| 87 | declare i16 @llvm.convert.to.fp16.f32(float) nounwind readnone |
Tim Northover | 2131044 | 2014-07-17 11:04:04 +0000 | [diff] [blame] | 88 | declare double @llvm.convert.from.fp16.f64(i16) nounwind readnone |
Tim Northover | 84ce0a6 | 2014-07-17 11:12:12 +0000 | [diff] [blame^] | 89 | declare i16 @llvm.convert.to.fp16.f64(double) nounwind readnone |