Skip to content

Commit 5785cbb

Browse files
authored
[llvm] Ensure that soft float targets don't emit fma() libcalls. (#106615)
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. Note: I don't have commit access.
1 parent 8fe49b0 commit 5785cbb

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
@@ -3223,6 +3223,9 @@ class TargetLoweringBase {
32233223
/// not legal, but should return true if those types will eventually legalize
32243224
/// to types that support FMAs. After legalization, it will only be called on
32253225
/// types that support FMAs (via Legal or Custom actions)
3226+
///
3227+
/// Targets that care about soft float support should return false when soft
3228+
/// float code is being generated (i.e. use-soft-float).
32263229
virtual bool isFMAFasterThanFMulAndFAdd(const MachineFunction &MF,
32273230
EVT) const {
32283231
return false;

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19354,6 +19354,9 @@ bool ARMTargetLowering::allowTruncateForTailCall(Type *Ty1, Type *Ty2) const {
1935419354
/// patterns (and we don't have the non-fused floating point instruction).
1935519355
bool ARMTargetLowering::isFMAFasterThanFMulAndFAdd(const MachineFunction &MF,
1935619356
EVT VT) const {
19357+
if (Subtarget->useSoftFloat())
19358+
return false;
19359+
1935719360
if (!VT.isSimple())
1935819361
return false;
1935919362

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
@@ -34838,6 +34838,9 @@ bool X86TargetLowering::isVectorLoadExtDesirable(SDValue ExtVal) const {
3483834838

3483934839
bool X86TargetLowering::isFMAFasterThanFMulAndFAdd(const MachineFunction &MF,
3484034840
EVT VT) const {
34841+
if (Subtarget.useSoftFloat())
34842+
return false;
34843+
3484134844
if (!Subtarget.hasAnyFMA())
3484234845
return false;
3484334846

0 commit comments

Comments
 (0)