More working CellSPU tests:
- vec_const.ll: Vector constant loads
- immed64.ll: i64, f64 constant loads


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45242 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/CellSPU/SPUAsmPrinter.cpp b/lib/Target/CellSPU/SPUAsmPrinter.cpp
index 14f9909..03644af 100644
--- a/lib/Target/CellSPU/SPUAsmPrinter.cpp
+++ b/lib/Target/CellSPU/SPUAsmPrinter.cpp
@@ -635,7 +635,7 @@
   DW.EndModule();
 
   // Emit ident information
-  O << "\t.ident\t\"(llvm 1.9+) STI CBEA Cell SPU backend\"\n";
+  O << "\t.ident\t\"(llvm 2.2+) STI CBEA Cell SPU backend\"\n";
 
   return AsmPrinter::doFinalization(M);
 }
diff --git a/lib/Target/CellSPU/SPUISelDAGToDAG.cpp b/lib/Target/CellSPU/SPUISelDAGToDAG.cpp
index a036038..59de205 100644
--- a/lib/Target/CellSPU/SPUISelDAGToDAG.cpp
+++ b/lib/Target/CellSPU/SPUISelDAGToDAG.cpp
@@ -155,7 +155,7 @@
   }
 
   //===------------------------------------------------------------------===//
-  //! MVT::ValueType to useful stuff structure:
+  //! MVT::ValueType to "useful stuff" mapping structure:
 
   struct valtype_map_s {
     MVT::ValueType VT;
@@ -166,13 +166,13 @@
   };
 
   const valtype_map_s valtype_map[] = {
-    { MVT::i1,   0,            3, 0,         0 },
-    { MVT::i8,   0,            3, 0,         0 },
-    { MVT::i16,  SPU::ORHIr16, 2, SPU::BRHZ, SPU::BRHNZ },
-    { MVT::i32,  SPU::ORIr32,  0, SPU::BRZ,  SPU::BRNZ },
-    { MVT::i64,  SPU::ORIr64,  0, 0,         0 },
-    { MVT::f32,  SPU::ORIf32,  0, 0,         0 },
-    { MVT::f64,  SPU::ORIf64,  0, 0,         0 }
+    { MVT::i1,  0,            3, 0,         0 },
+    { MVT::i8,  0,            3, 0,         0 },
+    { MVT::i16, SPU::ORHIr16, 2, SPU::BRHZ, SPU::BRHNZ },
+    { MVT::i32, SPU::ORIr32,  0, SPU::BRZ,  SPU::BRNZ },
+    { MVT::i64, SPU::ORIr64,  0, 0,         0 },
+    { MVT::f32, 0,            0, 0,         0 },
+    { MVT::f64, 0,            0, 0,         0 }
   };
 
   const size_t n_valtype_map = sizeof(valtype_map) / sizeof(valtype_map[0]);
@@ -605,23 +605,32 @@
     unsigned VT = N->getValueType(0);
     SDOperand Arg = N->getOperand(0);
     SDOperand Chain = N->getOperand(1);
-    SDOperand Zero = CurDAG->getTargetConstant(0, VT);
     SDNode *Result;
-    const valtype_map_s *vtm = getValueTypeMapEntry(VT);
-
-    if (vtm->ldresult_ins == 0) {
-      cerr << "LDRESULT for unsupported type: "
-           << MVT::getValueTypeString(VT)
-           << "\n";
-      abort();
-    } else
-      Opc = vtm->ldresult_ins;
 
     AddToISelQueue(Arg);
