summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/BranchFolding.cpp
diff options
context:
space:
mode:
authorJunmo Park <junmoz.park@samsung.com>2015-12-04 02:29:25 +0000
committerJunmo Park <junmoz.park@samsung.com>2015-12-04 02:29:25 +0000
commitc0731ca183fecde15b2badbac6f4292aa5b68c73 (patch)
treec535d2b9eb4b36e9a073f31b01bff97fc6d4e0c7 /llvm/lib/CodeGen/BranchFolding.cpp
parentf0f4b4c88217613f96d59c161a94424edef9458c (diff)
downloadbcm5719-llvm-c0731ca183fecde15b2badbac6f4292aa5b68c73.tar.gz
bcm5719-llvm-c0731ca183fecde15b2badbac6f4292aa5b68c73.zip
[BranchFolding] Merge MMOs during tail merge
Summary: If we remove the MMOs from Load/Store instructions, they are treated as volatile. This makes other optimization passes unhappy. eg. Load/Store Optimization So, it looks better to merge, not remove. Reviewers: gberry, mcrosier Subscribers: gberry, llvm-commits Differential Revision: http://reviews.llvm.org/D14797 llvm-svn: 254694
Diffstat (limited to 'llvm/lib/CodeGen/BranchFolding.cpp')
-rw-r--r--llvm/lib/CodeGen/BranchFolding.cpp42
1 files changed, 26 insertions, 16 deletions
diff --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp
index e41926a819c..3878281a4fe 100644
--- a/llvm/lib/CodeGen/BranchFolding.cpp
+++ b/llvm/lib/CodeGen/BranchFolding.cpp
@@ -744,24 +744,35 @@ bool BranchFolder::CreateCommonTailOnlyBlock(MachineBasicBlock *&PredBB,
return true;
}
-static bool hasIdenticalMMOs(const MachineInstr *MI1, const MachineInstr *MI2) {
+// Add MI1's MMOs to MI2's MMOs while excluding any duplicates. The MI scheduler
+// currently doesn't handle multiple MMOs, so duplicates would likely pessimize
+// the scheduler.
+static void mergeMMOs(MachineInstr *MI1, MachineInstr *MI2) {
auto I1 = MI1->memoperands_begin(), E1 = MI1->memoperands_end();
auto I2 = MI2->memoperands_begin(), E2 = MI2->memoperands_end();
- if ((E1 - I1) != (E2 - I2))
- return false;
- for (; I1 != E1; ++I1, ++I2) {
- if (**I1 != **I2)
- return false;
+ MachineFunction *MF = MI1->getParent()->getParent();
+
+ // Mostly, MI1's MMO count is 1 or zero. So we don't have to use
+ // SmallSet.
+ for (; I1 != E1; ++I1) {
+ bool IsDupMMO = false;
+ for (I2 = MI2->memoperands_begin(); I2 != E2; ++I2) {
+ if (**I1 == **I2) {
+ IsDupMMO = true;
+ break;
+ }
+ }
+ if (IsDupMMO == false) {
+ MI2->addMemOperand(*MF, *I1);
+ E2 = MI2->memoperands_end();
+ }
}
- return true;
}
static void
-removeMMOsFromMemoryOperations(MachineBasicBlock::iterator MBBIStartPos,
- MachineBasicBlock &MBBCommon) {
- // Remove MMOs from memory operations in the common block
- // when they do not match the ones from the block being tail-merged.
- // This ensures later passes conservatively compute dependencies.
+mergeMMOsFromMemoryOperations(MachineBasicBlock::iterator MBBIStartPos,
+ MachineBasicBlock &MBBCommon) {
+ // Merge MMOs from memory operations in the common block
MachineBasicBlock *MBB = MBBIStartPos->getParent();
// Note CommonTailLen does not necessarily matches the size of
// the common BB nor all its instructions because of debug
@@ -792,8 +803,7 @@ removeMMOsFromMemoryOperations(MachineBasicBlock::iterator MBBIStartPos,
assert(MBBICommon->isIdenticalTo(&*MBBI) && "Expected matching MIIs!");
if (MBBICommon->mayLoad() || MBBICommon->mayStore())
- if (!hasIdenticalMMOs(&*MBBI, &*MBBICommon))
- MBBICommon->clearMemRefs();
+ mergeMMOs(&*MBBI, &*MBBICommon);
++MBBI;
++MBBICommon;
@@ -913,8 +923,8 @@ bool BranchFolder::TryTailMergeBlocks(MachineBasicBlock *SuccBB,
continue;
DEBUG(dbgs() << "BB#" << SameTails[i].getBlock()->getNumber()
<< (i == e-1 ? "" : ", "));
- // Remove MMOs from memory operations as needed.
- removeMMOsFromMemoryOperations(SameTails[i].getTailStartPos(), *MBB);
+ // Merge MMOs from memory operations as needed.
+ mergeMMOsFromMemoryOperations(SameTails[i].getTailStartPos(), *MBB);
// Hack the end off BB i, making it jump to BB commonTailIndex instead.
ReplaceTailWithBranchTo(SameTails[i].getTailStartPos(), MBB);
// BB i is no longer a predecessor of SuccBB; remove it from the worklist.
OpenPOWER on IntegriCloud