Skip to content

Commit dbbadfd

Browse files
authored
[SDAG][X86] Promote float FMODF to double on 32-bit Windows (#130636)
On 32-bit MSVC `modff` is not a defined symbol -- only `modf` (`modff` is an inline function). Promoting FMODF to double in this case ensures we end up calling `modf` -- matching the behaviour of the CRT headers.
1 parent 26ecf97 commit dbbadfd

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2634,7 +2634,9 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
26342634
ISD::FSIN, ISD::STRICT_FSIN,
26352635
ISD::FSINH, ISD::STRICT_FSINH,
26362636
ISD::FTAN, ISD::STRICT_FTAN,
2637-
ISD::FTANH, ISD::STRICT_FTANH})
2637+
ISD::FTANH, ISD::STRICT_FTANH,
2638+
// TODO: Add ISD:::STRICT_FMODF too once implemented.
2639+
ISD::FMODF})
26382640
if (isOperationExpand(Op, MVT::f32))
26392641
setOperationAction(Op, MVT::f32, Promote);
26402642
// clang-format on
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -mtriple=i386-pc-win32 < %s | FileCheck -check-prefix=WIN32 %s
3+
; RUN: llc -mtriple=x86_64-unknown-unknown < %s | FileCheck -check-prefixes=X64 %s
4+
5+
; On 32-bit windows this should be promoted to a call to modf (not modff).
6+
define { float, float } @test_modf_f32(float %a) {
7+
; WIN32-LABEL: test_modf_f32:
8+
; WIN32: # %bb.0:
9+
; WIN32-NEXT: pushl %ebp
10+
; WIN32-NEXT: movl %esp, %ebp
11+
; WIN32-NEXT: andl $-8, %esp
12+
; WIN32-NEXT: subl $32, %esp
13+
; WIN32-NEXT: leal {{[0-9]+}}(%esp), %eax
14+
; WIN32-NEXT: movl %eax, {{[0-9]+}}(%esp)
15+
; WIN32-NEXT: flds 8(%ebp)
16+
; WIN32-NEXT: fstpl (%esp)
17+
; WIN32-NEXT: calll _modf
18+
; WIN32-NEXT: fstps {{[0-9]+}}(%esp)
19+
; WIN32-NEXT: fldl {{[0-9]+}}(%esp)
20+
; WIN32-NEXT: fstps {{[0-9]+}}(%esp)
21+
; WIN32-NEXT: flds {{[0-9]+}}(%esp)
22+
; WIN32-NEXT: flds {{[0-9]+}}(%esp)
23+
; WIN32-NEXT: fxch %st(1)
24+
; WIN32-NEXT: movl %ebp, %esp
25+
; WIN32-NEXT: popl %ebp
26+
; WIN32-NEXT: retl
27+
;
28+
; X64-LABEL: test_modf_f32:
29+
; X64: # %bb.0:
30+
; X64-NEXT: pushq %rax
31+
; X64-NEXT: .cfi_def_cfa_offset 16
32+
; X64-NEXT: leaq {{[0-9]+}}(%rsp), %rdi
33+
; X64-NEXT: callq modff@PLT
34+
; X64-NEXT: movss {{.*#+}} xmm1 = mem[0],zero,zero,zero
35+
; X64-NEXT: popq %rax
36+
; X64-NEXT: .cfi_def_cfa_offset 8
37+
; X64-NEXT: retq
38+
%result = call { float, float } @llvm.modf.f32(float %a)
39+
ret { float, float } %result
40+
}

0 commit comments

Comments
 (0)