Skip to content

Commit cf69f3a

Browse files
committed
Remove UnsafeFPMath uses in ARM
1 parent 4b5111a commit cf69f3a

File tree

13 files changed

+53
-30
lines changed

13 files changed

+53
-30
lines changed

llvm/lib/Target/ARM/ARMAsmPrinter.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,21 @@ static bool checkDenormalAttributeConsistency(const Module &M,
629629
});
630630
}
631631

632+
// Returns true if all functions have different denormal modes.
633+
static bool checkDenormalAttributeInconsistency(const Module &M) {
634+
if (M.functions().empty())
635+
return false;
636+
DenormalMode Value =
637+
parseDenormalFPAttribute(M.functions()
638+
.begin()
639+
->getFnAttribute("denormal-fp-math")
640+
.getValueAsString());
641+
return any_of(M, [&](const Function &F) {
642+
StringRef AttrVal = F.getFnAttribute("denormal-fp-math").getValueAsString();
643+
return parseDenormalFPAttribute(AttrVal) != Value;
644+
});
645+
}
646+
632647
void ARMAsmPrinter::emitAttributes() {
633648
MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();
634649
ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
@@ -695,7 +710,9 @@ void ARMAsmPrinter::emitAttributes() {
695710
DenormalMode::getPositiveZero()))
696711
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
697712
ARMBuildAttrs::PositiveZero);
698-
else if (!TM.Options.UnsafeFPMath)
713+
else if (checkDenormalAttributeInconsistency(*MMI->getModule()) ||
714+
checkDenormalAttributeConsistency(
715+
*MMI->getModule(), "denormal-fp-math", DenormalMode::getIEEE()))
699716
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
700717
ARMBuildAttrs::IEEEDenormals);
701718
else {
@@ -730,7 +747,7 @@ void ARMAsmPrinter::emitAttributes() {
730747
TM.Options.NoTrappingFPMath)
731748
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions,
732749
ARMBuildAttrs::Not_Allowed);
733-
else if (!TM.Options.UnsafeFPMath) {
750+
else {
734751
ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions, ARMBuildAttrs::Allowed);
735752

736753
// If the user has permitted this code to choose the IEEE 754

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5736,7 +5736,7 @@ static void expandf64Toi32(SDValue Op, SelectionDAG &DAG,
57365736
llvm_unreachable("Unknown VFP cmp argument!");
57375737
}
57385738

5739-
/// OptimizeVFPBrcond - With -enable-unsafe-fp-math, it's legal to optimize some
5739+
/// OptimizeVFPBrcond - With nnan, it's legal to optimize some
57405740
/// f32 and even f64 comparisons to integer ones.
57415741
SDValue
57425742
ARMTargetLowering::OptimizeVFPBrcond(SDValue Op, SelectionDAG &DAG) const {
@@ -5878,9 +5878,9 @@ SDValue ARMTargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) const {
58785878
return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, Chain, Dest, ARMcc, Cmp);
58795879
}
58805880

