summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Stannard <oliver.stannard@linaro.org>2019-08-02 10:23:17 +0000
committerOliver Stannard <oliver.stannard@linaro.org>2019-08-02 10:23:17 +0000
commit4b7239ebaca72f2cd92682019fbe0bef5b46cd4e (patch)
tree9e69d9d57dd2290f21ab73a63cf156a676e4cf36
parentf6b00c279a5587a25876752a6ecd8da0bed959dc (diff)
downloadbcm5719-llvm-4b7239ebaca72f2cd92682019fbe0bef5b46cd4e.tar.gz
bcm5719-llvm-4b7239ebaca72f2cd92682019fbe0bef5b46cd4e.zip
[IPRA][ARM] Disable no-CSR optimisation for ARM
This optimisation isn't generally profitable for ARM, because we can save/restore many registers in the prologue and epilogue using the PUSH and POP instructions, but mostly use individual LDR/STR instructions for other spills. Differential revision: https://reviews.llvm.org/D64910 llvm-svn: 367670
-rw-r--r--llvm/include/llvm/CodeGen/TargetFrameLowering.h5
-rw-r--r--llvm/lib/CodeGen/RegUsageInfoCollector.cpp3
-rw-r--r--llvm/lib/CodeGen/TargetFrameLoweringImpl.cpp4
-rw-r--r--llvm/lib/Target/ARM/ARMFrameLowering.h5
-rw-r--r--llvm/test/CodeGen/ARM/ipra-no-csr.ll22
5 files changed, 37 insertions, 2 deletions
diff --git a/llvm/include/llvm/CodeGen/TargetFrameLowering.h b/llvm/include/llvm/CodeGen/TargetFrameLowering.h
index 878c9ffd2b5..284f7ba64db 100644
--- a/llvm/include/llvm/CodeGen/TargetFrameLowering.h
+++ b/llvm/include/llvm/CodeGen/TargetFrameLowering.h
@@ -378,6 +378,11 @@ public:
return true;
}
+ /// Check if the no-CSR optimisation is profitable for the given function.
+ virtual bool isProfitableForNoCSROpt(const Function &F) const {
+ return true;
+ }
+
/// Return initial CFA offset value i.e. the one valid at the beginning of the
/// function (before any stack operations).
virtual int getInitialCFAOffset(const MachineFunction &MF) const;
diff --git a/llvm/lib/CodeGen/RegUsageInfoCollector.cpp b/llvm/lib/CodeGen/RegUsageInfoCollector.cpp
index 64552b58e2e..757ff0e4495 100644
--- a/llvm/lib/CodeGen/RegUsageInfoCollector.cpp
+++ b/llvm/lib/CodeGen/RegUsageInfoCollector.cpp
@@ -171,7 +171,8 @@ bool RegUsageInfoCollector::runOnMachineFunction(MachineFunction &MF) {
SetRegAsDefined(PReg);
}
- if (TargetFrameLowering::isSafeForNoCSROpt(F)) {
+ if (TargetFrameLowering::isSafeForNoCSROpt(F) &&
+ MF.getSubtarget().getFrameLowering()->isProfitableForNoCSROpt(F)) {
++NumCSROpt;
LLVM_DEBUG(dbgs() << MF.getName()
<< " function optimized for not having CSR.\n");
diff --git a/llvm/lib/CodeGen/TargetFrameLoweringImpl.cpp b/llvm/lib/CodeGen/TargetFrameLoweringImpl.cpp
index 9c4483cb240..c5cd87b1481 100644
--- a/llvm/lib/CodeGen/TargetFrameLoweringImpl.cpp
+++ b/llvm/lib/CodeGen/TargetFrameLoweringImpl.cpp
@@ -71,7 +71,9 @@ void TargetFrameLowering::determineCalleeSaves(MachineFunction &MF,
// When interprocedural register allocation is enabled caller saved registers
// are preferred over callee saved registers.
- if (MF.getTarget().Options.EnableIPRA && isSafeForNoCSROpt(MF.getFunction()))
+ if (MF.getTarget().Options.EnableIPRA &&
+ isSafeForNoCSROpt(MF.getFunction()) &&
+ isProfitableForNoCSROpt(MF.getFunction()))
return;
// Get the callee saved register list...
diff --git a/llvm/lib/Target/ARM/ARMFrameLowering.h b/llvm/lib/Target/ARM/ARMFrameLowering.h
index 7544ca3c38d..6d8aee59794 100644
--- a/llvm/lib/Target/ARM/ARMFrameLowering.h
+++ b/llvm/lib/Target/ARM/ARMFrameLowering.h
@@ -63,6 +63,11 @@ public:
bool enableShrinkWrapping(const MachineFunction &MF) const override {
return true;
}
+ bool isProfitableForNoCSROpt(const Function &F) const override {
+ // The no-CSR optimisation is bad for code size on ARM, because we can save
+ // many registers with a single PUSH/POP pair.
+ return false;
+ }
private:
void emitPushInst(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
diff --git a/llvm/test/CodeGen/ARM/ipra-no-csr.ll b/llvm/test/CodeGen/ARM/ipra-no-csr.ll
new file mode 100644
index 00000000000..8070573fbc0
--- /dev/null
+++ b/llvm/test/CodeGen/ARM/ipra-no-csr.ll
@@ -0,0 +1,22 @@
+; RUN: llc -mtriple armv7a--none-eabi < %s | FileCheck %s
+; RUN: llc -mtriple armv7a--none-eabi < %s -enable-ipra | FileCheck %s
+
+; Other targets disable callee-saved registers for internal functions when
+; using IPRA, but that isn't profitable for ARM because the PUSH/POP
+; instructions can more efficiently save registers than using individual
+; LDR/STRs in the caller.
+
+define internal void @callee() norecurse {
+; CHECK-LABEL: callee:
+entry:
+; CHECK: push {r4, lr}
+; CHECK: pop {r4, pc}
+ tail call void asm sideeffect "", "~{r4}"()
+ ret void
+}
+
+define void @caller() {
+entry:
+ call void @callee()
+ ret void
+}
OpenPOWER on IntegriCloud