-    AddToISelQueue(Zero);
-    AddToISelQueue(Chain);
-    Result = CurDAG->SelectNodeTo(N, Opc, VT, MVT::Other, Arg, Zero, Chain);
+    if (!MVT::isFloatingPoint(VT)) {
+      SDOperand Zero = CurDAG->getTargetConstant(0, VT);
+      const valtype_map_s *vtm = getValueTypeMapEntry(VT);
+
+      if (vtm->ldresult_ins == 0) {
+	cerr << "LDRESULT for unsupported type: "
+	     << MVT::getValueTypeString(VT)
+	     << "\n";
+	abort();
+      } else
+	Opc = vtm->ldresult_ins;
+
+      AddToISelQueue(Zero);
+      Result = CurDAG->SelectNodeTo(N, Opc, VT, MVT::Other, Arg, Zero, Chain);
+    } else {
+      Result =
+	CurDAG->SelectNodeTo(N, (VT == MVT::f32 ? SPU::ORf32 : SPU::ORf64),
+			     MVT::Other, Arg, Arg, Chain);
+    }
+
     Chain = SDOperand(Result, 1);
+    AddToISelQueue(Chain);
+
     return Result;
   }
   
diff --git a/lib/Target/CellSPU/SPUISelLowering.cpp b/lib/Target/CellSPU/SPUISelLowering.cpp
index 2ab4841..6b6af64 100644
--- a/lib/Target/CellSPU/SPUISelLowering.cpp
+++ b/lib/Target/CellSPU/SPUISelLowering.cpp
@@ -263,10 +263,10 @@
   setOperationAction(ISD::SINT_TO_FP, MVT::i64, Custom);
   setOperationAction(ISD::UINT_TO_FP, MVT::i64, Custom);
 
-  setOperationAction(ISD::BIT_CONVERT, MVT::f32, Expand);
-  setOperationAction(ISD::BIT_CONVERT, MVT::i32, Expand);
-  setOperationAction(ISD::BIT_CONVERT, MVT::i64, Expand);
-  setOperationAction(ISD::BIT_CONVERT, MVT::f64, Expand);
+  setOperationAction(ISD::BIT_CONVERT, MVT::i32, Legal);
+  setOperationAction(ISD::BIT_CONVERT, MVT::f32, Legal);
+  setOperationAction(ISD::BIT_CONVERT, MVT::i64, Legal);
+  setOperationAction(ISD::BIT_CONVERT, MVT::f64, Legal);
 
   // We cannot sextinreg(i1).  Expand to shifts.
   setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand);
@@ -441,6 +441,7 @@
   LoadSDNode *LN = cast<LoadSDNode>(Op);
   SDOperand basep = LN->getBasePtr();
   SDOperand the_chain = LN->getChain();
+  MVT::ValueType BasepOpc = basep.Val->getOpcode();
   MVT::ValueType VT = LN->getLoadedVT();
   MVT::ValueType OpVT = Op.Val->getValueType(0);
   MVT::ValueType PtrVT = DAG.getTargetLoweringInfo().getPointerTy();
@@ -449,6 +450,11 @@
   const valtype_map_s *vtm = getValueTypeMapEntry(VT);
   SDOperand Ops[8];
 
