1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=instsimplify -S < %s | FileCheck %s
4 ; Verify that we don't crash with an assertion failure when constant folding
5 ; a call to intrinsic 'convert.from.fp16' if the return type is not 'float'.
7 define float @fold_from_fp16_to_fp32() {
8 ; CHECK-LABEL: @fold_from_fp16_to_fp32(
9 ; CHECK-NEXT: ret float 0.000000e+00
11 %r = call float @llvm.convert.from.fp16.f32(i16 0)
15 define double @fold_from_fp16_to_fp64() {
16 ; CHECK-LABEL: @fold_from_fp16_to_fp64(
17 ; CHECK-NEXT: ret double 0.000000e+00
19 %r = call double @llvm.convert.from.fp16.f64(i16 0)
23 define x86_fp80 @fold_from_fp16_to_fp80() {
24 ; CHECK-LABEL: @fold_from_fp16_to_fp80(
25 ; CHECK-NEXT: ret x86_fp80 0xK00000000000000000000
27 %r = call x86_fp80 @llvm.convert.from.fp16.f80(i16 0)
31 define fp128 @fold_from_fp16_to_fp128() {
32 ; CHECK-LABEL: @fold_from_fp16_to_fp128(
33 ; CHECK-NEXT: ret fp128 0xL00000000000000000000000000000000
35 %r = call fp128 @llvm.convert.from.fp16.f128(i16 0)
39 define ppc_fp128 @fold_from_fp16_to_ppcfp128() {
40 ; CHECK-LABEL: @fold_from_fp16_to_ppcfp128(
41 ; CHECK-NEXT: ret ppc_fp128 0xM00000000000000000000000000000000
43 %r = call ppc_fp128 @llvm.convert.from.fp16.ppcf128(i16 0)
47 define float @fold_from_fp16_to_fp32_b() {
48 ; CHECK-LABEL: @fold_from_fp16_to_fp32_b(
49 ; CHECK-NEXT: ret float 4.000000e+00
51 %a = call i16 @llvm.convert.to.fp16.f64(double 4.0)
52 %r = call float @llvm.convert.from.fp16.f32(i16 %a)
56 define double @fold_from_fp16_to_fp64_b() {
57 ; CHECK-LABEL: @fold_from_fp16_to_fp64_b(
58 ; CHECK-NEXT: ret double 4.000000e+00
60 %a = call i16 @llvm.convert.to.fp16.f64(double 4.0)
61 %r = call double @llvm.convert.from.fp16.f64(i16 %a)
65 define x86_fp80 @fold_from_fp16_to_fp80_b() {
66 ; CHECK-LABEL: @fold_from_fp16_to_fp80_b(
67 ; CHECK-NEXT: ret x86_fp80 0xK40018000000000000000
69 %a = call i16 @llvm.convert.to.fp16.f64(double 4.0)
70 %r = call x86_fp80 @llvm.convert.from.fp16.f80(i16 %a)
74 define fp128 @fold_from_fp16_to_fp128_b() {
75 ; CHECK-LABEL: @fold_from_fp16_to_fp128_b(
76 ; CHECK-NEXT: ret fp128 0xL00000000000000004001000000000000
78 %a = call i16 @llvm.convert.to.fp16.f64(double 4.0)
79 %r = call fp128 @llvm.convert.from.fp16.f128(i16 %a)
83 define ppc_fp128 @fold_from_fp16_to_ppcfp128_b() {
84 ; CHECK-LABEL: @fold_from_fp16_to_ppcfp128_b(
85 ; CHECK-NEXT: ret ppc_fp128 0xM40100000000000000000000000000000
87 %a = call i16 @llvm.convert.to.fp16.f64(double 4.0)
88 %r = call ppc_fp128 @llvm.convert.from.fp16.ppcf128(i16 %a)
92 ; This would assert because converting SNAN causes an invalidOp status.
95 define float @convert_snan() {
96 ; CHECK-LABEL: @convert_snan(
97 ; CHECK-NEXT: ret float 0x7FF8040000000000
99 %r = call float @llvm.convert.from.fp16.f32(i16 31745) ; 0x7c01
103 declare i16 @llvm.convert.to.fp16.f64(double)
104 declare float @llvm.convert.from.fp16.f32(i16)
105 declare double @llvm.convert.from.fp16.f64(i16)
106 declare x86_fp80 @llvm.convert.from.fp16.f80(i16)
107 declare fp128 @llvm.convert.from.fp16.f128(i16)
108 declare ppc_fp128 @llvm.convert.from.fp16.ppcf128(i16)