Fix a ppc long double regression I introduced yesterday due to a
[oota-llvm.git] / lib / CodeGen / SelectionDAG / SelectionDAG.cpp
index 2ac30f6f3da533290dd817bd6a1ec0519ba8e299..34825beffabd0acb0ec982bb248f98b2c28e7df4 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -19,6 +19,7 @@
 #include "llvm/Assembly/Writer.h"
 #include "llvm/CodeGen/MachineBasicBlock.h"
 #include "llvm/CodeGen/MachineConstantPool.h"
+#include "llvm/CodeGen/MachineFrameInfo.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Target/MRegisterInfo.h"
 #include "llvm/Target/TargetData.h"
@@ -27,6 +28,7 @@
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include <algorithm>
@@ -370,8 +372,6 @@ static void AddNodeIDNode(FoldingSetNodeID &ID, SDNode *N) {
     ID.AddInteger(LD->getAddressingMode());
     ID.AddInteger(LD->getExtensionType());
     ID.AddInteger((unsigned int)(LD->getLoadedVT()));
-    ID.AddPointer(LD->getSrcValue());
-    ID.AddInteger(LD->getSrcValueOffset());
     ID.AddInteger(LD->getAlignment());
     ID.AddInteger(LD->isVolatile());
     break;
@@ -381,8 +381,6 @@ static void AddNodeIDNode(FoldingSetNodeID &ID, SDNode *N) {
     ID.AddInteger(ST->getAddressingMode());
     ID.AddInteger(ST->isTruncatingStore());
     ID.AddInteger((unsigned int)(ST->getStoredVT()));
-    ID.AddPointer(ST->getSrcValue());
-    ID.AddInteger(ST->getSrcValueOffset());
     ID.AddInteger(ST->getAlignment());
     ID.AddInteger(ST->isVolatile());
     break;
@@ -525,10 +523,16 @@ void SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) {
     Erased =
       TargetExternalSymbols.erase(cast<ExternalSymbolSDNode>(N)->getSymbol());
     break;
-  case ISD::VALUETYPE:
-    Erased = ValueTypeNodes[cast<VTSDNode>(N)->getVT()] != 0;
-    ValueTypeNodes[cast<VTSDNode>(N)->getVT()] = 0;
+  case ISD::VALUETYPE: {
+    MVT::ValueType VT = cast<VTSDNode>(N)->getVT();
+    if (MVT::isExtendedVT(VT)) {
+      Erased = ExtendedValueTypeNodes.erase(VT);
+    } else {
+      Erased = ValueTypeNodes[VT] != 0;
+      ValueTypeNodes[VT] = 0;
+    }
     break;
+  }
   default:
     // Remove it from the CSE Map.
     Erased = CSEMap.RemoveNode(N);
@@ -631,16 +635,12 @@ SDNode *SelectionDAG::FindModifiedNodeSlot(SDNode *N,
     ID.AddInteger(LD->getAddressingMode());
     ID.AddInteger(LD->getExtensionType());
     ID.AddInteger((unsigned int)(LD->getLoadedVT()));
-    ID.AddPointer(LD->getSrcValue());
-    ID.AddInteger(LD->getSrcValueOffset());
     ID.AddInteger(LD->getAlignment());
     ID.AddInteger(LD->isVolatile());
   } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
     ID.AddInteger(ST->getAddressingMode());
     ID.AddInteger(ST->isTruncatingStore());
     ID.AddInteger((unsigned int)(ST->getStoredVT()));
-    ID.AddPointer(ST->getSrcValue());
-    ID.AddInteger(ST->getSrcValueOffset());
     ID.AddInteger(ST->getAlignment());
     ID.AddInteger(ST->isVolatile());
   }
@@ -679,22 +679,35 @@ SDOperand SelectionDAG::getString(const std::string &Val) {
 
 SDOperand SelectionDAG::getConstant(uint64_t Val, MVT::ValueType VT, bool isT) {
   assert(MVT::isInteger(VT) && "Cannot create FP integer constant!");
-  assert(!MVT::isVector(VT) && "Cannot create Vector ConstantSDNodes!");
+
+  MVT::ValueType EltVT =
+    MVT::isVector(VT) ? MVT::getVectorElementType(VT) : VT;
   
   // Mask out any bits that are not valid for this constant.
-  Val &= MVT::getIntVTBitMask(VT);
+  Val &= MVT::getIntVTBitMask(EltVT);
 
   unsigned Opc = isT ? ISD::TargetConstant : ISD::Constant;
   FoldingSetNodeID ID;
-  AddNodeIDNode(ID, Opc, getVTList(VT), 0, 0);
+  AddNodeIDNode(ID, Opc, getVTList(EltVT), 0, 0);
   ID.AddInteger(Val);
   void *IP = 0;
-  if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP))
-    return SDOperand(E, 0);
-  SDNode *N = new ConstantSDNode(isT, Val, VT);
-  CSEMap.InsertNode(N, IP);
-  AllNodes.push_back(N);
-  return SDOperand(N, 0);
+  SDNode *N = NULL;
+  if ((N = CSEMap.FindNodeOrInsertPos(ID, IP)))
+    if (!MVT::isVector(VT))
+      return SDOperand(N, 0);
+  if (!N) {
+    N = new ConstantSDNode(isT, Val, EltVT);
+    CSEMap.InsertNode(N, IP);
+    AllNodes.push_back(N);
+  }
+
+  SDOperand Result(N, 0);
+  if (MVT::isVector(VT)) {
+    SmallVector<SDOperand, 8> Ops;
+    Ops.assign(MVT::getVectorNumElements(VT), Result);
+    Result = getNode(ISD::BUILD_VECTOR, VT, &Ops[0], Ops.size());
+  }
+  return Result;
 }
 
 SDOperand SelectionDAG::getConstantFP(const APFloat& V, MVT::ValueType VT,
@@ -845,14 +858,16 @@ SDOperand SelectionDAG::getBasicBlock(MachineBasicBlock *MBB) {
 }
 
 SDOperand SelectionDAG::getValueType(MVT::ValueType VT) {
-  if ((unsigned)VT >= ValueTypeNodes.size())
+  if (!MVT::isExtendedVT(VT) && (unsigned)VT >= ValueTypeNodes.size())
     ValueTypeNodes.resize(VT+1);
-  if (ValueTypeNodes[VT] == 0) {
-    ValueTypeNodes[VT] = new VTSDNode(VT);
-    AllNodes.push_back(ValueTypeNodes[VT]);
-  }
 
-  return SDOperand(ValueTypeNodes[VT], 0);
+  SDNode *&N = MVT::isExtendedVT(VT) ?
+    ExtendedValueTypeNodes[VT] : ValueTypeNodes[VT];
+
+  if (N) return SDOperand(N, 0);
+  N = new VTSDNode(VT);
+  AllNodes.push_back(N);
+  return SDOperand(N, 0);
 }
 
 SDOperand SelectionDAG::getExternalSymbol(const char *Sym, MVT::ValueType VT) {
@@ -913,6 +928,18 @@ SDOperand SelectionDAG::getSrcValue(const Value *V, int Offset) {
   return SDOperand(N, 0);
 }
 
+/// CreateStackTemporary - Create a stack temporary, suitable for holding the
+/// specified value type.
+SDOperand SelectionDAG::CreateStackTemporary(MVT::ValueType VT) {
+  MachineFrameInfo *FrameInfo = getMachineFunction().getFrameInfo();
+  unsigned ByteSize = MVT::getSizeInBits(VT)/8;
+  const Type *Ty = MVT::getTypeForValueType(VT);
+  unsigned StackAlign = (unsigned)TLI.getTargetData()->getPrefTypeAlignment(Ty);
+  int FrameIdx = FrameInfo->CreateStackObject(ByteSize, StackAlign);
+  return getFrameIndex(FrameIdx, TLI.getPointerTy());
+}
+
+
 SDOperand SelectionDAG::FoldSetCC(MVT::ValueType VT, SDOperand N1,
                                   SDOperand N2, ISD::CondCode Cond) {
   // These setcc operations always fold.
@@ -965,6 +992,9 @@ SDOperand SelectionDAG::FoldSetCC(MVT::ValueType VT, SDOperand N1,
   }
   if (ConstantFPSDNode *N1C = dyn_cast<ConstantFPSDNode>(N1.Val))
     if (ConstantFPSDNode *N2C = dyn_cast<ConstantFPSDNode>(N2.Val)) {
+      // No compile time operations on this type yet.
+      if (N1C->getValueType(0) == MVT::ppcf128)
+        return SDOperand();
 
       APFloat::cmpResult R = N1C->getValueAPF().compare(N2C->getValueAPF());
       switch (Cond) {
@@ -1293,6 +1323,11 @@ void SelectionDAG::ComputeMaskedBits(SDOperand Op, uint64_t Mask,
     KnownZero |= (~InMask) & Mask;
     return;
   }
+  case ISD::FGETSIGN:
+    // All bits are zero except the low bit.
+    KnownZero = MVT::getIntVTBitMask(Op.getValueType()) ^ 1;
+    return;
+  
   case ISD::ADD: {
     // If either the LHS or the RHS are Zero, the result is zero.
     ComputeMaskedBits(Op.getOperand(1), Mask, KnownZero, KnownOne, Depth+1);
@@ -1594,6 +1629,9 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
     case ISD::UINT_TO_FP:
     case ISD::SINT_TO_FP: {
       const uint64_t zero[] = {0, 0};
+      // No compile time operations on this type.
+      if (VT==MVT::ppcf128)
+        break;
       APFloat apf = APFloat(APInt(MVT::getSizeInBits(VT), 2, zero));
       (void)apf.convertFromZeroExtendedInteger(&Val, 
                                MVT::getSizeInBits(Operand.getValueType()), 
@@ -1666,42 +1704,44 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
   // Constant fold unary operations with a floating point constant operand.
   if (ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(Operand.Val)) {
     APFloat V = C->getValueAPF();    // make copy
-    switch (Opcode) {
-    case ISD::FNEG:
-      V.changeSign();
-      return getConstantFP(V, VT);
-    case ISD::FABS:
-      V.clearSign();
-      return getConstantFP(V, VT);
-    case ISD::FP_ROUND:
-    case ISD::FP_EXTEND:
-      // This can return overflow, underflow, or inexact; we don't care.
-      // FIXME need to be more flexible about rounding mode.
-      (void) V.convert(VT==MVT::f32 ? APFloat::IEEEsingle : 
-                       VT==MVT::f64 ? APFloat::IEEEdouble :
-                       VT==MVT::f80 ? APFloat::x87DoubleExtended :
-                       VT==MVT::f128 ? APFloat::IEEEquad :
-                       APFloat::Bogus,
-                       APFloat::rmNearestTiesToEven);
-      return getConstantFP(V, VT);
-    case ISD::FP_TO_SINT:
-    case ISD::FP_TO_UINT: {
-      integerPart x;
-      assert(integerPartWidth >= 64);
-      // FIXME need to be more flexible about rounding mode.
-      APFloat::opStatus s = V.convertToInteger(&x, 64U,
-                            Opcode==ISD::FP_TO_SINT,
-                            APFloat::rmTowardZero);
-      if (s==APFloat::opInvalidOp)     // inexact is OK, in fact usual
+    if (VT!=MVT::ppcf128 && Operand.getValueType()!=MVT::ppcf128) {
+      switch (Opcode) {
+      case ISD::FNEG:
+        V.changeSign();
+        return getConstantFP(V, VT);
+      case ISD::FABS:
+        V.clearSign();
+        return getConstantFP(V, VT);
+      case ISD::FP_ROUND:
+      case ISD::FP_EXTEND:
+        // This can return overflow, underflow, or inexact; we don't care.
+        // FIXME need to be more flexible about rounding mode.
+        (void) V.convert(VT==MVT::f32 ? APFloat::IEEEsingle : 
+                         VT==MVT::f64 ? APFloat::IEEEdouble :
+                         VT==MVT::f80 ? APFloat::x87DoubleExtended :
+                         VT==MVT::f128 ? APFloat::IEEEquad :
+                         APFloat::Bogus,
+                         APFloat::rmNearestTiesToEven);
+        return getConstantFP(V, VT);
+      case ISD::FP_TO_SINT:
+      case ISD::FP_TO_UINT: {
+        integerPart x;
+        assert(integerPartWidth >= 64);
+        // FIXME need to be more flexible about rounding mode.
+        APFloat::opStatus s = V.convertToInteger(&x, 64U,
+                              Opcode==ISD::FP_TO_SINT,
+                              APFloat::rmTowardZero);
+        if (s==APFloat::opInvalidOp)     // inexact is OK, in fact usual
+          break;
+        return getConstant(x, VT);
+      }
+      case ISD::BIT_CONVERT:
+        if (VT == MVT::i32 && C->getValueType(0) == MVT::f32)
+          return getConstant((uint32_t)V.convertToAPInt().getZExtValue(), VT);
+        else if (VT == MVT::i64 && C->getValueType(0) == MVT::f64)
+          return getConstant(V.convertToAPInt().getZExtValue(), VT);
         break;
-      return getConstant(x, VT);
-    }
-    case ISD::BIT_CONVERT:
-      if (VT == MVT::i32 && C->getValueType(0) == MVT::f32)
-        return getConstant((uint32_t)V.convertToAPInt().getZExtValue(), VT);
-      else if (VT == MVT::i64 && C->getValueType(0) == MVT::f64)
-        return getConstant(V.convertToAPInt().getZExtValue(), VT);
-      break;
+      }
     }
   }
 
@@ -1713,12 +1753,14 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
   case ISD::FP_EXTEND:
     assert(MVT::isFloatingPoint(VT) &&
            MVT::isFloatingPoint(Operand.getValueType()) && "Invalid FP cast!");
+    if (Operand.getValueType() == VT) return Operand;  // noop conversion.
     break;
   case ISD::SIGN_EXTEND:
     assert(MVT::isInteger(VT) && MVT::isInteger(Operand.getValueType()) &&
            "Invalid SIGN_EXTEND!");
     if (Operand.getValueType() == VT) return Operand;   // noop extension
-    assert(Operand.getValueType() < VT && "Invalid sext node, dst < src!");
+    assert(MVT::getSizeInBits(Operand.getValueType()) < MVT::getSizeInBits(VT)
+           && "Invalid sext node, dst < src!");
     if (OpOpcode == ISD::SIGN_EXTEND || OpOpcode == ISD::ZERO_EXTEND)
       return getNode(OpOpcode, VT, Operand.Val->getOperand(0));
     break;
@@ -1726,7 +1768,8 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
     assert(MVT::isInteger(VT) && MVT::isInteger(Operand.getValueType()) &&
            "Invalid ZERO_EXTEND!");
     if (Operand.getValueType() == VT) return Operand;   // noop extension
-    assert(Operand.getValueType() < VT && "Invalid zext node, dst < src!");
+    assert(MVT::getSizeInBits(Operand.getValueType()) < MVT::getSizeInBits(VT)
+           && "Invalid zext node, dst < src!");
     if (OpOpcode == ISD::ZERO_EXTEND)   // (zext (zext x)) -> (zext x)
       return getNode(ISD::ZERO_EXTEND, VT, Operand.Val->getOperand(0));
     break;
@@ -1734,7 +1777,8 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
     assert(MVT::isInteger(VT) && MVT::isInteger(Operand.getValueType()) &&
            "Invalid ANY_EXTEND!");
     if (Operand.getValueType() == VT) return Operand;   // noop extension
-    assert(Operand.getValueType() < VT && "Invalid anyext node, dst < src!");
+    assert(MVT::getSizeInBits(Operand.getValueType()) < MVT::getSizeInBits(VT)
+           && "Invalid anyext node, dst < src!");
     if (OpOpcode == ISD::ZERO_EXTEND || OpOpcode == ISD::SIGN_EXTEND)
       // (ext (zext x)) -> (zext x)  and  (ext (sext x)) -> (sext x)
       return getNode(OpOpcode, VT, Operand.Val->getOperand(0));
@@ -1743,15 +1787,18 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
     assert(MVT::isInteger(VT) && MVT::isInteger(Operand.getValueType()) &&
            "Invalid TRUNCATE!");
     if (Operand.getValueType() == VT) return Operand;   // noop truncate
-    assert(Operand.getValueType() > VT && "Invalid truncate node, src < dst!");
+    assert(MVT::getSizeInBits(Operand.getValueType()) > MVT::getSizeInBits(VT)
+           && "Invalid truncate node, src < dst!");
     if (OpOpcode == ISD::TRUNCATE)
       return getNode(ISD::TRUNCATE, VT, Operand.Val->getOperand(0));
     else if (OpOpcode == ISD::ZERO_EXTEND || OpOpcode == ISD::SIGN_EXTEND ||
              OpOpcode == ISD::ANY_EXTEND) {
       // If the source is smaller than the dest, we still need an extend.
-      if (Operand.Val->getOperand(0).getValueType() < VT)
+      if (MVT::getSizeInBits(Operand.Val->getOperand(0).getValueType())
+          < MVT::getSizeInBits(VT))
         return getNode(OpOpcode, VT, Operand.Val->getOperand(0));
-      else if (Operand.Val->getOperand(0).getValueType() > VT)
+      else if (MVT::getSizeInBits(Operand.Val->getOperand(0).getValueType())
+               > MVT::getSizeInBits(VT))
         return getNode(ISD::TRUNCATE, VT, Operand.Val->getOperand(0));
       else
         return Operand.Val->getOperand(0);
@@ -1858,7 +1905,8 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
     assert(VT == N1.getValueType() && "Not an inreg round!");
     assert(MVT::isFloatingPoint(VT) && MVT::isFloatingPoint(EVT) &&
            "Cannot FP_ROUND_INREG integer types");
-    assert(EVT <= VT && "Not rounding down!");
+    assert(MVT::getSizeInBits(EVT) <= MVT::getSizeInBits(VT) &&
+           "Not rounding down!");
     break;
   }
   case ISD::AssertSext:
@@ -1868,7 +1916,8 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
     assert(VT == N1.getValueType() && "Not an inreg extend!");
     assert(MVT::isInteger(VT) && MVT::isInteger(EVT) &&
            "Cannot *_EXTEND_INREG FP types");
-    assert(EVT <= VT && "Not extending!");
+    assert(MVT::getSizeInBits(EVT) <= MVT::getSizeInBits(VT) &&
+           "Not extending!");
   }
 
   default: break;
@@ -1931,7 +1980,7 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
   ConstantFPSDNode *N1CFP = dyn_cast<ConstantFPSDNode>(N1.Val);
   ConstantFPSDNode *N2CFP = dyn_cast<ConstantFPSDNode>(N2.Val);
   if (N1CFP) {
-    if (N2CFP) {
+    if (N2CFP && VT!=MVT::ppcf128) {
       APFloat V1 = N1CFP->getValueAPF(), V2 = N2CFP->getValueAPF();
       APFloat::opStatus s;
       switch (Opcode) {
@@ -2231,6 +2280,30 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
   return getNode(Opcode, VT, Ops, 5);
 }
 
+SDOperand SelectionDAG::getMemcpy(SDOperand Chain, SDOperand Dest,
+                                  SDOperand Src, SDOperand Size,
+                                  SDOperand Align,
+                                  SDOperand AlwaysInline) {
+  SDOperand Ops[] = { Chain, Dest, Src, Size, Align, AlwaysInline };
+  return getNode(ISD::MEMCPY, MVT::Other, Ops, 6);
+}
+
+SDOperand SelectionDAG::getMemmove(SDOperand Chain, SDOperand Dest,
+                                  SDOperand Src, SDOperand Size,
+                                  SDOperand Align,
+                                  SDOperand AlwaysInline) {
+  SDOperand Ops[] = { Chain, Dest, Src, Size, Align, AlwaysInline };
+  return getNode(ISD::MEMMOVE, MVT::Other, Ops, 6);
+}
+
+SDOperand SelectionDAG::getMemset(SDOperand Chain, SDOperand Dest,
+                                  SDOperand Src, SDOperand Size,
+                                  SDOperand Align,
+                                  SDOperand AlwaysInline) {
+  SDOperand Ops[] = { Chain, Dest, Src, Size, Align, AlwaysInline };
+  return getNode(ISD::MEMSET, MVT::Other, Ops, 6);
+}
+
 SDOperand SelectionDAG::getLoad(MVT::ValueType VT,
                                 SDOperand Chain, SDOperand Ptr,
                                 const Value *SV, int SVOffset,
@@ -2255,8 +2328,6 @@ SDOperand SelectionDAG::getLoad(MVT::ValueType VT,
   ID.AddInteger(ISD::UNINDEXED);
   ID.AddInteger(ISD::NON_EXTLOAD);
   ID.AddInteger((unsigned int)VT);
-  ID.AddPointer(SV);
-  ID.AddInteger(SVOffset);
   ID.AddInteger(Alignment);
   ID.AddInteger(isVolatile);
   void *IP = 0;
@@ -2278,12 +2349,13 @@ SDOperand SelectionDAG::getExtLoad(ISD::LoadExtType ExtType, MVT::ValueType VT,
   // If they are asking for an extending load from/to the same thing, return a
   // normal load.
   if (VT == EVT)
-    ExtType = ISD::NON_EXTLOAD;
+    return getLoad(VT, Chain, Ptr, SV, SVOffset, isVolatile, Alignment);
 
   if (MVT::isVector(VT))
     assert(EVT == MVT::getVectorElementType(VT) && "Invalid vector extload!");
   else
-    assert(EVT < VT && "Should only be an extending load, not truncating!");
+    assert(MVT::getSizeInBits(EVT) < MVT::getSizeInBits(VT) &&
+           "Should only be an extending load, not truncating!");
   assert((ExtType == ISD::EXTLOAD || MVT::isInteger(VT)) &&
          "Cannot sign/zero extend a FP/Vector load!");
   assert(MVT::isInteger(VT) == MVT::isInteger(EVT) &&
@@ -2309,8 +2381,6 @@ SDOperand SelectionDAG::getExtLoad(ISD::LoadExtType ExtType, MVT::ValueType VT,
   ID.AddInteger(ISD::UNINDEXED);
   ID.AddInteger(ExtType);
   ID.AddInteger((unsigned int)EVT);
-  ID.AddPointer(SV);
-  ID.AddInteger(SVOffset);
   ID.AddInteger(Alignment);
   ID.AddInteger(isVolatile);
   void *IP = 0;
@@ -2337,8 +2407,6 @@ SelectionDAG::getIndexedLoad(SDOperand OrigLoad, SDOperand Base,
   ID.AddInteger(AM);
   ID.AddInteger(LD->getExtensionType());
   ID.AddInteger((unsigned int)(LD->getLoadedVT()));
-  ID.AddPointer(LD->getSrcValue());
-  ID.AddInteger(LD->getSrcValueOffset());
   ID.AddInteger(LD->getAlignment());
   ID.AddInteger(LD->isVolatile());
   void *IP = 0;
@@ -2378,8 +2446,6 @@ SDOperand SelectionDAG::getStore(SDOperand Chain, SDOperand Val,
   ID.AddInteger(ISD::UNINDEXED);
   ID.AddInteger(false);
   ID.AddInteger((unsigned int)VT);
-  ID.AddPointer(SV);
-  ID.AddInteger(SVOffset);
   ID.AddInteger(Alignment);
   ID.AddInteger(isVolatile);
   void *IP = 0;
@@ -2397,9 +2463,12 @@ SDOperand SelectionDAG::getTruncStore(SDOperand Chain, SDOperand Val,
                                       int SVOffset, MVT::ValueType SVT,
                                       bool isVolatile, unsigned Alignment) {
   MVT::ValueType VT = Val.getValueType();
-  bool isTrunc = VT != SVT;
 
-  assert(VT > SVT && "Not a truncation?");
+  if (VT == SVT)
+    return getStore(Chain, Val, Ptr, SV, SVOffset, isVolatile, Alignment);
+
+  assert(MVT::getSizeInBits(VT) > MVT::getSizeInBits(SVT) &&
+         "Not a truncation?");
   assert(MVT::isInteger(VT) == MVT::isInteger(SVT) &&
          "Can't do FP-INT conversion!");
 
@@ -2421,16 +2490,14 @@ SDOperand SelectionDAG::getTruncStore(SDOperand Chain, SDOperand Val,
   FoldingSetNodeID ID;
   AddNodeIDNode(ID, ISD::STORE, VTs, Ops, 4);
   ID.AddInteger(ISD::UNINDEXED);
-  ID.AddInteger(isTrunc);
+  ID.AddInteger(1);
   ID.AddInteger((unsigned int)SVT);
-  ID.AddPointer(SV);
-  ID.AddInteger(SVOffset);
   ID.AddInteger(Alignment);
   ID.AddInteger(isVolatile);
   void *IP = 0;
   if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP))
     return SDOperand(E, 0);
-  SDNode *N = new StoreSDNode(Ops, VTs, ISD::UNINDEXED, isTrunc,
+  SDNode *N = new StoreSDNode(Ops, VTs, ISD::UNINDEXED, true,
                               SVT, SV, SVOffset, Alignment, isVolatile);
   CSEMap.InsertNode(N, IP);
   AllNodes.push_back(N);
@@ -2450,8 +2517,6 @@ SelectionDAG::getIndexedStore(SDOperand OrigStore, SDOperand Base,
   ID.AddInteger(AM);
   ID.AddInteger(ST->isTruncatingStore());
   ID.AddInteger((unsigned int)(ST->getStoredVT()));
-  ID.AddPointer(ST->getSrcValue());
-  ID.AddInteger(ST->getSrcValueOffset());
   ID.AddInteger(ST->getAlignment());
   ID.AddInteger(ST->isVolatile());
   void *IP = 0;
@@ -2632,18 +2697,7 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, SDVTList VTList,
 }
 
 SDVTList SelectionDAG::getVTList(MVT::ValueType VT) {
-  if (!MVT::isExtendedVT(VT))
-    return makeVTList(SDNode::getValueTypeList(VT), 1);
-
-  for (std::list<std::vector<MVT::ValueType> >::iterator I = VTList.begin(),
-       E = VTList.end(); I != E; ++I) {
-    if (I->size() == 1 && (*I)[0] == VT)
-      return makeVTList(&(*I)[0], 1);
-  }
-  std::vector<MVT::ValueType> V;
-  V.push_back(VT);
-  VTList.push_front(V);
-  return makeVTList(&(*VTList.begin())[0], 1);
+  return makeVTList(SDNode::getValueTypeList(VT), 1);
 }
 
 SDVTList SelectionDAG::getVTList(MVT::ValueType VT1, MVT::ValueType VT2) {
@@ -3229,11 +3283,11 @@ void SelectionDAG::ReplaceAllUsesWith(SDNode *From,
 /// uses of other values produced by From.Val alone.  The Deleted vector is
 /// handled the same was as for ReplaceAllUsesWith.
 void SelectionDAG::ReplaceAllUsesOfValueWith(SDOperand From, SDOperand To,
-                                             std::vector<SDNode*> &Deleted) {
+                                             std::vector<SDNode*> *Deleted) {
   assert(From != To && "Cannot replace a value with itself");
   // Handle the simple, trivial, case efficiently.
   if (From.Val->getNumValues() == 1 && To.Val->getNumValues() == 1) {
-    ReplaceAllUsesWith(From, To, &Deleted);
+    ReplaceAllUsesWith(From, To, Deleted);
     return;
   }
   
@@ -3241,48 +3295,66 @@ void SelectionDAG::ReplaceAllUsesOfValueWith(SDOperand From, SDOperand To,
   // deterministically ordered and uniqued set, so we use a SmallSetVector.
   SmallSetVector<SDNode*, 16> Users(From.Val->use_begin(), From.Val->use_end());
 
+  std::vector<SDNode*> LocalDeletionVector;
+  
+  // Pick a deletion vector to use.  If the user specified one, use theirs,
+  // otherwise use a local one.
+  std::vector<SDNode*> *DeleteVector = Deleted ? Deleted : &LocalDeletionVector;
   while (!Users.empty()) {
     // We know that this user uses some value of From.  If it is the right
     // value, update it.
     SDNode *User = Users.back();
     Users.pop_back();
     
-    for (SDOperand *Op = User->OperandList,
-         *E = User->OperandList+User->NumOperands; Op != E; ++Op) {
+    // Scan for an operand that matches From.
+    SDOperand *Op = User->OperandList, *E = User->OperandList+User->NumOperands;
+    for (; Op != E; ++Op)
+      if (*Op == From) break;
+    
+    // If there are no matches, the user must use some other result of From.
+    if (Op == E) continue;
+      
+    // Okay, we know this user needs to be updated.  Remove its old self
+    // from the CSE maps.
+    RemoveNodeFromCSEMaps(User);
+    
+    // Update all operands that match "From".
+    for (; Op != E; ++Op) {
       if (*Op == From) {
-        // Okay, we know this user needs to be updated.  Remove its old self
-        // from the CSE maps.
-        RemoveNodeFromCSEMaps(User);
-        
-        // Update all operands that match "From".
-        for (; Op != E; ++Op) {
-          if (*Op == From) {
-            From.Val->removeUser(User);
-            *Op = To;
-            To.Val->addUser(User);
-          }
-        }
-                   
-        // Now that we have modified User, add it back to the CSE maps.  If it
-        // already exists there, recursively merge the results together.
-        if (SDNode *Existing = AddNonLeafNodeToCSEMaps(User)) {
-          unsigned NumDeleted = Deleted.size();
-          ReplaceAllUsesWith(User, Existing, &Deleted);
-          
-          // User is now dead.
-          Deleted.push_back(User);
-          DeleteNodeNotInCSEMaps(User);
-          
-          // We have to be careful here, because ReplaceAllUsesWith could have
-          // deleted a user of From, which means there may be dangling pointers
-          // in the "Users" setvector.  Scan over the deleted node pointers and
-          // remove them from the setvector.
-          for (unsigned i = NumDeleted, e = Deleted.size(); i != e; ++i)
-            Users.remove(Deleted[i]);
-        }
-        break;   // Exit the operand scanning loop.
+        From.Val->removeUser(User);
+        *Op = To;
+        To.Val->addUser(User);
       }
     }
+               
+    // Now that we have modified User, add it back to the CSE maps.  If it
+    // already exists there, recursively merge the results together.
+    SDNode *Existing = AddNonLeafNodeToCSEMaps(User);
+    if (!Existing) continue;  // Continue on to next user.
+    
+    // If there was already an existing matching node, use ReplaceAllUsesWith
+    // to replace the dead one with the existing one.  However, this can cause
+    // recursive merging of other unrelated nodes down the line.  The merging
+    // can cause deletion of nodes that used the old value.  In this case,
+    // we have to be certain to remove them from the Users set.
+    unsigned NumDeleted = DeleteVector->size();
+    ReplaceAllUsesWith(User, Existing, DeleteVector);
+    
+    // User is now dead.
+    DeleteVector->push_back(User);
+    DeleteNodeNotInCSEMaps(User);
+    
+    // We have to be careful here, because ReplaceAllUsesWith could have
+    // deleted a user of From, which means there may be dangling pointers
+    // in the "Users" setvector.  Scan over the deleted node pointers and
+    // remove them from the setvector.
+    for (unsigned i = NumDeleted, e = DeleteVector->size(); i != e; ++i)
+      Users.remove((*DeleteVector)[i]);
+
+    // If the user doesn't need the set of deleted elements, don't retain them
+    // to the next loop iteration.
+    if (Deleted == 0)
+      LocalDeletionVector.clear();
   }
 }
 
@@ -3393,11 +3465,16 @@ void SDNode::Profile(FoldingSetNodeID &ID) {
 /// getValueTypeList - Return a pointer to the specified value type.
 ///
 MVT::ValueType *SDNode::getValueTypeList(MVT::ValueType VT) {
-  static MVT::ValueType VTs[MVT::LAST_VALUETYPE];
-  VTs[VT] = VT;
-  return &VTs[VT];
+  if (MVT::isExtendedVT(VT)) {
+    static std::set<MVT::ValueType> EVTs;
+    return (MVT::ValueType *)&(*EVTs.insert(VT).first);
+  } else {
+    static MVT::ValueType VTs[MVT::LAST_VALUETYPE];
+    VTs[VT] = VT;
+    return &VTs[VT];
+  }
 }
-  
+
 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
 /// indicated value.  This method ignores uses of other values defined by this
 /// operation.
@@ -3486,6 +3563,37 @@ bool SDNode::isOperand(SDNode *N) const {
   return false;
 }
 
+/// reachesChainWithoutSideEffects - Return true if this operand (which must
+/// be a chain) reaches the specified operand without crossing any 
+/// side-effecting instructions.  In practice, this looks through token
+/// factors and non-volatile loads.  In order to remain efficient, this only
+/// looks a couple of nodes in, it does not do an exhaustive search.
+bool SDOperand::reachesChainWithoutSideEffects(SDOperand Dest, 
+                                               unsigned Depth) const {
+  if (*this == Dest) return true;
+  
+  // Don't search too deeply, we just want to be able to see through
+  // TokenFactor's etc.
+  if (Depth == 0) return false;
+  
+  // If this is a token factor, all inputs to the TF happen in parallel.  If any
+  // of the operands of the TF reach dest, then we can do the xform.
+  if (getOpcode() == ISD::TokenFactor) {
+    for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
+      if (getOperand(i).reachesChainWithoutSideEffects(Dest, Depth-1))
+        return true;
+    return false;
+  }
+  
+  // Loads don't have side effects, look through them.
+  if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(*this)) {
+    if (!Ld->isVolatile())
+      return Ld->getChain().reachesChainWithoutSideEffects(Dest, Depth-1);
+  }
+  return false;
+}
+
+
 static void findPredecessor(SDNode *N, const SDNode *P, bool &found,
                             SmallPtrSet<SDNode *, 32> &Visited) {
   if (found || !Visited.insert(N))
@@ -3526,7 +3634,7 @@ std::string SDNode::getOperationName(const SelectionDAG *G) const {
       if (G) {
         if (const TargetInstrInfo *TII = G->getTarget().getInstrInfo())
           if (getOpcode()-ISD::BUILTIN_OP_END < TII->getNumOpcodes())
-            return TII->getName(getOpcode()-ISD::BUILTIN_OP_END);
+            return TII->get(getOpcode()-ISD::BUILTIN_OP_END).getName();
 
         TargetLowering &TLI = G->getTargetLoweringInfo();
         const char *Name =
@@ -3602,6 +3710,7 @@ std::string SDNode::getOperationName(const SelectionDAG *G) const {
   case ISD::FSIN:   return "fsin";
   case ISD::FCOS:   return "fcos";
   case ISD::FPOWI:  return "fpowi";
+  case ISD::FPOW:   return "fpow";
 
   // Binary operators
   case ISD::ADD:    return "add";
@@ -3631,6 +3740,7 @@ std::string SDNode::getOperationName(const SelectionDAG *G) const {
   case ISD::FDIV:   return "fdiv";
   case ISD::FREM:   return "frem";
   case ISD::FCOPYSIGN: return "fcopysign";
+  case ISD::FGETSIGN:  return "fgetsign";
 
   case ISD::SETCC:       return "setcc";
   case ISD::SELECT:      return "select";
@@ -3660,6 +3770,7 @@ std::string SDNode::getOperationName(const SelectionDAG *G) const {
   case ISD::SIGN_EXTEND_INREG: return "sign_extend_inreg";
   case ISD::TRUNCATE:    return "truncate";
   case ISD::FP_ROUND:    return "fp_round";
+  case ISD::FLT_ROUNDS:  return "flt_rounds";
   case ISD::FP_ROUND_INREG: return "fp_round_inreg";
   case ISD::FP_EXTEND:   return "fp_extend";
 
@@ -3691,7 +3802,8 @@ std::string SDNode::getOperationName(const SelectionDAG *G) const {
   case ISD::BUILD_PAIR:         return "build_pair";
   case ISD::STACKSAVE:          return "stacksave";
   case ISD::STACKRESTORE:       return "stackrestore";
-    
+  case ISD::TRAP:               return "trap";
+
   // Block memory operations.
   case ISD::MEMSET:  return "memset";
   case ISD::MEMCPY:  return "memcpy";
@@ -3775,6 +3887,19 @@ void SDNode::dump(const SelectionDAG *G) const {
       cerr << ":" << RN;
   }
 
+  if (!isTargetOpcode() && getOpcode() == ISD::VECTOR_SHUFFLE) {
+    SDNode *Mask = getOperand(2).Val;
+    cerr << "<";
+    for (unsigned i = 0, e = Mask->getNumOperands(); i != e; ++i) {
+      if (i) cerr << ",";
+      if (Mask->getOperand(i).getOpcode() == ISD::UNDEF)
+        cerr << "u";
+      else
+        cerr << cast<ConstantSDNode>(Mask->getOperand(i))->getValue();
+    }
+    cerr << ">";
+  }
+
   if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(this)) {
     cerr << "<" << CSDN->getValue() << ">";
   } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(this)) {
@@ -3833,6 +3958,15 @@ void SDNode::dump(const SelectionDAG *G) const {
   } else if (const VTSDNode *N = dyn_cast<VTSDNode>(this)) {
     cerr << ":" << MVT::getValueTypeString(N->getVT());
   } else if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(this)) {
+    const Value *SrcValue = LD->getSrcValue();
+    int SrcOffset = LD->getSrcValueOffset();
+    cerr << " <";
+    if (SrcValue)
+      cerr << SrcValue;
+    else
+      cerr << "null";
+    cerr << ":" << SrcOffset << ">";
+
     bool doExt = true;
     switch (LD->getExtensionType()) {
     default: doExt = false; break;
@@ -3852,7 +3986,19 @@ void SDNode::dump(const SelectionDAG *G) const {
     const char *AM = getIndexedModeName(LD->getAddressingMode());
     if (*AM)
       cerr << " " << AM;
+    if (LD->isVolatile())
+      cerr << " <volatile>";
+    cerr << " alignment=" << LD->getAlignment();
   } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(this)) {
+    const Value *SrcValue = ST->getSrcValue();
+    int SrcOffset = ST->getSrcValueOffset();
+    cerr << " <";
+    if (SrcValue)
+      cerr << SrcValue;
+    else
+      cerr << "null";
+    cerr << ":" << SrcOffset << ">";
+
     if (ST->isTruncatingStore())
       cerr << " <trunc "
            << MVT::getValueTypeString(ST->getStoredVT()) << ">";
@@ -3860,6 +4006,9 @@ void SDNode::dump(const SelectionDAG *G) const {
     const char *AM = getIndexedModeName(ST->getAddressingMode());
     if (*AM)
       cerr << " " << AM;
+    if (ST->isVolatile())
+      cerr << " <volatile>";
+    cerr << " alignment=" << ST->getAlignment();
   }
 }