1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 19:52:54 +01:00

Make legalize a bit more efficient, and canonicalize sub X, C -> add X, -C

llvm-svn: 21882
This commit is contained in:
Chris Lattner 2005-05-12 00:17:04 +00:00
parent 71bcc67a0f
commit b38ffd7fbf
2 changed files with 12 additions and 8 deletions

View File

@ -323,8 +323,11 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
// There is no need to legalize the size argument (Operand #1) // There is no need to legalize the size argument (Operand #1)
if (Tmp1 != Node->getOperand(0)) if (Tmp1 != Node->getOperand(0))
Result = DAG.getNode(Node->getOpcode(), MVT::Other, Tmp1, Node->setAdjCallChain(Tmp1);
Node->getOperand(1)); // Note that we do not create new ADJCALLSTACK DOWN/UP nodes here. These
// nodes are treated specially and are mutated in place. This makes the dag
// legalization process more efficient and also makes libcall insertion
// easier.
break; break;
case ISD::DYNAMIC_STACKALLOC: case ISD::DYNAMIC_STACKALLOC:
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.

View File

@ -916,7 +916,7 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
break; break;
case ISD::SUB: case ISD::SUB:
if (!C2) return N1; // sub X, 0 -> X if (!C2) return N1; // sub X, 0 -> X
break; return getNode(ISD::ADD, VT, N1, getConstant(-C2, VT));
case ISD::MUL: case ISD::MUL:
if (!C2) return N2; // mul X, 0 -> 0 if (!C2) return N2; // mul X, 0 -> 0
if (N2C->isAllOnesValue()) // mul X, -1 -> 0-X if (N2C->isAllOnesValue()) // mul X, -1 -> 0-X
@ -1194,13 +1194,13 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
// Memoize this node if possible. // Memoize this node if possible.
SDNode *N; SDNode *N;
if (Opcode != ISD::ADJCALLSTACKDOWN) { if (Opcode != ISD::ADJCALLSTACKDOWN && Opcode != ISD::ADJCALLSTACKUP) {
SDNode *&BON = BinaryOps[std::make_pair(Opcode, std::make_pair(N1, N2))]; SDNode *&BON = BinaryOps[std::make_pair(Opcode, std::make_pair(N1, N2))];
if (BON) return SDOperand(BON, 0); if (BON) return SDOperand(BON, 0);
BON = N = new SDNode(Opcode, N1, N2); BON = N = new SDNode(Opcode, N1, N2);
} else { } else {
N = new SDNode(ISD::ADJCALLSTACKDOWN, N1, N2); N = new SDNode(Opcode, N1, N2);
} }
@ -1213,11 +1213,12 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
return SDOperand(N, 0); return SDOperand(N, 0);
} }
// setAdjCallChain - This method changes the token chain of an ADJCALLSTACKDOWN // setAdjCallChain - This method changes the token chain of an
// node to be the specified operand. // ADJCALLSTACKDOWN/UP node to be the specified operand.
void SDNode::setAdjCallChain(SDOperand N) { void SDNode::setAdjCallChain(SDOperand N) {
assert(N.getValueType() == MVT::Other); assert(N.getValueType() == MVT::Other);
assert(getOpcode() == ISD::ADJCALLSTACKDOWN && "Cannot adjust this node!"); assert((getOpcode() == ISD::ADJCALLSTACKDOWN ||
getOpcode() == ISD::ADJCALLSTACKUP) && "Cannot adjust this node!");
Operands[0].Val->removeUser(this); Operands[0].Val->removeUser(this);
Operands[0] = N; Operands[0] = N;