[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Nate Begeman natebegeman at mac.com
Tue Apr 5 17:24:05 PDT 2005



Changes in directory llvm/lib/CodeGen/SelectionDAG:

LegalizeDAG.cpp updated: 1.73 -> 1.74
---
Log message:

Expand SREM and UREM for targets that claim not to have them, like PowerPC


---
Diffs of the changes:  (+25 -2)

 LegalizeDAG.cpp |   27 +++++++++++++++++++++++++--
 1 files changed, 25 insertions(+), 2 deletions(-)


Index: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.73 llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.74
--- llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.73	Sun Apr  3 19:57:08 2005
+++ llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp	Tue Apr  5 19:23:54 2005
@@ -854,8 +854,6 @@
   case ISD::MUL:
   case ISD::UDIV:
   case ISD::SDIV:
-  case ISD::UREM:
-  case ISD::SREM:
   case ISD::AND:
   case ISD::OR:
   case ISD::XOR:
@@ -868,6 +866,31 @@
         Tmp2 != Node->getOperand(1))
       Result = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1,Tmp2);
     break;
+  
+  case ISD::UREM:
+  case ISD::SREM:
+    Tmp1 = LegalizeOp(Node->getOperand(0));   // LHS
+    Tmp2 = LegalizeOp(Node->getOperand(1));   // RHS
+    switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
+    case TargetLowering::Legal:
+      if (Tmp1 != Node->getOperand(0) ||
+          Tmp2 != Node->getOperand(1))
+        Result = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1, 
+                             Tmp2);
+      break;
+    case TargetLowering::Promote:
+    case TargetLowering::Custom:
+      assert(0 && "Cannot promote/custom handle this yet!");
+    case TargetLowering::Expand: {
+      MVT::ValueType VT = Node->getValueType(0);
+      unsigned Opc = (Node->getOpcode() == ISD::UREM) ? ISD::UDIV : ISD::SDIV;
+      Result = DAG.getNode(Opc, VT, Tmp1, Tmp2);
+      Result = DAG.getNode(ISD::MUL, VT, Result, Tmp2);
+      Result = DAG.getNode(ISD::SUB, VT, Tmp1, Result);
+      }
+      break;
+    }
+    break;
 
     // Unary operators
   case ISD::FABS:






More information about the llvm-commits mailing list