summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/BranchFolding.cpp
diff options
context:
space:
mode:
authorBob Wilson <bob.wilson@apple.com>2009-10-28 22:10:20 +0000
committerBob Wilson <bob.wilson@apple.com>2009-10-28 22:10:20 +0000
commit3ab552ec74751a3388cf085ee5b10adcd4d2bea2 (patch)
tree605577d294624500c2ee008d4c20edf1d9c9eaca /llvm/lib/CodeGen/BranchFolding.cpp
parentf0c8611d3fe5c6d17d5b687ed52bd2abb49a32ff (diff)
downloadbcm5719-llvm-3ab552ec74751a3388cf085ee5b10adcd4d2bea2.tar.gz
bcm5719-llvm-3ab552ec74751a3388cf085ee5b10adcd4d2bea2.zip
Reimplement BranchFolding change to avoid tail merging for a 1 instruction
common tail, except when the OptimizeForSize function attribute is present. Radar 7338114. llvm-svn: 85441
Diffstat (limited to 'llvm/lib/CodeGen/BranchFolding.cpp')
-rw-r--r--llvm/lib/CodeGen/BranchFolding.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp
index 66c5aa5ff78..7bc25ab9e95 100644
--- a/llvm/lib/CodeGen/BranchFolding.cpp
+++ b/llvm/lib/CodeGen/BranchFolding.cpp
@@ -18,6 +18,7 @@
#define DEBUG_TYPE "branchfolding"
#include "BranchFolding.h"
+#include "llvm/Function.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
@@ -465,22 +466,23 @@ unsigned BranchFolder::ComputeSameTails(unsigned CurHash,
CurMPIter!=B && CurMPIter->first==CurHash;
--CurMPIter) {
for (MPIterator I = prior(CurMPIter); I->first==CurHash ; --I) {
- unsigned CommonTailLen = ComputeCommonTailLength(
- CurMPIter->second,
- I->second,
- TrialBBI1, TrialBBI2);
+ unsigned CommonTailLen = ComputeCommonTailLength(CurMPIter->second,
+ I->second,
+ TrialBBI1, TrialBBI2);
// If we will have to split a block, there should be at least
- // minCommonTailLength instructions in common; if not, at worst
- // we will be replacing a fallthrough into the common tail with a
- // branch, which at worst breaks even with falling through into
- // the duplicated common tail, so 1 instruction in common is enough.
- // We will always pick a block we do not have to split as the common
- // tail if there is one.
- // (Empty blocks will get forwarded and need not be considered.)
+ // minCommonTailLength instructions in common. Otherwise, if we are
+ // optimizing for code size, 1 instruction in common is enough. At
+ // worst we will be replacing a fallthrough into the common tail with a
+ // branch, which at worst breaks even with falling through into the
+ // duplicated common tail. We will always pick a block we do not have
+ // to split as the common tail if there is one. (Empty blocks will get
+ // forwarded and need not be considered.)
+ MachineFunction *MF = CurMPIter->second->getParent();
if (CommonTailLen >= minCommonTailLength ||
(CommonTailLen > 0 &&
- (TrialBBI1==CurMPIter->second->begin() ||
- TrialBBI2==I->second->begin()))) {
+ MF->getFunction()->hasFnAttr(Attribute::OptimizeForSize) &&
+ (TrialBBI1 == CurMPIter->second->begin() ||
+ TrialBBI2 == I->second->begin()))) {
if (CommonTailLen > maxCommonTailLength) {
SameTails.clear();
maxCommonTailLength = CommonTailLen;
OpenPOWER on IntegriCloud