5881-
if (getTargetMachine().Options.UnsafeFPMath &&
5882-
(CC == ISD::SETEQ || CC == ISD::SETOEQ ||
5883-
CC == ISD::SETNE || CC == ISD::SETUNE)) {
5881+
if (SDNodeFlags Flags = Op->getFlags();
5882+
Flags.hasNoNaNs() && (CC == ISD::SETEQ || CC == ISD::SETOEQ ||
5883+
CC == ISD::SETNE || CC == ISD::SETUNE)) {
58845884
if (SDValue Result = OptimizeVFPBrcond(Op, DAG))
58855885
return Result;
58865886
}

llvm/lib/Target/ARM/ARMSubtarget.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,16 @@ ARMFrameLowering *ARMSubtarget::initializeFrameLowering(StringRef CPU,
8888
ARMSubtarget::ARMSubtarget(const Triple &TT, const std::string &CPU,
8989
const std::string &FS,
9090
const ARMBaseTargetMachine &TM, bool IsLittle,
91-
bool MinSize)
91+
bool MinSize, DenormalMode DM)
9292
: ARMGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS),
9393
UseMulOps(UseFusedMulOps), CPUString(CPU), OptMinSize(MinSize),
94-
IsLittle(IsLittle), TargetTriple(TT), Options(TM.Options), TM(TM),
94+
IsLittle(IsLittle), DM(DM), TargetTriple(TT), Options(TM.Options), TM(TM),
9595
FrameLowering(initializeFrameLowering(CPU, FS)),
9696
// At this point initializeSubtargetDependencies has been called so
9797
// we can query directly.
98-
InstrInfo(isThumb1Only()
99-
? (ARMBaseInstrInfo *)new Thumb1InstrInfo(*this)
100-
: !isThumb()
101-
? (ARMBaseInstrInfo *)new ARMInstrInfo(*this)
102-
: (ARMBaseInstrInfo *)new Thumb2InstrInfo(*this)),
98+
InstrInfo(isThumb1Only() ? (ARMBaseInstrInfo *)new Thumb1InstrInfo(*this)
99+
: !isThumb() ? (ARMBaseInstrInfo *)new ARMInstrInfo(*this)
100+
: (ARMBaseInstrInfo *)new Thumb2InstrInfo(*this)),
103101
TLInfo(TM, *this) {
104102

105103
CallLoweringInfo.reset(new ARMCallLowering(*getTargetLowering()));
@@ -224,7 +222,7 @@ void ARMSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
224222
// NEON f32 ops are non-IEEE 754 compliant. Darwin is ok with it by default.
225223
const FeatureBitset &Bits = getFeatureBits();
226224
if ((Bits[ARM::ProcA5] || Bits[ARM::ProcA8]) && // Where this matters
227-
(Options.UnsafeFPMath || isTargetDarwin()))
225+
(isTargetDarwin() || DM == DenormalMode::getPreserveSign()))
228226
HasNEONForFP = true;
229227

230228
if (isRWPI())

