add a trivial fold

llvm-svn: 23764
This commit is contained in:
Chris Lattner 2005-10-17 01:07:11 +00:00
parent 17acad625c
commit eeb2bda2fa
1 changed files with 4 additions and 0 deletions

View File

@ -532,6 +532,10 @@ SDOperand DAGCombiner::visitSUB(SDNode *N) {
ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0.Val); ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0.Val);
ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1.Val); ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1.Val);
// fold (sub x, x) -> 0
if (N0 == N1)
return DAG.getConstant(0, N->getValueType(0));
// fold (sub c1, c2) -> c1-c2 // fold (sub c1, c2) -> c1-c2
if (N0C && N1C) if (N0C && N1C)
return DAG.getConstant(N0C->getValue() - N1C->getValue(), return DAG.getConstant(N0C->getValue() - N1C->getValue(),