diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp @@ -3093,6 +3093,9 @@ EVT NFPVT = TLI.getTypeToTransformTo(*DAG.getContext(), Op.getValueType()); Op = GetSoftPromotedHalf(Op); Op = DAG.getNode(ISD::FP16_TO_FP, dl, NFPVT, Op); + Op = DAG.getNode(ISD::FP_TO_SINT, dl, VT, Op); + SplitInteger(Op, Lo, Hi); + return; } RTLIB::Libcall LC = RTLIB::getFPTOSINT(Op.getValueType(), VT); @@ -3122,6 +3125,9 @@ EVT NFPVT = TLI.getTypeToTransformTo(*DAG.getContext(), Op.getValueType()); Op = GetSoftPromotedHalf(Op); Op = DAG.getNode(ISD::FP16_TO_FP, dl, NFPVT, Op); + Op = DAG.getNode(ISD::FP_TO_UINT, dl, VT, Op); + SplitInteger(Op, Lo, Hi); + return; } RTLIB::Libcall LC = RTLIB::getFPTOUINT(Op.getValueType(), VT); diff --git a/llvm/test/CodeGen/X86/half.ll b/llvm/test/CodeGen/X86/half.ll --- a/llvm/test/CodeGen/X86/half.ll +++ b/llvm/test/CodeGen/X86/half.ll @@ -210,14 +210,23 @@ ; ; CHECK-I686-LABEL: test_fptosi_i64: ; CHECK-I686: # %bb.0: -; CHECK-I686-NEXT: subl $12, %esp +; CHECK-I686-NEXT: subl $28, %esp ; CHECK-I686-NEXT: movl {{[0-9]+}}(%esp), %eax ; CHECK-I686-NEXT: movzwl (%eax), %eax ; CHECK-I686-NEXT: movl %eax, (%esp) ; CHECK-I686-NEXT: calll __gnu_h2f_ieee -; CHECK-I686-NEXT: fstps (%esp) -; CHECK-I686-NEXT: calll __fixsfdi -; CHECK-I686-NEXT: addl $12, %esp +; CHECK-I686-NEXT: fstps {{[0-9]+}}(%esp) +; CHECK-I686-NEXT: flds {{[0-9]+}}(%esp) +; CHECK-I686-NEXT: fnstcw {{[0-9]+}}(%esp) +; CHECK-I686-NEXT: movzwl {{[0-9]+}}(%esp), %eax +; CHECK-I686-NEXT: orl $3072, %eax # imm = 0xC00 +; CHECK-I686-NEXT: movw %ax, {{[0-9]+}}(%esp) +; CHECK-I686-NEXT: fldcw {{[0-9]+}}(%esp) +; CHECK-I686-NEXT: fistpll {{[0-9]+}}(%esp) +; CHECK-I686-NEXT: fldcw {{[0-9]+}}(%esp) +; CHECK-I686-NEXT: movl {{[0-9]+}}(%esp), %eax +; CHECK-I686-NEXT: movl {{[0-9]+}}(%esp), %edx +; CHECK-I686-NEXT: addl $28, %esp ; CHECK-I686-NEXT: retl %a = load half, half* %p, align 2 %r = fptosi half %a to i64 @@ -295,14 +304,35 @@ ; ; CHECK-I686-LABEL: test_fptoui_i64: ; CHECK-I686: # %bb.0: -; CHECK-I686-NEXT: subl $12, %esp +; CHECK-I686-NEXT: subl $28, %esp ; CHECK-I686-NEXT: movl {{[0-9]+}}(%esp), %eax ; CHECK-I686-NEXT: movzwl (%eax), %eax ; CHECK-I686-NEXT: movl %eax, (%esp) ; CHECK-I686-NEXT: calll __gnu_h2f_ieee -; CHECK-I686-NEXT: fstps (%esp) -; CHECK-I686-NEXT: calll __fixunssfdi -; CHECK-I686-NEXT: addl $12, %esp +; CHECK-I686-NEXT: fstps {{[0-9]+}}(%esp) +; CHECK-I686-NEXT: movss {{.*#+}} xmm0 = mem[0],zero,zero,zero +; CHECK-I686-NEXT: movss {{.*#+}} xmm1 = mem[0],zero,zero,zero +; CHECK-I686-NEXT: ucomiss %xmm1, %xmm0 +; CHECK-I686-NEXT: jae .LBB9_2 +; CHECK-I686-NEXT: # %bb.1: +; CHECK-I686-NEXT: xorps %xmm1, %xmm1 +; CHECK-I686-NEXT: .LBB9_2: +; CHECK-I686-NEXT: subss %xmm1, %xmm0 +; CHECK-I686-NEXT: movss %xmm0, {{[0-9]+}}(%esp) +; CHECK-I686-NEXT: setae %al +; CHECK-I686-NEXT: flds {{[0-9]+}}(%esp) +; CHECK-I686-NEXT: fnstcw {{[0-9]+}}(%esp) +; CHECK-I686-NEXT: movzwl {{[0-9]+}}(%esp), %ecx +; CHECK-I686-NEXT: orl $3072, %ecx # imm = 0xC00 +; CHECK-I686-NEXT: movw %cx, {{[0-9]+}}(%esp) +; CHECK-I686-NEXT: fldcw {{[0-9]+}}(%esp) +; CHECK-I686-NEXT: fistpll {{[0-9]+}}(%esp) +; CHECK-I686-NEXT: fldcw {{[0-9]+}}(%esp) +; CHECK-I686-NEXT: movzbl %al, %edx +; CHECK-I686-NEXT: shll $31, %edx +; CHECK-I686-NEXT: xorl {{[0-9]+}}(%esp), %edx +; CHECK-I686-NEXT: movl {{[0-9]+}}(%esp), %eax +; CHECK-I686-NEXT: addl $28, %esp ; CHECK-I686-NEXT: retl %a = load half, half* %p, align 2 %r = fptoui half %a to i64