llvm/lib/Target/ARM/ARMSubtarget.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ class ARMSubtarget : public ARMGenSubtargetInfo {
186186
/// IsLittle - The target is Little Endian
187187
bool IsLittle;
188188

189+
/// DM - Denormal mode
190+
DenormalMode DM;
191+
189192
/// TargetTriple - What processor and OS we're targeting.
190193
Triple TargetTriple;
191194

@@ -206,7 +209,7 @@ class ARMSubtarget : public ARMGenSubtargetInfo {
206209
///
207210
ARMSubtarget(const Triple &TT, const std::string &CPU, const std::string &FS,
208211
const ARMBaseTargetMachine &TM, bool IsLittle,
209-
bool MinSize = false);
212+
bool MinSize = false, DenormalMode DM = DenormalMode::getIEEE());
210213

211214
/// getMaxInlineSizeThreshold - Returns the maximum memset / memcpy size
212215
/// that still makes it profitable to inline the call.

llvm/lib/Target/ARM/ARMTargetMachine.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,14 +285,19 @@ ARMBaseTargetMachine::getSubtargetImpl(const Function &F) const {
285285
if (F.hasMinSize())
286286
Key += "+minsize";
287287

288+
DenormalMode DM = parseDenormalFPAttribute(
289+
F.getFnAttribute("denormal-fp-math").getValueAsString());
290+
if (DM != DenormalMode::getIEEE())
291+
Key += "denormal-fp-math=" + DM.str();
292+
288293
auto &I = SubtargetMap[Key];
289294
if (!I) {
290295
// This needs to be done before we create a new subtarget since any
291296
// creation will depend on the TM and the code generation flags on the
292297
// function that reside in TargetOptions.
293298
resetTargetOptions(F);
294299
I = std::make_unique<ARMSubtarget>(TargetTriple, CPU, FS, *this, isLittle,
295-
F.hasMinSize());
300+
F.hasMinSize(), DM);
296301

297302
if (!I->isThumb() && !I->hasARMOps())
298303
F.getContext().emitError("Function '" + F.getName() + "' uses ARM "

llvm/test/CodeGen/ARM/fadds.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
; RUN: llc -mtriple=arm-eabi -mcpu=cortex-a8 %s -o - \
88
; RUN: | FileCheck %s -check-prefix=CORTEXA8
99

10-
; RUN: llc -mtriple=arm-eabi -mcpu=cortex-a8 --enable-unsafe-fp-math %s -o - \
10+
; RUN: llc -mtriple=arm-eabi -mcpu=cortex-a8 --denormal-fp-math=preserve-sign %s -o - \
1111
; RUN: | FileCheck %s -check-prefix=CORTEXA8U
1212

1313
; RUN: llc -mtriple=arm-darwin -mcpu=cortex-a8 %s -o - \

llvm/test/CodeGen/ARM/fmuls.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
; RUN: llc -mtriple=arm-eabi -mcpu=cortex-a8 %s -o - \
88
; RUN: | FileCheck %s -check-prefix=CORTEXA8
99

10-
; RUN: llc -mtriple=arm-eabi -mcpu=cortex-a8 --enable-unsafe-fp-math %s -o - \
10+
; RUN: llc -mtriple=arm-eabi -mcpu=cortex-a8 --denormal-fp-math=preserve-sign %s -o - \
1111
; RUN: | FileCheck %s -check-prefix=CORTEXA8U
1212

1313
; RUN: llc -mtriple=arm-darwin -mcpu=cortex-a8 %s -o - \

llvm/test/CodeGen/ARM/fnegs.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
; RUN: llc -mtriple=arm-eabi -mcpu=cortex-a8 %s -o - \
1111
; RUN: | FileCheck %s -check-prefix=CORTEXA8
1212

13-
; RUN: llc -mtriple=arm-eabi -mcpu=cortex-a8 --enable-unsafe-fp-math %s -o - \
13+
; RUN: llc -mtriple=arm-eabi -mcpu=cortex-a8 --denormal-fp-math=preserve-sign %s -o - \
1414
; RUN: | FileCheck %s -check-prefix=CORTEXA8U
1515

1616
; RUN: llc -mtriple=arm-darwin -mcpu=cortex-a8 %s -o - \

llvm/test/CodeGen/ARM/fnmscs.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
; RUN: llc -mtriple=arm-eabi -mcpu=cortex-a8 -regalloc=basic %s -o - \
1414
; RUN: | FileCheck %s -check-prefix=A8
1515

16-
; RUN: llc -mtriple=arm-eabi -mcpu=cortex-a8 --enable-unsafe-fp-math %s -o - \
16+
; RUN: llc -mtriple=arm-eabi -mcpu=cortex-a8 --enable-unsafe-fp-math %s -o - \
1717
; RUN: | FileCheck %s -check-prefix=A8U
1818

1919
; RUN: llc -mtriple=arm-darwin -mcpu=cortex-a8 %s -o - \

llvm/test/CodeGen/ARM/fp_convert.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
; RUN: llc -mtriple=arm-eabi -mcpu=cortex-a8 %s -o - \
88
; RUN: | FileCheck %s -check-prefix=VFP2
99

10-
; RUN: llc -mtriple=arm-eabi -mcpu=cortex-a8 --enable-unsafe-fp-math %s -o - \
10+
; RUN: llc -mtriple=arm-eabi -mcpu=cortex-a8 --denormal-fp-math=preserve-sign %s -o - \
1111
; RUN: | FileCheck %s -check-prefix=NEON
1212

1313
; RUN: llc -mtriple=arm-darwin -mcpu=cortex-a8 %s -o - \

0 commit comments

Comments
 (0)