summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-04-20 05:39:12 +0000
committerChris Lattner <sabre@nondot.org>2006-04-20 05:39:12 +0000
commit62b5772959741f1f1368e9a603d171caac1083f5 (patch)
tree16e53a963bf49309d5f0a0b825f7db5c94db86c1
parent1ef81aff91c64f8d97e5780f095260fcf8e9dd7f (diff)
downloadllvm-62b5772959741f1f1368e9a603d171caac1083f5.tar.gz
llvm-62b5772959741f1f1368e9a603d171caac1083f5.tar.bz2
llvm-62b5772959741f1f1368e9a603d171caac1083f5.tar.xz
Implement folding of a bunch of binops with undef
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27863 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAG.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 75281d5a85..ec1050fd72 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -1367,6 +1367,52 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
}
}
}
+
+ // Canonicalize an UNDEF to the RHS, even over a constant.
+ if (N1.getOpcode() == ISD::UNDEF) {
+ if (isCommutativeBinOp(Opcode)) {
+ std::swap(N1, N2);
+ } else {
+ switch (Opcode) {
+ case ISD::FP_ROUND_INREG:
+ case ISD::SIGN_EXTEND_INREG:
+ case ISD::SUB:
+ case ISD::FSUB:
+ case ISD::FDIV:
+ case ISD::FREM:
+ return N1; // fold op(undef, arg2) -> undef
+ case ISD::UDIV:
+ case ISD::SDIV:
+ case ISD::UREM:
+ case ISD::SREM:
+ return getConstant(0, VT); // fold op(undef, arg2) -> 0
+ }
+ }
+ }
+
+ // Fold a bunch of operators that
+ if (N2.getOpcode() == ISD::UNDEF) {
+ switch (Opcode) {
+ case ISD::ADD:
+ case ISD::SUB:
+ case ISD::FADD:
+ case ISD::FSUB:
+ case ISD::FMUL:
+ case ISD::FDIV:
+ case ISD::FREM:
+ case ISD::UDIV:
+ case ISD::SDIV:
+ case ISD::UREM:
+ case ISD::SREM:
+ case ISD::XOR:
+ return N2; // fold op(arg1, undef) -> undef
+ case ISD::MUL:
+ case ISD::AND:
+ return getConstant(0, VT); // fold op(arg1, undef) -> 0
+ case ISD::OR:
+ return getConstant(MVT::getIntVTBitMask(VT), VT);
+ }
+ }
// Finally, fold operations that do not require constants.
switch (Opcode) {