summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
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
commitbc1b262725e2dae907e8b5511ce3e94b6a55a769 (patch)
tree18af9d6c6a898aa4d9dde7fc481675127ebe8451 /llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
parent499abb5695314ca7f9667fbf2f92b68c745810a4 (diff)
downloadbcm5719-llvm-bc1b262725e2dae907e8b5511ce3e94b6a55a769.tar.gz
bcm5719-llvm-bc1b262725e2dae907e8b5511ce3e94b6a55a769.zip
Implement folding of a bunch of binops with undef
llvm-svn: 27863
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 75281d5a85d..ec1050fd72a 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/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) {
OpenPOWER on IntegriCloud