-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[ARM] Consider denormal mode in ARMSubtarget
#160456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-backend-arm Author: None (paperchalice) ChangesFactor out from #151275. Full diff: https://github.com/llvm/llvm-project/pull/160456.diff 3 Files Affected:
diff --git a/llvm/lib/Target/ARM/ARMSubtarget.cpp b/llvm/lib/Target/ARM/ARMSubtarget.cpp
index 9f600e0c685ab..ed7a1ef21ee84 100644
--- a/llvm/lib/Target/ARM/ARMSubtarget.cpp
+++ b/llvm/lib/Target/ARM/ARMSubtarget.cpp
@@ -88,18 +88,16 @@ ARMFrameLowering *ARMSubtarget::initializeFrameLowering(StringRef CPU,
ARMSubtarget::ARMSubtarget(const Triple &TT, const std::string &CPU,
const std::string &FS,
const ARMBaseTargetMachine &TM, bool IsLittle,
- bool MinSize)
+ bool MinSize, DenormalMode DM)
: ARMGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS),
UseMulOps(UseFusedMulOps), CPUString(CPU), OptMinSize(MinSize),
- IsLittle(IsLittle), TargetTriple(TT), Options(TM.Options), TM(TM),
+ IsLittle(IsLittle), DM(DM), TargetTriple(TT), Options(TM.Options), TM(TM),
FrameLowering(initializeFrameLowering(CPU, FS)),
// At this point initializeSubtargetDependencies has been called so
// we can query directly.
- InstrInfo(isThumb1Only()
- ? (ARMBaseInstrInfo *)new Thumb1InstrInfo(*this)
- : !isThumb()
- ? (ARMBaseInstrInfo *)new ARMInstrInfo(*this)
- : (ARMBaseInstrInfo *)new Thumb2InstrInfo(*this)),
+ InstrInfo(isThumb1Only() ? (ARMBaseInstrInfo *)new Thumb1InstrInfo(*this)
+ : !isThumb() ? (ARMBaseInstrInfo *)new ARMInstrInfo(*this)
+ : (ARMBaseInstrInfo *)new Thumb2InstrInfo(*this)),
TLInfo(TM, *this) {
CallLoweringInfo.reset(new ARMCallLowering(*getTargetLowering()));
diff --git a/llvm/lib/Target/ARM/ARMSubtarget.h b/llvm/lib/Target/ARM/ARMSubtarget.h
index 637eb4560e0f1..d848da0f1dbd5 100644
--- a/llvm/lib/Target/ARM/ARMSubtarget.h
+++ b/llvm/lib/Target/ARM/ARMSubtarget.h
@@ -183,6 +183,12 @@ class ARMSubtarget : public ARMGenSubtargetInfo {
/// the function attribute.
bool OptMinSize = false;
+ /// DM - Denormal mode
+ /// NEON and VFP RunFast mode are not IEEE 754 compliant,
+ /// use this field to determine whether to generate NEON/VFP
+ /// instructions in related function.
+ DenormalMode DM;
+
/// IsLittle - The target is Little Endian
bool IsLittle;
diff --git a/llvm/lib/Target/ARM/ARMTargetMachine.cpp b/llvm/lib/Target/ARM/ARMTargetMachine.cpp
index 131b9332e9ade..86740a92b32c5 100644
--- a/llvm/lib/Target/ARM/ARMTargetMachine.cpp
+++ b/llvm/lib/Target/ARM/ARMTargetMachine.cpp
@@ -229,6 +229,10 @@ ARMBaseTargetMachine::getSubtargetImpl(const Function &F) const {
if (F.hasMinSize())
Key += "+minsize";
+ DenormalMode DM = F.getDenormalModeRaw();
+ if (DM != DenormalMode::getIEEE())
+ Key += "denormal-fp-math=" + DM.str();
+
auto &I = SubtargetMap[Key];
if (!I) {
// This needs to be done before we create a new subtarget since any
@@ -236,7 +240,7 @@ ARMBaseTargetMachine::getSubtargetImpl(const Function &F) const {
// function that reside in TargetOptions.
resetTargetOptions(F);
I = std::make_unique<ARMSubtarget>(TargetTriple, CPU, FS, *this, isLittle,
- F.hasMinSize());
+ F.hasMinSize(), DM);
if (!I->isThumb() && !I->hasARMOps())
F.getContext().emitError("Function '" + F.getName() + "' uses ARM "
|
Another possible method is adding a new IR module flag meta data for ARM with behavior 1 or 2. |
6cdd9c3
to
98cf73e
Compare
98cf73e
to
9e268b4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this. Can you pull in the change from this bit of code too? It can use this denormal feature now?
// NEON f32 ops are non-IEEE 754 compliant. Darwin is ok with it by default.
const FeatureBitset &Bits = getFeatureBits();
if ((Bits[ARM::ProcA5] || Bits[ARM::ProcA8]) && // Where this matters
(Options.UnsafeFPMath || isTargetDarwin()))
And maybe update the test, I think there are a few that this triggers on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. LGTM
Hopefully what remains in #151275 is a lot simpler now.
Factor out from llvm#151275. Add denormal mode to subtarget.
Factor out from llvm#151275. Add denormal mode to subtarget.
Factor out from #151275.
Add denormal mode to subtarget.