Skip to content

Commit add906f

Browse files
authored
[ARM] Consider denormal mode in ARMSubtarget (#160456)
Factor out from #151275. Add denormal mode to subtarget.
1 parent 475e0ee commit add906f

File tree

8 files changed

+28
-19
lines changed

8 files changed

+28
-19
lines changed

llvm/lib/Target/ARM/ARMSubtarget.cpp

Lines changed: 7 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,8 @@ 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+
(Options.UnsafeFPMath || isTargetDarwin() ||
226+
DM == DenormalMode::getPreserveSign()))
228227
HasNEONForFP = true;
229228

230229
if (isRWPI())

llvm/lib/Target/ARM/ARMSubtarget.h

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

189+
/// DM - Denormal mode
190+
/// NEON and VFP RunFast mode are not IEEE 754 compliant,
191+
/// use this field to determine whether to generate NEON/VFP
192+
/// instructions in related function.
193+
DenormalMode DM;
194+
189195
/// TargetTriple - What processor and OS we're targeting.
190196
Triple TargetTriple;
191197

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

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

llvm/lib/Target/ARM/ARMTargetMachine.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,18 @@ ARMBaseTargetMachine::getSubtargetImpl(const Function &F) const {
229229
if (F.hasMinSize())
230230
Key += "+minsize";
231231

232+
DenormalMode DM = F.getDenormalModeRaw();
233+
if (DM != DenormalMode::getIEEE())
234+
Key += "denormal-fp-math=" + DM.str();
235+
232236
auto &I = SubtargetMap[Key];
233237
if (!I) {
234238
// This needs to be done before we create a new subtarget since any
235239
// creation will depend on the TM and the code generation flags on the
236240
// function that reside in TargetOptions.
237241
resetTargetOptions(F);
238242
I = std::make_unique<ARMSubtarget>(TargetTriple, CPU, FS, *this, isLittle,
239-
F.hasMinSize());
243+
F.hasMinSize(), DM);
240244

241245
if (!I->isThumb() && !I->hasARMOps())
242246
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/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 - \

llvm/test/CodeGen/ARM/fsubs.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
; RUN: llc -mtriple=arm-eabi -mcpu=cortex-a8 %s -o - \
55
; RUN: | FileCheck %s -check-prefix=NFP1
66

7-
; RUN: llc -mtriple=arm-eabi -mcpu=cortex-a8 --enable-unsafe-fp-math %s -o - \
7+
; RUN: llc -mtriple=arm-eabi -mcpu=cortex-a8 --denormal-fp-math=preserve-sign %s -o - \
88
; RUN: | FileCheck %s -check-prefix=NFP1U
99

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

llvm/test/CodeGen/ARM/neon-spfp.ll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
; RUN: llc < %s -mtriple armv7a-none-linux-gnueabihf -mcpu=cortex-a15 | FileCheck %s -check-prefix=CHECK-LINUXA15
55
; RUN: llc < %s -mtriple armv7a-none-linux-gnueabihf -mcpu=swift | FileCheck %s -check-prefix=CHECK-LINUXSWIFT
66

7-
; RUN: llc < %s -mtriple armv7a-none-linux-gnueabihf -mcpu=cortex-a5 --enable-unsafe-fp-math | FileCheck %s -check-prefix=CHECK-UNSAFEA5
8-
; RUN: llc < %s -mtriple armv7a-none-linux-gnueabihf -mcpu=cortex-a8 --enable-unsafe-fp-math | FileCheck %s -check-prefix=CHECK-UNSAFEA8
9-
; RUN: llc < %s -mtriple armv7a-none-linux-gnueabihf -mcpu=cortex-a9 --enable-unsafe-fp-math | FileCheck %s -check-prefix=CHECK-UNSAFEA9
10-
; RUN: llc < %s -mtriple armv7a-none-linux-gnueabihf -mcpu=cortex-a15 --enable-unsafe-fp-math | FileCheck %s -check-prefix=CHECK-UNSAFEA15
11-
; RUN: llc < %s -mtriple armv7a-none-linux-gnueabihf -mcpu=swift --enable-unsafe-fp-math | FileCheck %s -check-prefix=CHECK-UNSAFESWIFT
7+
; RUN: llc < %s -mtriple armv7a-none-linux-gnueabihf -mcpu=cortex-a5 --denormal-fp-math=preserve-sign | FileCheck %s -check-prefix=CHECK-UNSAFEA5
8+
; RUN: llc < %s -mtriple armv7a-none-linux-gnueabihf -mcpu=cortex-a8 --denormal-fp-math=preserve-sign | FileCheck %s -check-prefix=CHECK-UNSAFEA8
9+
; RUN: llc < %s -mtriple armv7a-none-linux-gnueabihf -mcpu=cortex-a9 --denormal-fp-math=preserve-sign | FileCheck %s -check-prefix=CHECK-UNSAFEA9
10+
; RUN: llc < %s -mtriple armv7a-none-linux-gnueabihf -mcpu=cortex-a15 --denormal-fp-math=preserve-sign| FileCheck %s -check-prefix=CHECK-UNSAFEA15
11+
; RUN: llc < %s -mtriple armv7a-none-linux-gnueabihf -mcpu=swift --denormal-fp-math=preserve-sign | FileCheck %s -check-prefix=CHECK-UNSAFESWIFT
1212

1313
; RUN: llc < %s -mtriple armv7a-none-darwin -mcpu=cortex-a5 | FileCheck %s -check-prefix=CHECK-DARWINA5
1414
; RUN: llc < %s -mtriple armv7a-none-darwin -mcpu=cortex-a8 | FileCheck %s -check-prefix=CHECK-DARWINA8

0 commit comments

Comments
 (0)