From 62b5772959741f1f1368e9a603d171caac1083f5 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 20 Apr 2006 05:39:12 +0000 Subject: [PATCH] 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 --- lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 75281d5a85d..ec1050fd72a 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) { -- 2.34.1