aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2007-03-17 08:22:49 +0000
committerEvan Cheng <evan.cheng@apple.com>2007-03-17 08:22:49 +0000
commit2edd5638255dbbcdad55ca724953e155ab13b5d1 (patch)
treef6f74071f28e099ec765d3bd67317ecfeed6ef8f /lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
parentade0162fdfb133440fdf4df18158719c04157dcc (diff)
If sdisel has decided to sink GEP index expression into any BB. Replace all uses
in that BB. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35132 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp')
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp59
1 files changed, 37 insertions, 22 deletions
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index 5fc3be1fd4..059d8a7211 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -3982,18 +3982,13 @@ static bool SinkInvariantGEPIndex(BinaryOperator *BinOp, LoopInfo *loopInfo,
BinOp->getOpcode() != Instruction::Sub)
return false;
- /// InsertedOps - Only insert a duplicate in each block once.
- std::map<BasicBlock*, BinaryOperator*> InsertedOps;
-
- bool MadeChange = false;
+ // DestBBs - These are the blocks where a copy of BinOp will be inserted.
+ std::set<BasicBlock*> DestBBs;
BasicBlock *DefBB = BinOp->getParent();
+ bool MadeChange = false;
for (Value::use_iterator UI = BinOp->use_begin(), E = BinOp->use_end();
- UI != E; ) {
+ UI != E; ++UI) {
Instruction *User = cast<Instruction>(*UI);
-
- // Preincrement use iterator so we don't invalidate it.
- ++UI;
-
// Only look for GEP use in another block.
if (User->getParent() == DefBB) continue;
@@ -4016,28 +4011,48 @@ static bool SinkInvariantGEPIndex(BinaryOperator *BinOp, LoopInfo *loopInfo,
if (UseTy &&
TLI.isLegalAddressExpression(Instruction::Add, BinOp->getOperand(0),
BinOp->getOperand(1), UseTy)) {
- // Sink it into user block.
- BinaryOperator *&InsertedOp = InsertedOps[UserBB];
- if (!InsertedOp) {
- BasicBlock::iterator InsertPt = UserBB->begin();
- while (isa<PHINode>(InsertPt)) ++InsertPt;
-
- InsertedOp =
- BinaryOperator::create(BinOp->getOpcode(), BinOp->getOperand(0),
- BinOp->getOperand(1), "", InsertPt);
- }
-
- User->replaceUsesOfWith(BinOp, InsertedOp);
+ DestBBs.insert(UserBB);
MadeChange = true;
}
}
}
}
+ // Nothing to do.
+ if (!MadeChange)
+ return false;
+
+ /// InsertedOps - Only insert a duplicate in each block once.
+ std::map<BasicBlock*, BinaryOperator*> InsertedOps;
+ for (Value::use_iterator UI = BinOp->use_begin(), E = BinOp->use_end();
+ UI != E; ) {
+ Instruction *User = cast<Instruction>(*UI);
+ BasicBlock *UserBB = User->getParent();
+
+ // Preincrement use iterator so we don't invalidate it.
+ ++UI;
+
+ // If any user in this BB wants it, replace all the uses in the BB.
+ if (DestBBs.count(UserBB)) {
+ // Sink it into user block.
+ BinaryOperator *&InsertedOp = InsertedOps[UserBB];
+ if (!InsertedOp) {
+ BasicBlock::iterator InsertPt = UserBB->begin();
+ while (isa<PHINode>(InsertPt)) ++InsertPt;
+
+ InsertedOp =
+ BinaryOperator::create(BinOp->getOpcode(), BinOp->getOperand(0),
+ BinOp->getOperand(1), "", InsertPt);
+ }
+
+ User->replaceUsesOfWith(BinOp, InsertedOp);
+ }
+ }
+
if (BinOp->use_empty())
BinOp->eraseFromParent();
- return MadeChange;
+ return true;
}