1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 19:42:54 +02:00

Fix several over-aggressive folds for undef nodes in dagcombine, to

follow the rules for undef used in instcombine.

llvm-svn: 37851
This commit is contained in:
Dan Gohman 2007-07-03 14:03:57 +00:00
parent 5c63a5b487
commit d2d18267e6

View File

@ -854,6 +854,9 @@ SDOperand DAGCombiner::visitADD(SDNode *N) {
SDOperand FoldedVOp = SimplifyVBinOp(N);
if (FoldedVOp.Val) return FoldedVOp;
// fold (add x, undef) -> undef
if (N1.getOpcode() == ISD::UNDEF)
return N1;
// fold (add c1, c2) -> c1+c2
if (N0C && N1C)
return DAG.getNode(ISD::ADD, VT, N0, N1);
@ -925,10 +928,6 @@ SDOperand DAGCombiner::visitADD(SDNode *N) {
if (Result.Val) return Result;
}
// If either operand is undef, the result is undef
if (N0.getOpcode() == ISD::UNDEF || N1.getOpcode() == ISD::UNDEF)
return DAG.getNode(ISD::UNDEF, VT);
return SDOperand();
}
@ -1029,7 +1028,7 @@ SDOperand DAGCombiner::visitSUB(SDNode *N) {
SDOperand Result = combineSelectAndUse(N, N1, N0, DAG);
if (Result.Val) return Result;
}
// If either operand is undef, the result is undef
// If either operand of a sub is undef, the result is undef
if (N0.getOpcode() == ISD::UNDEF || N1.getOpcode() == ISD::UNDEF)
return DAG.getNode(ISD::UNDEF, VT);
@ -1047,6 +1046,9 @@ SDOperand DAGCombiner::visitMUL(SDNode *N) {
SDOperand FoldedVOp = SimplifyVBinOp(N);
if (FoldedVOp.Val) return FoldedVOp;
// fold (mul x, undef) -> 0
if (N1.getOpcode() == ISD::UNDEF)
return DAG.getConstant(0, VT);
// fold (mul c1, c2) -> c1*c2
if (N0C && N1C)
return DAG.getNode(ISD::MUL, VT, N0, N1);
@ -1112,10 +1114,6 @@ SDOperand DAGCombiner::visitMUL(SDNode *N) {
if (RMUL.Val != 0)
return RMUL;
// If either operand is undef, the result is undef
if (N0.getOpcode() == ISD::UNDEF || N1.getOpcode() == ISD::UNDEF)
return DAG.getNode(ISD::UNDEF, VT);
return SDOperand();
}
@ -1185,9 +1183,12 @@ SDOperand DAGCombiner::visitSDIV(SDNode *N) {
if (Op.Val) return Op;
}
// If either operand is undef, the result is undef
if (N0.getOpcode() == ISD::UNDEF || N1.getOpcode() == ISD::UNDEF)
return DAG.getNode(ISD::UNDEF, VT);
// undef / X -> 0
if (N0.getOpcode() == ISD::UNDEF)
return DAG.getConstant(0, VT);
// X / undef -> undef
if (N1.getOpcode() == ISD::UNDEF)
return N1;
return SDOperand();
}
@ -1230,9 +1231,12 @@ SDOperand DAGCombiner::visitUDIV(SDNode *N) {
if (Op.Val) return Op;
}
// If either operand is undef, the result is undef
if (N0.getOpcode() == ISD::UNDEF || N1.getOpcode() == ISD::UNDEF)
return DAG.getNode(ISD::UNDEF, VT);
// undef / X -> 0
if (N0.getOpcode() == ISD::UNDEF)
return DAG.getConstant(0, VT);
// X / undef -> undef
if (N1.getOpcode() == ISD::UNDEF)
return N1;
return SDOperand();
}
@ -1265,9 +1269,12 @@ SDOperand DAGCombiner::visitSREM(SDNode *N) {
return Sub;
}
// If either operand is undef, the result is undef
if (N0.getOpcode() == ISD::UNDEF || N1.getOpcode() == ISD::UNDEF)
return DAG.getNode(ISD::UNDEF, VT);
// undef % X -> 0
if (N0.getOpcode() == ISD::UNDEF)
return DAG.getConstant(0, VT);
// X % undef -> undef
if (N1.getOpcode() == ISD::UNDEF)
return N1;
return SDOperand();
}
@ -1307,9 +1314,12 @@ SDOperand DAGCombiner::visitUREM(SDNode *N) {
return Sub;
}
// If either operand is undef, the result is undef
if (N0.getOpcode() == ISD::UNDEF || N1.getOpcode() == ISD::UNDEF)
return DAG.getNode(ISD::UNDEF, VT);
// undef % X -> 0
if (N0.getOpcode() == ISD::UNDEF)
return DAG.getConstant(0, VT);
// X % undef -> undef
if (N1.getOpcode() == ISD::UNDEF)
return N1;
return SDOperand();
}
@ -1328,9 +1338,9 @@ SDOperand DAGCombiner::visitMULHS(SDNode *N) {
return DAG.getNode(ISD::SRA, N0.getValueType(), N0,
DAG.getConstant(MVT::getSizeInBits(N0.getValueType())-1,
TLI.getShiftAmountTy()));
// If either operand is undef, the result is undef
if (N0.getOpcode() == ISD::UNDEF || N1.getOpcode() == ISD::UNDEF)
return DAG.getNode(ISD::UNDEF, VT);
// fold (mulhs x, undef) -> 0
if (N1.getOpcode() == ISD::UNDEF)
return DAG.getConstant(0, VT);
return SDOperand();
}
@ -1347,9 +1357,9 @@ SDOperand DAGCombiner::visitMULHU(SDNode *N) {
// fold (mulhu x, 1) -> 0
if (N1C && N1C->getValue() == 1)
return DAG.getConstant(0, N0.getValueType());
// If either operand is undef, the result is undef
if (N0.getOpcode() == ISD::UNDEF || N1.getOpcode() == ISD::UNDEF)
return DAG.getNode(ISD::UNDEF, VT);
// fold (mulhu x, undef) -> 0
if (N1.getOpcode() == ISD::UNDEF)
return DAG.getConstant(0, VT);
return SDOperand();
}
@ -1390,10 +1400,6 @@ SDOperand DAGCombiner::SimplifyBinOpWithSameOpcodeHands(SDNode *N) {
return DAG.getNode(N0.getOpcode(), VT, ORNode, N0.getOperand(1));
}
// If either operand is undef, the result is undef
if (N0.getOpcode() == ISD::UNDEF || N1.getOpcode() == ISD::UNDEF)
return DAG.getNode(ISD::UNDEF, VT);
return SDOperand();
}
@ -1409,6 +1415,9 @@ SDOperand DAGCombiner::visitAND(SDNode *N) {
SDOperand FoldedVOp = SimplifyVBinOp(N);
if (FoldedVOp.Val) return FoldedVOp;
// fold (and x, undef) -> 0
if (N1.getOpcode() == ISD::UNDEF)
return DAG.getConstant(0, VT);
// fold (and c1, c2) -> c1&c2
if (N0C && N1C)
return DAG.getNode(ISD::AND, VT, N0, N1);
@ -1594,6 +1603,9 @@ SDOperand DAGCombiner::visitOR(SDNode *N) {
SDOperand FoldedVOp = SimplifyVBinOp(N);
if (FoldedVOp.Val) return FoldedVOp;
// fold (or x, undef) -> -1
if (N1.getOpcode() == ISD::UNDEF)
return DAG.getConstant(-1, VT);
// fold (or c1, c2) -> c1|c2
if (N0C && N1C)
return DAG.getNode(ISD::OR, VT, N0, N1);
@ -1877,6 +1889,9 @@ SDOperand DAGCombiner::visitXOR(SDNode *N) {
SDOperand FoldedVOp = SimplifyVBinOp(N);
if (FoldedVOp.Val) return FoldedVOp;
// fold (xor x, undef) -> undef
if (N1.getOpcode() == ISD::UNDEF)
return N1;
// fold (xor c1, c2) -> c1^c2
if (N0C && N1C)
return DAG.getNode(ISD::XOR, VT, N0, N1);
@ -3009,10 +3024,6 @@ SDOperand DAGCombiner::visitFADD(SDNode *N) {
return DAG.getNode(ISD::FADD, VT, N0.getOperand(0),
DAG.getNode(ISD::FADD, VT, N0.getOperand(1), N1));
// If either operand is undef, the result is undef
if (N0.getOpcode() == ISD::UNDEF || N1.getOpcode() == ISD::UNDEF)
return DAG.getNode(ISD::UNDEF, VT);
return SDOperand();
}
@ -3040,10 +3051,6 @@ SDOperand DAGCombiner::visitFSUB(SDNode *N) {
if (isNegatibleForFree(N1))
return DAG.getNode(ISD::FADD, VT, N0, GetNegatedExpression(N1, DAG));
// If either operand is undef, the result is undef
if (N0.getOpcode() == ISD::UNDEF || N1.getOpcode() == ISD::UNDEF)
return DAG.getNode(ISD::UNDEF, VT);
return SDOperand();
}
@ -3088,10 +3095,6 @@ SDOperand DAGCombiner::visitFMUL(SDNode *N) {
return DAG.getNode(ISD::FMUL, VT, N0.getOperand(0),
DAG.getNode(ISD::FMUL, VT, N0.getOperand(1), N1));
// If either operand is undef, the result is undef
if (N0.getOpcode() == ISD::UNDEF || N1.getOpcode() == ISD::UNDEF)
return DAG.getNode(ISD::UNDEF, VT);
return SDOperand();
}
@ -3122,10 +3125,6 @@ SDOperand DAGCombiner::visitFDIV(SDNode *N) {
}
}
// If either operand is undef, the result is undef
if (N0.getOpcode() == ISD::UNDEF || N1.getOpcode() == ISD::UNDEF)
return DAG.getNode(ISD::UNDEF, VT);
return SDOperand();
}
@ -3140,10 +3139,6 @@ SDOperand DAGCombiner::visitFREM(SDNode *N) {
if (N0CFP && N1CFP)
return DAG.getNode(ISD::FREM, VT, N0, N1);
// If either operand is undef, the result is undef
if (N0.getOpcode() == ISD::UNDEF || N1.getOpcode() == ISD::UNDEF)
return DAG.getNode(ISD::UNDEF, VT);
return SDOperand();
}