[llvm-commits] [llvm] r56552 - /llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Bill Wendling isanbard at gmail.com
Wed Sep 24 03:16:24 PDT 2008


Author: void
Date: Wed Sep 24 05:16:24 2008
New Revision: 56552

URL: http://llvm.org/viewvc/llvm-project?rev=56552&view=rev
Log:
Forgot this part with my last patch. Sorry about the breakage.

Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=56552&r1=56551&r2=56552&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Wed Sep 24 05:16:24 2008
@@ -2271,6 +2271,42 @@
   return SDValue(N, 0);
 }
 
+SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode,
+                                             MVT VT,
+                                             ConstantSDNode *Cst1,
+                                             ConstantSDNode *Cst2) {
+  const APInt &C1 = Cst1->getAPIntValue(), &C2 = Cst2->getAPIntValue();
+
+  switch (Opcode) {
+  case ISD::ADD:  return getConstant(C1 + C2, VT);
+  case ISD::SUB:  return getConstant(C1 - C2, VT);
+  case ISD::MUL:  return getConstant(C1 * C2, VT);
+  case ISD::UDIV:
+    if (C2.getBoolValue()) return getConstant(C1.udiv(C2), VT);
+    break;
+  case ISD::UREM:
+    if (C2.getBoolValue()) return getConstant(C1.urem(C2), VT);
+    break;
+  case ISD::SDIV:
+    if (C2.getBoolValue()) return getConstant(C1.sdiv(C2), VT);
+    break;
+  case ISD::SREM:
+    if (C2.getBoolValue()) return getConstant(C1.srem(C2), VT);
+    break;
+  case ISD::AND:  return getConstant(C1 & C2, VT);
+  case ISD::OR:   return getConstant(C1 | C2, VT);
+  case ISD::XOR:  return getConstant(C1 ^ C2, VT);
+  case ISD::SHL:  return getConstant(C1 << C2, VT);
+  case ISD::SRL:  return getConstant(C1.lshr(C2), VT);
+  case ISD::SRA:  return getConstant(C1.ashr(C2), VT);
+  case ISD::ROTL: return getConstant(C1.rotl(C2), VT);
+  case ISD::ROTR: return getConstant(C1.rotr(C2), VT);
+  default: break;
+  }
+
+  return SDValue();
+}
+
 SDValue SelectionDAG::getNode(unsigned Opcode, MVT VT,
                               SDValue N1, SDValue N2) {
   ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1.getNode());
@@ -2457,33 +2493,8 @@
 
   if (N1C) {
     if (N2C) {
-      const APInt &C1 = N1C->getAPIntValue(), &C2 = N2C->getAPIntValue();
-      switch (Opcode) {
-      case ISD::ADD: return getConstant(C1 + C2, VT);
-      case ISD::SUB: return getConstant(C1 - C2, VT);
-      case ISD::MUL: return getConstant(C1 * C2, VT);
-      case ISD::UDIV:
-        if (C2.getBoolValue()) return getConstant(C1.udiv(C2), VT);
-        break;
-      case ISD::UREM :
-        if (C2.getBoolValue()) return getConstant(C1.urem(C2), VT);
-        break;
-      case ISD::SDIV :
-        if (C2.getBoolValue()) return getConstant(C1.sdiv(C2), VT);
-        break;
-      case ISD::SREM :
-        if (C2.getBoolValue()) return getConstant(C1.srem(C2), VT);
-        break;
-      case ISD::AND  : return getConstant(C1 & C2, VT);
-      case ISD::OR   : return getConstant(C1 | C2, VT);
-      case ISD::XOR  : return getConstant(C1 ^ C2, VT);
-      case ISD::SHL  : return getConstant(C1 << C2, VT);
-      case ISD::SRL  : return getConstant(C1.lshr(C2), VT);
-      case ISD::SRA  : return getConstant(C1.ashr(C2), VT);
-      case ISD::ROTL : return getConstant(C1.rotl(C2), VT);
-      case ISD::ROTR : return getConstant(C1.rotr(C2), VT);
-      default: break;
-      }
+      SDValue SV = FoldConstantArithmetic(Opcode, VT, N1C, N2C);
+      if (SV.getNode()) return SV;
     } else {      // Cannonicalize constant to RHS if commutative
       if (isCommutativeBinOp(Opcode)) {
         std::swap(N1C, N2C);





More information about the llvm-commits mailing list