Skip to content

Commit eac58d8

Browse files
committed
[X86] Promote several single precision FP libcalls on Windows
A number of libcalls don't exist in any particular lib but are, instead, defined in math.h as inline functions (even in C mode!). Don't rely on their existence when lowering @llvm.{cos,sin,floor,..}.f32, promote them instead. N.B. We had logic to handle FREM but were missing out on a number of others. This change generalizes the FREM handling. llvm-svn: 268875
1 parent 81296fb commit eac58d8

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

‎llvm/lib/Analysis/TargetLibraryInfo.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
205205
TLI.setUnavailable(LibFunc::fmaxf);
206206
TLI.setUnavailable(LibFunc::fmodf);
207207
TLI.setUnavailable(LibFunc::logf);
208+
TLI.setUnavailable(LibFunc::log10f);
209+
TLI.setUnavailable(LibFunc::modff);
208210
TLI.setUnavailable(LibFunc::powf);
209211
TLI.setUnavailable(LibFunc::sinf);
210212
TLI.setUnavailable(LibFunc::sinhf);

‎llvm/lib/Target/X86/X86ISelLowering.cpp‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -308,16 +308,7 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
308308
setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1 , Expand);
309309
setOperationAction(ISD::FP_ROUND_INREG , MVT::f32 , Expand);
310310

311-
if (Subtarget.is32Bit() && Subtarget.isTargetKnownWindowsMSVC()) {
312-
// On 32 bit MSVC, `fmodf(f32)` is not defined - only `fmod(f64)`
313-
// is. We should promote the value to 64-bits to solve this.
314-
// This is what the CRT headers do - `fmodf` is an inline header
315-
// function casting to f64 and calling `fmod`.
316-
setOperationAction(ISD::FREM , MVT::f32 , Promote);
317-
} else {
318-
setOperationAction(ISD::FREM , MVT::f32 , Expand);
319-
}
320-
311+
setOperationAction(ISD::FREM , MVT::f32 , Expand);
321312
setOperationAction(ISD::FREM , MVT::f64 , Expand);
322313
setOperationAction(ISD::FREM , MVT::f80 , Expand);
323314
setOperationAction(ISD::FLT_ROUNDS_ , MVT::i32 , Custom);
@@ -1585,6 +1576,17 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
15851576
setOperationAction(ISD::UDIVREM, MVT::i128, Custom);
15861577
}
15871578

1579+
// On 32 bit MSVC, `fmodf(f32)` is not defined - only `fmod(f64)`
1580+
// is. We should promote the value to 64-bits to solve this.
1581+
// This is what the CRT headers do - `fmodf` is an inline header
1582+
// function casting to f64 and calling `fmod`.
1583+
if (Subtarget.is32Bit() && Subtarget.isTargetKnownWindowsMSVC())
1584+
for (ISD::NodeType Op :
1585+
{ISD::FCEIL, ISD::FCOS, ISD::FEXP, ISD::FFLOOR, ISD::FREM, ISD::FLOG,
1586+
ISD::FLOG10, ISD::FPOW, ISD::FSIN})
1587+
if (isOperationExpand(Op, MVT::f32))
1588+
setOperationAction(Op, MVT::f32, Promote);
1589+
15881590
// We have target-specific dag combine patterns for the following nodes:
15891591
setTargetDAGCombine(ISD::VECTOR_SHUFFLE);
15901592
setTargetDAGCombine(ISD::EXTRACT_VECTOR_ELT);

0 commit comments

Comments
 (0)