Skip to content

Commit ecd9e0b

Browse files
v01dXYZv01dxyz
and
v01dxyz
authored
[X86][LegalizeDAG] FPOWI: promote f16 operand (#105775)
Fixes #105747 --------- Co-authored-by: v01dxyz <[email protected]>
1 parent 37d0841 commit ecd9e0b

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
614614
setOperationAction(ISD::FTAN, VT, Action);
615615
setOperationAction(ISD::FSQRT, VT, Action);
616616
setOperationAction(ISD::FPOW, VT, Action);
617+
setOperationAction(ISD::FPOWI, VT, Action);
617618
setOperationAction(ISD::FLOG, VT, Action);
618619
setOperationAction(ISD::FLOG2, VT, Action);
619620
setOperationAction(ISD::FLOG10, VT, Action);

llvm/test/CodeGen/X86/fp16-libcalls.ll

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,77 @@ define void @test_half_pow(half %a0, half %a1, ptr %p0) nounwind {
926926
ret void
927927
}
928928

929+
define void @test_half_powi(half %a0, i32 %a1, ptr %p0) nounwind {
930+
; F16C-LABEL: test_half_powi:
931+
; F16C: # %bb.0:
932+
; F16C-NEXT: pushq %rbx
933+
; F16C-NEXT: movq %rsi, %rbx
934+
; F16C-NEXT: vpextrw $0, %xmm0, %eax
935+
; F16C-NEXT: vmovd %eax, %xmm0
936+
; F16C-NEXT: vcvtph2ps %xmm0, %xmm0
937+
; F16C-NEXT: callq __powisf2@PLT
938+
; F16C-NEXT: vcvtps2ph $4, %xmm0, %xmm0
939+
; F16C-NEXT: vmovd %xmm0, %eax
940+
; F16C-NEXT: movw %ax, (%rbx)
941+
; F16C-NEXT: popq %rbx
942+
; F16C-NEXT: retq
943+
;
944+
; FP16-LABEL: test_half_powi:
945+
; FP16: # %bb.0:
946+
; FP16-NEXT: pushq %rbx
947+
; FP16-NEXT: movq %rsi, %rbx
948+
; FP16-NEXT: vcvtsh2ss %xmm0, %xmm0, %xmm0
949+
; FP16-NEXT: callq __powisf2@PLT
950+
; FP16-NEXT: vcvtss2sh %xmm0, %xmm0, %xmm0
951+
; FP16-NEXT: vmovsh %xmm0, (%rbx)
952+
; FP16-NEXT: popq %rbx
953+
; FP16-NEXT: retq
954+
;
955+
; X64-LABEL: test_half_powi:
956+
; X64: # %bb.0:
957+
; X64-NEXT: pushq %rbp
958+
; X64-NEXT: pushq %rbx
959+
; X64-NEXT: pushq %rax
960+
; X64-NEXT: movq %rsi, %rbx
961+
; X64-NEXT: movl %edi, %ebp
962+
; X64-NEXT: callq __extendhfsf2@PLT
963+
; X64-NEXT: movl %ebp, %edi
964+
; X64-NEXT: callq __powisf2@PLT
965+
; X64-NEXT: callq __truncsfhf2@PLT
966+
; X64-NEXT: pextrw $0, %xmm0, %eax
967+
; X64-NEXT: movw %ax, (%rbx)
968+
; X64-NEXT: addq $8, %rsp
969+
; X64-NEXT: popq %rbx
970+
; X64-NEXT: popq %rbp
971+
; X64-NEXT: retq
972+
;
973+
; X86-LABEL: test_half_powi:
974+
; X86: # %bb.0:
975+
; X86-NEXT: pushl %edi
976+
; X86-NEXT: pushl %esi
977+
; X86-NEXT: subl $20, %esp
978+
; X86-NEXT: pinsrw $0, {{[0-9]+}}(%esp), %xmm0
979+
; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
980+
; X86-NEXT: movl {{[0-9]+}}(%esp), %edi
981+
; X86-NEXT: pextrw $0, %xmm0, %eax
982+
; X86-NEXT: movw %ax, (%esp)
983+
; X86-NEXT: calll __extendhfsf2
984+
; X86-NEXT: movl %edi, {{[0-9]+}}(%esp)
985+
; X86-NEXT: fstps (%esp)
986+
; X86-NEXT: calll __powisf2
987+
; X86-NEXT: fstps (%esp)
988+
; X86-NEXT: calll __truncsfhf2
989+
; X86-NEXT: pextrw $0, %xmm0, %eax
990+
; X86-NEXT: movw %ax, (%esi)
991+
; X86-NEXT: addl $20, %esp
992+
; X86-NEXT: popl %esi
993+
; X86-NEXT: popl %edi
994+
; X86-NEXT: retl
995+
%res = call half @llvm.powi.half(half %a0, i32 %a1)
996+
store half %res, ptr %p0, align 2
997+
ret void
998+
}
999+
9291000
define void @test_half_rint(half %a0, ptr %p0) nounwind {
9301001
; F16C-LABEL: test_half_rint:
9311002
; F16C: # %bb.0:

0 commit comments

Comments
 (0)