forked from OSchip/llvm-project
reduce indentation by using early exits. No functionality change.
llvm-svn: 31660
This commit is contained in:
parent
6c9f548704
commit
eabc15c1d8
|
@ -2737,83 +2737,89 @@ bool DAGCombiner::CombineToPreIndexedLoadStore(SDNode *N) {
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ((Ptr.getOpcode() == ISD::ADD || Ptr.getOpcode() == ISD::SUB) &&
|
// If the pointer is not an add/sub, or if it doesn't have multiple uses, bail
|
||||||
Ptr.Val->use_size() > 1) {
|
// out. There is no reason to make this a preinc/predec.
|
||||||
SDOperand BasePtr;
|
if ((Ptr.getOpcode() != ISD::ADD && Ptr.getOpcode() != ISD::SUB) ||
|
||||||
SDOperand Offset;
|
Ptr.Val->hasOneUse())
|
||||||
ISD::MemIndexedMode AM = ISD::UNINDEXED;
|
return false;
|
||||||
if (TLI.getPreIndexedAddressParts(N, BasePtr, Offset, AM, DAG)) {
|
|
||||||
// Try turning it into a pre-indexed load / store except when
|
|
||||||
// 1) If N is a store and the ptr is either the same as or is a
|
|
||||||
// predecessor of the value being stored.
|
|
||||||
// 2) Another use of base ptr is a predecessor of N. If ptr is folded
|
|
||||||
// that would create a cycle.
|
|
||||||
// 3) All uses are load / store ops that use it as base ptr.
|
|
||||||
|
|
||||||
// Checking #1.
|
// Ask the target to do addressing mode selection.
|
||||||
if (!isLoad) {
|
SDOperand BasePtr;
|
||||||
SDOperand Val = cast<StoreSDNode>(N)->getValue();
|
SDOperand Offset;
|
||||||
if (Val == Ptr || Ptr.Val->isPredecessor(Val.Val))
|
ISD::MemIndexedMode AM = ISD::UNINDEXED;
|
||||||
return false;
|
if (!TLI.getPreIndexedAddressParts(N, BasePtr, Offset, AM, DAG))
|
||||||
}
|
return false;
|
||||||
|
|
||||||
|
// Try turning it into a pre-indexed load / store except when
|
||||||
|
// 1) If N is a store and the ptr is either the same as or is a
|
||||||
|
// predecessor of the value being stored.
|
||||||
|
// 2) Another use of base ptr is a predecessor of N. If ptr is folded
|
||||||
|
// that would create a cycle.
|
||||||
|
// 3) All uses are load / store ops that use it as base ptr.
|
||||||
|
|
||||||
// Now check for #2 and #3.
|
// Checking #1.
|
||||||
bool RealUse = false;
|
if (!isLoad) {
|
||||||
for (SDNode::use_iterator I = Ptr.Val->use_begin(),
|
SDOperand Val = cast<StoreSDNode>(N)->getValue();
|
||||||
E = Ptr.Val->use_end(); I != E; ++I) {
|
if (Val == Ptr || Ptr.Val->isPredecessor(Val.Val))
|
||||||
SDNode *Use = *I;
|
return false;
|
||||||
if (Use == N)
|
|
||||||
continue;
|
|
||||||
if (Use->isPredecessor(N))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!((Use->getOpcode() == ISD::LOAD &&
|
|
||||||
cast<LoadSDNode>(Use)->getBasePtr() == Ptr) ||
|
|
||||||
(Use->getOpcode() == ISD::STORE) &&
|
|
||||||
cast<StoreSDNode>(Use)->getBasePtr() == Ptr))
|
|
||||||
RealUse = true;
|
|
||||||
}
|
|
||||||
if (!RealUse)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
SDOperand Result = isLoad
|
|
||||||
? DAG.getIndexedLoad(SDOperand(N,0), BasePtr, Offset, AM)
|
|
||||||
: DAG.getIndexedStore(SDOperand(N,0), BasePtr, Offset, AM);
|
|
||||||
++PreIndexedNodes;
|
|
||||||
++NodesCombined;
|
|
||||||
DEBUG(std::cerr << "\nReplacing.4 "; N->dump();
|
|
||||||
std::cerr << "\nWith: "; Result.Val->dump(&DAG);
|
|
||||||
std::cerr << '\n');
|
|
||||||
std::vector<SDNode*> NowDead;
|
|
||||||
if (isLoad) {
|
|
||||||
DAG.ReplaceAllUsesOfValueWith(SDOperand(N, 0), Result.getValue(0),
|
|
||||||
NowDead);
|
|
||||||
DAG.ReplaceAllUsesOfValueWith(SDOperand(N, 1), Result.getValue(2),
|
|
||||||
NowDead);
|
|
||||||
} else {
|
|
||||||
DAG.ReplaceAllUsesOfValueWith(SDOperand(N, 0), Result.getValue(1),
|
|
||||||
NowDead);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Nodes can end up on the worklist more than once. Make sure we do
|
|
||||||
// not process a node that has been replaced.
|
|
||||||
for (unsigned i = 0, e = NowDead.size(); i != e; ++i)
|
|
||||||
removeFromWorkList(NowDead[i]);
|
|
||||||
// Finally, since the node is now dead, remove it from the graph.
|
|
||||||
DAG.DeleteNode(N);
|
|
||||||
|
|
||||||
// Replace the uses of Ptr with uses of the updated base value.
|
|
||||||
DAG.ReplaceAllUsesOfValueWith(Ptr, Result.getValue(isLoad ? 1 : 0),
|
|
||||||
NowDead);
|
|
||||||
removeFromWorkList(Ptr.Val);
|
|
||||||
for (unsigned i = 0, e = NowDead.size(); i != e; ++i)
|
|
||||||
removeFromWorkList(NowDead[i]);
|
|
||||||
DAG.DeleteNode(Ptr.Val);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
// Now check for #2 and #3.
|
||||||
|
bool RealUse = false;
|
||||||
|
for (SDNode::use_iterator I = Ptr.Val->use_begin(),
|
||||||
|
E = Ptr.Val->use_end(); I != E; ++I) {
|
||||||
|
SDNode *Use = *I;
|
||||||
|
if (Use == N)
|
||||||
|
continue;
|
||||||
|
if (Use->isPredecessor(N))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!((Use->getOpcode() == ISD::LOAD &&
|
||||||
|
cast<LoadSDNode>(Use)->getBasePtr() == Ptr) ||
|
||||||
|
(Use->getOpcode() == ISD::STORE) &&
|
||||||
|
cast<StoreSDNode>(Use)->getBasePtr() == Ptr))
|
||||||
|
RealUse = true;
|
||||||
|
}
|
||||||
|
if (!RealUse)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
SDOperand Result;
|
||||||
|
if (isLoad)
|
||||||
|
Result = DAG.getIndexedLoad(SDOperand(N,0), BasePtr, Offset, AM);
|
||||||
|
else
|
||||||
|
Result = DAG.getIndexedStore(SDOperand(N,0), BasePtr, Offset, AM);
|
||||||
|
++PreIndexedNodes;
|
||||||
|
++NodesCombined;
|
||||||
|
DEBUG(std::cerr << "\nReplacing.4 "; N->dump();
|
||||||
|
std::cerr << "\nWith: "; Result.Val->dump(&DAG);
|
||||||
|
std::cerr << '\n');
|
||||||
|
std::vector<SDNode*> NowDead;
|
||||||
|
if (isLoad) {
|
||||||
|
DAG.ReplaceAllUsesOfValueWith(SDOperand(N, 0), Result.getValue(0),
|
||||||
|
NowDead);
|
||||||
|
DAG.ReplaceAllUsesOfValueWith(SDOperand(N, 1), Result.getValue(2),
|
||||||
|
NowDead);
|
||||||
|
} else {
|
||||||
|
DAG.ReplaceAllUsesOfValueWith(SDOperand(N, 0), Result.getValue(1),
|
||||||
|
NowDead);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nodes can end up on the worklist more than once. Make sure we do
|
||||||
|
// not process a node that has been replaced.
|
||||||
|
for (unsigned i = 0, e = NowDead.size(); i != e; ++i)
|
||||||
|
removeFromWorkList(NowDead[i]);
|
||||||
|
// Finally, since the node is now dead, remove it from the graph.
|
||||||
|
DAG.DeleteNode(N);
|
||||||
|
|
||||||
|
// Replace the uses of Ptr with uses of the updated base value.
|
||||||
|
DAG.ReplaceAllUsesOfValueWith(Ptr, Result.getValue(isLoad ? 1 : 0),
|
||||||
|
NowDead);
|
||||||
|
removeFromWorkList(Ptr.Val);
|
||||||
|
for (unsigned i = 0, e = NowDead.size(); i != e; ++i)
|
||||||
|
removeFromWorkList(NowDead[i]);
|
||||||
|
DAG.DeleteNode(Ptr.Val);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// CombineToPostIndexedLoadStore - Try combine a load / store with a
|
/// CombineToPostIndexedLoadStore - Try combine a load / store with a
|
||||||
|
@ -2844,99 +2850,100 @@ bool DAGCombiner::CombineToPostIndexedLoadStore(SDNode *N) {
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (Ptr.Val->use_size() > 1) {
|
if (!Ptr.Val->hasOneUse())
|
||||||
for (SDNode::use_iterator I = Ptr.Val->use_begin(),
|
return false;
|
||||||
E = Ptr.Val->use_end(); I != E; ++I) {
|
|
||||||
SDNode *Op = *I;
|
for (SDNode::use_iterator I = Ptr.Val->use_begin(),
|
||||||
if (Op == N ||
|
E = Ptr.Val->use_end(); I != E; ++I) {
|
||||||
(Op->getOpcode() != ISD::ADD && Op->getOpcode() != ISD::SUB))
|
SDNode *Op = *I;
|
||||||
|
if (Op == N ||
|
||||||
|
(Op->getOpcode() != ISD::ADD && Op->getOpcode() != ISD::SUB))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
SDOperand BasePtr;
|
||||||
|
SDOperand Offset;
|
||||||
|
ISD::MemIndexedMode AM = ISD::UNINDEXED;
|
||||||
|
if (TLI.getPostIndexedAddressParts(N, Op, BasePtr, Offset, AM, DAG)) {
|
||||||
|
if (Ptr == Offset)
|
||||||
|
std::swap(BasePtr, Offset);
|
||||||
|
if (Ptr != BasePtr)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
SDOperand BasePtr;
|
// Try turning it into a post-indexed load / store except when
|
||||||
SDOperand Offset;
|
// 1) All uses are load / store ops that use it as base ptr.
|
||||||
ISD::MemIndexedMode AM = ISD::UNINDEXED;
|
// 2) Op must be independent of N, i.e. Op is neither a predecessor
|
||||||
if (TLI.getPostIndexedAddressParts(N, Op, BasePtr, Offset, AM, DAG)) {
|
// nor a successor of N. Otherwise, if Op is folded that would
|
||||||
if (Ptr == Offset)
|
// create a cycle.
|
||||||
std::swap(BasePtr, Offset);
|
|
||||||
if (Ptr != BasePtr)
|
// Check for #1.
|
||||||
|
bool TryNext = false;
|
||||||
|
for (SDNode::use_iterator II = BasePtr.Val->use_begin(),
|
||||||
|
EE = BasePtr.Val->use_end(); II != EE; ++II) {
|
||||||
|
SDNode *Use = *II;
|
||||||
|
if (Use == Ptr.Val)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Try turning it into a post-indexed load / store except when
|
// If all the uses are load / store addresses, then don't do the
|
||||||
// 1) All uses are load / store ops that use it as base ptr.
|
// transformation.
|
||||||
// 2) Op must be independent of N, i.e. Op is neither a predecessor
|
if (Use->getOpcode() == ISD::ADD || Use->getOpcode() == ISD::SUB){
|
||||||
// nor a successor of N. Otherwise, if Op is folded that would
|
bool RealUse = false;
|
||||||
// create a cycle.
|
for (SDNode::use_iterator III = Use->use_begin(),
|
||||||
|
EEE = Use->use_end(); III != EEE; ++III) {
|
||||||
|
SDNode *UseUse = *III;
|
||||||
|
if (!((UseUse->getOpcode() == ISD::LOAD &&
|
||||||
|
cast<LoadSDNode>(UseUse)->getBasePtr().Val == Use) ||
|
||||||
|
(UseUse->getOpcode() == ISD::STORE) &&
|
||||||
|
cast<StoreSDNode>(UseUse)->getBasePtr().Val == Use))
|
||||||
|
RealUse = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Check for #1.
|
if (!RealUse) {
|
||||||
bool TryNext = false;
|
TryNext = true;
|
||||||
for (SDNode::use_iterator II = BasePtr.Val->use_begin(),
|
break;
|
||||||
EE = BasePtr.Val->use_end(); II != EE; ++II) {
|
|
||||||
SDNode *Use = *II;
|
|
||||||
if (Use == Ptr.Val)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// If all the uses are load / store addresses, then don't do the
|
|
||||||
// transformation.
|
|
||||||
if (Use->getOpcode() == ISD::ADD || Use->getOpcode() == ISD::SUB){
|
|
||||||
bool RealUse = false;
|
|
||||||
for (SDNode::use_iterator III = Use->use_begin(),
|
|
||||||
EEE = Use->use_end(); III != EEE; ++III) {
|
|
||||||
SDNode *UseUse = *III;
|
|
||||||
if (!((UseUse->getOpcode() == ISD::LOAD &&
|
|
||||||
cast<LoadSDNode>(UseUse)->getBasePtr().Val == Use) ||
|
|
||||||
(UseUse->getOpcode() == ISD::STORE) &&
|
|
||||||
cast<StoreSDNode>(UseUse)->getBasePtr().Val == Use))
|
|
||||||
RealUse = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!RealUse) {
|
|
||||||
TryNext = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (TryNext)
|
}
|
||||||
continue;
|
if (TryNext)
|
||||||
|
continue;
|
||||||
|
|
||||||
// Check for #2
|
// Check for #2
|
||||||
if (!Op->isPredecessor(N) && !N->isPredecessor(Op)) {
|
if (!Op->isPredecessor(N) && !N->isPredecessor(Op)) {
|
||||||
SDOperand Result = isLoad
|
SDOperand Result = isLoad
|
||||||
? DAG.getIndexedLoad(SDOperand(N,0), BasePtr, Offset, AM)
|
? DAG.getIndexedLoad(SDOperand(N,0), BasePtr, Offset, AM)
|
||||||
: DAG.getIndexedStore(SDOperand(N,0), BasePtr, Offset, AM);
|
: DAG.getIndexedStore(SDOperand(N,0), BasePtr, Offset, AM);
|
||||||
++PostIndexedNodes;
|
++PostIndexedNodes;
|
||||||
++NodesCombined;
|
++NodesCombined;
|
||||||
DEBUG(std::cerr << "\nReplacing.5 "; N->dump();
|
DEBUG(std::cerr << "\nReplacing.5 "; N->dump();
|
||||||
std::cerr << "\nWith: "; Result.Val->dump(&DAG);
|
std::cerr << "\nWith: "; Result.Val->dump(&DAG);
|
||||||
std::cerr << '\n');
|
std::cerr << '\n');
|
||||||
std::vector<SDNode*> NowDead;
|
std::vector<SDNode*> NowDead;
|
||||||
if (isLoad) {
|
if (isLoad) {
|
||||||
DAG.ReplaceAllUsesOfValueWith(SDOperand(N, 0), Result.getValue(0),
|
DAG.ReplaceAllUsesOfValueWith(SDOperand(N, 0), Result.getValue(0),
|
||||||
NowDead);
|
NowDead);
|
||||||
DAG.ReplaceAllUsesOfValueWith(SDOperand(N, 1), Result.getValue(2),
|
DAG.ReplaceAllUsesOfValueWith(SDOperand(N, 1), Result.getValue(2),
|
||||||
NowDead);
|
NowDead);
|
||||||
} else {
|
} else {
|
||||||
DAG.ReplaceAllUsesOfValueWith(SDOperand(N, 0), Result.getValue(1),
|
DAG.ReplaceAllUsesOfValueWith(SDOperand(N, 0), Result.getValue(1),
|
||||||
NowDead);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Nodes can end up on the worklist more than once. Make sure we do
|
|
||||||
// not process a node that has been replaced.
|
|
||||||
for (unsigned i = 0, e = NowDead.size(); i != e; ++i)
|
|
||||||
removeFromWorkList(NowDead[i]);
|
|
||||||
// Finally, since the node is now dead, remove it from the graph.
|
|
||||||
DAG.DeleteNode(N);
|
|
||||||
|
|
||||||
// Replace the uses of Use with uses of the updated base value.
|
|
||||||
DAG.ReplaceAllUsesOfValueWith(SDOperand(Op, 0),
|
|
||||||
Result.getValue(isLoad ? 1 : 0),
|
|
||||||
NowDead);
|
NowDead);
|
||||||
removeFromWorkList(Op);
|
|
||||||
for (unsigned i = 0, e = NowDead.size(); i != e; ++i)
|
|
||||||
removeFromWorkList(NowDead[i]);
|
|
||||||
DAG.DeleteNode(Op);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Nodes can end up on the worklist more than once. Make sure we do
|
||||||
|
// not process a node that has been replaced.
|
||||||
|
for (unsigned i = 0, e = NowDead.size(); i != e; ++i)
|
||||||
|
removeFromWorkList(NowDead[i]);
|
||||||
|
// Finally, since the node is now dead, remove it from the graph.
|
||||||
|
DAG.DeleteNode(N);
|
||||||
|
|
||||||
|
// Replace the uses of Use with uses of the updated base value.
|
||||||
|
DAG.ReplaceAllUsesOfValueWith(SDOperand(Op, 0),
|
||||||
|
Result.getValue(isLoad ? 1 : 0),
|
||||||
|
NowDead);
|
||||||
|
removeFromWorkList(Op);
|
||||||
|
for (unsigned i = 0, e = NowDead.size(); i != e; ++i)
|
||||||
|
removeFromWorkList(NowDead[i]);
|
||||||
|
DAG.DeleteNode(Op);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue