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

Chris Lattner lattner at cs.uiuc.edu
Fri Apr 1 19:39:09 PST 2005



Changes in directory llvm/lib/CodeGen/SelectionDAG:

LegalizeDAG.cpp updated: 1.67 -> 1.68
---
Log message:

Turn expanded shift operations into (e.g.) SHL_PARTS if the target supports it.


---
Diffs of the changes:  (+39 -9)

 LegalizeDAG.cpp |   48 +++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 39 insertions(+), 9 deletions(-)


Index: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.67 llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.68
--- llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.67	Fri Apr  1 21:22:40 2005
+++ llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp	Fri Apr  1 21:38:53 2005
@@ -125,8 +125,8 @@
                           SDOperand Source);
   bool ExpandShift(unsigned Opc, SDOperand Op, SDOperand Amt,
                    SDOperand &Lo, SDOperand &Hi);
-  void ExpandAddSub(bool isAdd, SDOperand Op, SDOperand Amt,
-                    SDOperand &Lo, SDOperand &Hi);
+  void ExpandByParts(unsigned NodeOp, SDOperand Op, SDOperand Amt,
+                     SDOperand &Lo, SDOperand &Hi);
 
   SDOperand getIntPtrConstant(uint64_t Val) {
     return DAG.getConstant(Val, TLI.getPointerTy());
@@ -1288,8 +1288,9 @@
 
 /// ExpandAddSub - Find a clever way to expand this add operation into
 /// subcomponents.
-void SelectionDAGLegalize::ExpandAddSub(bool isAdd, SDOperand LHS,SDOperand RHS,
-                                        SDOperand &Lo, SDOperand &Hi) {
+void SelectionDAGLegalize::
+ExpandByParts(unsigned NodeOp, SDOperand LHS, SDOperand RHS,
+              SDOperand &Lo, SDOperand &Hi) {
   // Expand the subcomponents.
   SDOperand LHSL, LHSH, RHSL, RHSH;
   ExpandOp(LHS, LHSL, LHSH);
@@ -1297,13 +1298,12 @@
 
   // Convert this add to the appropriate ADDC pair.  The low part has no carry
   // in.
-  unsigned Opc = isAdd ? ISD::ADD_PARTS : ISD::SUB_PARTS;
   std::vector<SDOperand> Ops;
   Ops.push_back(LHSL);
   Ops.push_back(LHSH);
   Ops.push_back(RHSL);
   Ops.push_back(RHSH);
-  Lo = DAG.getNode(Opc, LHSL.getValueType(), Ops);
+  Lo = DAG.getNode(NodeOp, LHSL.getValueType(), Ops);
   Hi = Lo.getValue(1);
 }
 
@@ -1313,6 +1313,10 @@
 /// low-parts expanded into Lo and Hi.
 bool SelectionDAGLegalize::ExpandShift(unsigned Opc, SDOperand Op,SDOperand Amt,
                                        SDOperand &Lo, SDOperand &Hi) {
+  // FIXME: This code is buggy, disable it for now.  Note that we should at
+  // least handle the case when Amt is an immediate here.
+  return false;
+
   assert((Opc == ISD::SHL || Opc == ISD::SRA || Opc == ISD::SRL) &&
          "This is not a shift!");
   MVT::ValueType NVT = TLI.getTypeToTransformTo(Op.getValueType());
@@ -1746,6 +1750,14 @@
     // If we can emit an efficient shift operation, do so now.
     if (ExpandShift(ISD::SHL, Node->getOperand(0), Node->getOperand(1), Lo, Hi))
       break;
+
+    // If this target supports SHL_PARTS, use it.
+    if (TLI.getOperationAction(ISD::SHL_PARTS, NVT) == TargetLowering::Legal) {
+      ExpandByParts(ISD::SHL_PARTS, Node->getOperand(0), Node->getOperand(1),
+                    Lo, Hi);
+      break;
+    }
+
     // Otherwise, emit a libcall.
     Lo = ExpandLibCall("__ashldi3", Node, Hi);
     break;
@@ -1754,6 +1766,14 @@
     // If we can emit an efficient shift operation, do so now.
     if (ExpandShift(ISD::SRA, Node->getOperand(0), Node->getOperand(1), Lo, Hi))
       break;
+
+    // If this target supports SRA_PARTS, use it.
+    if (TLI.getOperationAction(ISD::SRA_PARTS, NVT) == TargetLowering::Legal) {
+      ExpandByParts(ISD::SRA_PARTS, Node->getOperand(0), Node->getOperand(1),
+                    Lo, Hi);
+      break;
+    }
+
     // Otherwise, emit a libcall.
     Lo = ExpandLibCall("__ashrdi3", Node, Hi);
     break;
@@ -1761,15 +1781,25 @@
     // If we can emit an efficient shift operation, do so now.
     if (ExpandShift(ISD::SRL, Node->getOperand(0), Node->getOperand(1), Lo, Hi))
       break;
+
+    // If this target supports SRL_PARTS, use it.
+    if (TLI.getOperationAction(ISD::SRL_PARTS, NVT) == TargetLowering::Legal) {
+      ExpandByParts(ISD::SRL_PARTS, Node->getOperand(0), Node->getOperand(1),
+                    Lo, Hi);
+      break;
+    }
+
     // Otherwise, emit a libcall.
     Lo = ExpandLibCall("__lshrdi3", Node, Hi);
     break;
 
-  case ISD::ADD:
-    ExpandAddSub(true, Node->getOperand(0), Node->getOperand(1), Lo, Hi);
+  case ISD::ADD: 
+    ExpandByParts(ISD::ADD_PARTS, Node->getOperand(0), Node->getOperand(1),
+                  Lo, Hi);
     break;
   case ISD::SUB:
-    ExpandAddSub(false, Node->getOperand(0), Node->getOperand(1), Lo, Hi);
+    ExpandByParts(ISD::SUB_PARTS, Node->getOperand(0), Node->getOperand(1),
+                  Lo, Hi);
     break;
   case ISD::MUL:  Lo = ExpandLibCall("__muldi3" , Node, Hi); break;
   case ISD::SDIV: Lo = ExpandLibCall("__divdi3" , Node, Hi); break;






More information about the llvm-commits mailing list