Skip to content

Commit d1bfa9c

Browse files
committed
[llvm] Ensure that soft float targets don't emit fma() libcalls.
The previous behavior could be harmful in some edge cases, such as emitting a call to fma() in the fma() implementation itself. Do this by just being more accurate in isFMAFasterThanFMulAndFAdd(). This was already done for PowerPC; this commit just extends that to Arm, z/Arch, and x86. MIPS and SPARC already got it right, but I added tests for them too, for good measure.
1 parent 9614f69 commit d1bfa9c

File tree

9 files changed

+3742
-0
lines changed

9 files changed

+3742
-0
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3242,6 +3242,9 @@ class TargetLoweringBase {
32423242
/// not legal, but should return true if those types will eventually legalize
32433243
/// to types that support FMAs. After legalization, it will only be called on
32443244
/// types that support FMAs (via Legal or Custom actions)
3245+
///
3246+
/// Targets that care about soft float support should return false when soft
3247+
/// float code is being generated (i.e. use-soft-float).
32453248
virtual bool isFMAFasterThanFMulAndFAdd(const MachineFunction &MF,
32463249
EVT) const {
32473250
return false;

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19487,6 +19487,9 @@ bool ARMTargetLowering::allowTruncateForTailCall(Type *Ty1, Type *Ty2) const {
1948719487
/// patterns (and we don't have the non-fused floating point instruction).
1948819488
bool ARMTargetLowering::isFMAFasterThanFMulAndFAdd(const MachineFunction &MF,
1948919489
EVT VT) const {
19490+
if (Subtarget->useSoftFloat())
19491+
return false;
19492+
1949019493
if (!VT.isSimple())
1949119494
return false;
1949219495

llvm/lib/Target/SystemZ/SystemZISelLowering.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,9 @@ EVT SystemZTargetLowering::getSetCCResultType(const DataLayout &DL,
793793

794794
bool SystemZTargetLowering::isFMAFasterThanFMulAndFAdd(
795795
const MachineFunction &MF, EVT VT) const {
796+
if (useSoftFloat())
797+
return false;
798+
796799
VT = VT.getScalarType();
797800

798801
if (!VT.isSimple())

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34843,6 +34843,9 @@ bool X86TargetLowering::isVectorLoadExtDesirable(SDValue ExtVal) const {
3484334843

3484434844
bool X86TargetLowering::isFMAFasterThanFMulAndFAdd(const MachineFunction &MF,
3484534845
EVT VT) const {
34846+
if (Subtarget.useSoftFloat())
34847+
return false;
34848+
3484634849
if (!Subtarget.hasAnyFMA())
3484734850
return false;
3484834851

0 commit comments

Comments
 (0)