+  if (BasepOpc == ISD::FrameIndex) {
+    // Loading from a frame index is always properly aligned. Always.
+    return SDOperand();
+  }
+
   // For an extending load of an i1 variable, just call it i8 (or whatever we
   // were passed) and make it zero-extended:
   if (VT == MVT::i1) {
@@ -467,11 +473,9 @@
     // The vector type we really want to be when we load the 16-byte chunk
     MVT::ValueType vecVT, opVecVT;
     
+    vecVT = MVT::v16i8;
     if (VT != MVT::i1)
       vecVT = MVT::getVectorType(VT, (128 / MVT::getSizeInBits(VT)));
-    else
-      vecVT = MVT::v16i8;
-
     opVecVT = MVT::getVectorType(OpVT, (128 / MVT::getSizeInBits(OpVT)));
 
     if (basep.getOpcode() == ISD::ADD) {
@@ -604,8 +608,8 @@
       // address scheme:
 
       SDOperand ZeroOffs = DAG.getConstant(0, PtrVT);
-      SDOperand loOp = DAG.getNode(SPUISD::Lo, VT, basep, ZeroOffs);
-      SDOperand hiOp = DAG.getNode(SPUISD::Hi, VT, basep, ZeroOffs);
+      SDOperand loOp = DAG.getNode(SPUISD::Lo, PtrVT, basep, ZeroOffs);
+      SDOperand hiOp = DAG.getNode(SPUISD::Hi, PtrVT, basep, ZeroOffs);
 
       ptrp = DAG.getNode(ISD::ADD, PtrVT, loOp, hiOp);
 
diff --git a/lib/Target/CellSPU/SPUInstrInfo.cpp b/lib/Target/CellSPU/SPUInstrInfo.cpp
index 5c2bd52..7d008c0 100644
--- a/lib/Target/CellSPU/SPUInstrInfo.cpp
+++ b/lib/Target/CellSPU/SPUInstrInfo.cpp
@@ -49,8 +49,6 @@
     break;
   case SPU::ORIv4i32:
   case SPU::ORIr32:
-  case SPU::ORIf64:
-  case SPU::ORIf32:
   case SPU::ORIr64:
   case SPU::ORHIv8i16:
   case SPU::ORHIr16:
@@ -86,18 +84,6 @@
       return true;
     }
     break;
-#if 0
-  case SPU::ORIf64:
-  case SPU::ORIf32:
-    // Special case because there's no third immediate operand to the
-    // instruction (the constant is embedded in the instruction)
-    assert(MI.getOperand(0).isRegister() &&
-	   MI.getOperand(1).isRegister() &&
-	   "ORIf32/f64: operands not registers");
-    sourceReg = MI.getOperand(1).getReg();
-    destReg = MI.getOperand(0).getReg();
-    return true;
-#endif
   case SPU::ORv16i8_i8:
   case SPU::ORv8i16_i16:
   case SPU::ORv4i32_i32:
@@ -115,6 +101,8 @@
   case SPU::ORv4i32:
   case SPU::ORr32:
   case SPU::ORr64:
+  case SPU::ORf32:
+  case SPU::ORf64:
   case SPU::ORgprc:
     assert(MI.getNumOperands() == 3 &&
            MI.getOperand(0).isRegister() &&
diff --git a/lib/Target/CellSPU/SPUInstrInfo.td b/lib/Target/CellSPU/SPUInstrInfo.td
index 82e0a93..a0e2fe1 100644
--- a/lib/Target/CellSPU/SPUInstrInfo.td
+++ b/lib/Target/CellSPU/SPUInstrInfo.td
@@ -1285,6 +1285,18 @@
       "or\t$rT, $rA, $rB", IntegerOp,
       [(set R8C:$rT, (or R8C:$rA, R8C:$rB))]>;
 
+// OR instruction forms that are used to copy f32 and f64 registers.
+// They do not match patterns.
+def ORf32:
+    RRForm<0b10000010000, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
+      "or\t$rT, $rA, $rB", IntegerOp,
+      [/* no pattern */]>;
+
+def ORf64:
+    RRForm<0b10000010000, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
+      "or\t$rT, $rA, $rB", IntegerOp,
+      [/* no pattern */]>;
+
 // ORv*_*: Used in scalar->vector promotions:
 def ORv16i8_i8:
     RRForm<0b10000010000, (outs VECREG:$rT), (ins R8C:$rA, R8C:$rB),
@@ -1474,18 +1486,6 @@
       "ori\t$rT, $rA, $val", IntegerOp,
       [(set R32C:$rT, (or R32C:$rA, i32ImmUns10:$val))]>;
 
-// Hacked forms of or immediate to copy one 32- and 64-bit FP register  
-// to another. Do not match patterns.
-def ORIf32:
-    RI10Form_1<0b00100000, (outs R32FP:$rT), (ins R32FP:$rA, s10imm_i32:$val),
-      "ori\t$rT, $rA, $val", IntegerOp,
-      [/* no pattern */]>;
-
-def ORIf64:
-    RI10Form_1<0b00100000, (outs R64FP:$rT), (ins R64FP:$rA, s10imm_i32:$val),
-      "ori\t$rT, $rA, $val", IntegerOp,
-      [/* no pattern */]>;
-
 def ORIr64:
     RI10Form_1<0b00100000, (outs R64C:$rT), (ins R64C:$rA, s10imm_i32:$val),
       "ori\t$rT, $rA, $val", IntegerOp,
@@ -2108,7 +2108,7 @@
 def SHUFB:
     RRRForm<0b1000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
       "shufb\t$rT, $rA, $rB, $rC", IntegerOp,
-      [/* insert intrinsic here */]>;
+      [/* no pattern */]>;
 
 // SPUshuffle is generated in LowerVECTOR_SHUFFLE and gets replaced with SHUFB.
 // See the SPUshuffle SDNode operand above, which sets up the DAG pattern
@@ -2123,9 +2123,15 @@
 def : Pat<(SPUshuffle (v4i32 VECREG:$rA), (v4i32 VECREG:$rB), VECREG:$rC),
           (SHUFB VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
 
+def : Pat<(SPUshuffle (v4f32 VECREG:$rA), (v4f32 VECREG:$rB), VECREG:$rC),
+          (SHUFB VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
+
 def : Pat<(SPUshuffle (v2i64 VECREG:$rA), (v2i64 VECREG:$rB), VECREG:$rC),
           (SHUFB VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
 
+def : Pat<(SPUshuffle (v2f64 VECREG:$rA), (v2f64 VECREG:$rB), VECREG:$rC),
+          (SHUFB VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
+
 //===----------------------------------------------------------------------===//
 // Shift and rotate group:
 //===----------------------------------------------------------------------===//
@@ -3372,6 +3378,7 @@
 def : Pat<(v2f64 (bitconvert (v2f64 VECREG:$src))), (v2f64 VECREG:$src)>;
 
 def : Pat<(f32 (bitconvert (i32 R32C:$src))), (f32 R32FP:$src)>;
+def : Pat<(f64 (bitconvert (i64 R64C:$src))), (f64 R64FP:$src)>;
 
 //===----------------------------------------------------------------------===//
 // Instruction patterns:
diff --git a/lib/Target/CellSPU/SPURegisterInfo.cpp b/lib/Target/CellSPU/SPURegisterInfo.cpp
index 26917fe..7ef134c 100644
--- a/lib/Target/CellSPU/SPURegisterInfo.cpp
+++ b/lib/Target/CellSPU/SPURegisterInfo.cpp
@@ -378,11 +378,13 @@
   } else if (DestRC == SPU::R32CRegisterClass) {
     BuildMI(MBB, MI, TII.get(SPU::ORIr32), DestReg).addReg(SrcReg).addImm(0);
   } else if (DestRC == SPU::R32FPRegisterClass) {
-    BuildMI(MBB, MI, TII.get(SPU::ORIf32), DestReg).addReg(SrcReg).addImm(0);
+    BuildMI(MBB, MI, TII.get(SPU::ORf32), DestReg).addReg(SrcReg)
+      .addReg(SrcReg);
   } else if (DestRC == SPU::R64CRegisterClass) {
     BuildMI(MBB, MI, TII.get(SPU::ORIr64), DestReg).addReg(SrcReg).addImm(0);
   } else if (DestRC == SPU::R64FPRegisterClass) {
-    BuildMI(MBB, MI, TII.get(SPU::ORIf64), DestReg).addReg(SrcReg).addImm(0);
+    BuildMI(MBB, MI, TII.get(SPU::ORf64), DestReg).addReg(SrcReg)
+      .addReg(SrcReg);
   } else if (DestRC == SPU::GPRCRegisterClass) {
     BuildMI(MBB, MI, TII.get(SPU::ORgprc), DestReg).addReg(SrcReg)
       .addReg(SrcReg);