More CellSPU refinements:

- struct_2.ll: Completely unaligned load/store testing

- call_indirect.ll, struct_1.ll: Add test lines to exercise
   X-form [$reg($reg)] addressing

At this point, loads and stores should be under control (he says
in an optimistic tone of voice.)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45882 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/CellSPU/SPUISelDAGToDAG.cpp b/lib/Target/CellSPU/SPUISelDAGToDAG.cpp
index bb3b100..167d3c3 100644
--- a/lib/Target/CellSPU/SPUISelDAGToDAG.cpp
+++ b/lib/Target/CellSPU/SPUISelDAGToDAG.cpp
@@ -456,8 +456,9 @@
     const SDOperand Op0 = N.getOperand(0); // Frame index/base
     const SDOperand Op1 = N.getOperand(1); // Offset within base
 
-    if (Op1.getOpcode() == ISD::Constant
-        || Op1.getOpcode() == ISD::TargetConstant) {
+    if ((Op1.getOpcode() == ISD::Constant
+	 || Op1.getOpcode() == ISD::TargetConstant)
+	&& Op0.getOpcode() != SPUISD::XFormAddr) {
       ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Op1);
       assert(CN != 0 && "SelectDFormAddr: Expected a constant");
 
@@ -499,12 +500,19 @@
     } else
       return false;
   } else if (Opc == SPUISD::DFormAddr) {
-    // D-Form address: This is pretty straightforward, naturally...
-    ConstantSDNode *CN = cast<ConstantSDNode>(N.getOperand(1));
-    assert(CN != 0 && "SelectDFormAddr/SPUISD::DFormAddr expecting constant"); 
-    Base = CurDAG->getTargetConstant(CN->getValue(), PtrTy);
-    Index = N.getOperand(0);
-    return true;
+    // D-Form address: This is pretty straightforward,
+    // naturally... but make sure that this isn't a D-form address
+    // with a X-form address embedded within:
+    const SDOperand Op0 = N.getOperand(0); // Frame index/base
+    const SDOperand Op1 = N.getOperand(1); // Offset within base
+
+    if (Op0.getOpcode() != SPUISD::XFormAddr) {
+      ConstantSDNode *CN = cast<ConstantSDNode>(Op1);
+      assert(CN != 0 && "SelectDFormAddr/SPUISD::DFormAddr expecting constant"); 
+      Base = CurDAG->getTargetConstant(CN->getValue(), PtrTy);
+      Index = Op0;
+      return true;
+    }
   } else if (Opc == ISD::FrameIndex) {
     // Stack frame index must be less than 512 (divided by 16):
     FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(N);
@@ -564,6 +572,12 @@
     Base = N;
     Index = N.getOperand(1);
     return true;
+  } else if (Opc == SPUISD::DFormAddr) {
+    // Must be a D-form address with an X-form address embedded
+    // within:
+    Base = N.getOperand(0);
+    Index = N.getOperand(1);
+    return true;
   } else if (N.getNumOperands() == 2) {
     SDOperand N1 = N.getOperand(0);
     SDOperand N2 = N.getOperand(1);
@@ -578,14 +592,14 @@
       /*UNREACHED*/
     } else {
       cerr << "SelectXFormAddr: 2-operand unhandled operand:\n";
-      N.Val->dump();
+      N.Val->dump(CurDAG);
       cerr << "\n";
       abort();
     /*UNREACHED*/
     }
   } else {
     cerr << "SelectXFormAddr: Unhandled operand type:\n";
-    N.Val->dump();
+    N.Val->dump(CurDAG);
     cerr << "\n";
     abort();
     /*UNREACHED*/