[llvm-commits] [llvm] r37851 - /llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Dan Gohman
djg at cray.com
Tue Jul 3 07:03:58 PDT 2007
Author: djg
Date: Tue Jul 3 09:03:57 2007
New Revision: 37851
URL: http://llvm.org/viewvc/llvm-project?rev=37851&view=rev
Log:
Fix several over-aggressive folds for undef nodes in dagcombine, to
follow the rules for undef used in instcombine.
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=37851&r1=37850&r2=37851&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Tue Jul 3 09:03:57 2007
@@ -854,6 +854,9 @@
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 @@
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 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 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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
// 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 @@
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 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 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 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 @@
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 @@
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 @@
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 @@
}
}
- // 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 @@
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();
}
More information about the llvm-commits
mailing list