LLVM API Documentation

LegalizeVectorOps.cpp
Go to the documentation of this file.
00001 //===-- LegalizeVectorOps.cpp - Implement SelectionDAG::LegalizeVectors ---===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements the SelectionDAG::LegalizeVectors method.
00011 //
00012 // The vector legalizer looks for vector operations which might need to be
00013 // scalarized and legalizes them. This is a separate step from Legalize because
00014 // scalarizing can introduce illegal types.  For example, suppose we have an
00015 // ISD::SDIV of type v2i64 on x86-32.  The type is legal (for example, addition
00016 // on a v2i64 is legal), but ISD::SDIV isn't legal, so we have to unroll the
00017 // operation, which introduces nodes with the illegal type i64 which must be
00018 // expanded.  Similarly, suppose we have an ISD::SRA of type v16i8 on PowerPC;
00019 // the operation must be unrolled, which introduces nodes with the illegal
00020 // type i8 which must be promoted.
00021 //
00022 // This does not legalize vector manipulations like ISD::BUILD_VECTOR,
00023 // or operations that happen to take a vector which are custom-lowered;
00024 // the legalization for such operations never produces nodes
00025 // with illegal types, so it's okay to put off legalizing them until
00026 // SelectionDAG::Legalize runs.
00027 //
00028 //===----------------------------------------------------------------------===//
00029 
00030 #include "llvm/CodeGen/SelectionDAG.h"
00031 #include "llvm/Target/TargetLowering.h"
00032 using namespace llvm;
00033 
00034 namespace {
00035 class VectorLegalizer {
00036   SelectionDAG& DAG;
00037   const TargetLowering &TLI;
00038   bool Changed; // Keep track of whether anything changed
00039 
00040   /// For nodes that are of legal width, and that have more than one use, this
00041   /// map indicates what regularized operand to use.  This allows us to avoid
00042   /// legalizing the same thing more than once.
00043   SmallDenseMap<SDValue, SDValue, 64> LegalizedNodes;
00044 
00045   /// \brief Adds a node to the translation cache.
00046   void AddLegalizedOperand(SDValue From, SDValue To) {
00047     LegalizedNodes.insert(std::make_pair(From, To));
00048     // If someone requests legalization of the new node, return itself.
00049     if (From != To)
00050       LegalizedNodes.insert(std::make_pair(To, To));
00051   }
00052 
00053   /// \brief Legalizes the given node.
00054   SDValue LegalizeOp(SDValue Op);
00055 
00056   /// \brief Assuming the node is legal, "legalize" the results.
00057   SDValue TranslateLegalizeResults(SDValue Op, SDValue Result);
00058 
00059   /// \brief Implements unrolling a VSETCC.
00060   SDValue UnrollVSETCC(SDValue Op);
00061 
00062   /// \brief Implement expand-based legalization of vector operations.
00063   ///
00064   /// This is just a high-level routine to dispatch to specific code paths for
00065   /// operations to legalize them.
00066   SDValue Expand(SDValue Op);
00067 
00068   /// \brief Implements expansion for FNEG; falls back to UnrollVectorOp if
00069   /// FSUB isn't legal.
00070   ///
00071   /// Implements expansion for UINT_TO_FLOAT; falls back to UnrollVectorOp if
00072   /// SINT_TO_FLOAT and SHR on vectors isn't legal.
00073   SDValue ExpandUINT_TO_FLOAT(SDValue Op);
00074 
00075   /// \brief Implement expansion for SIGN_EXTEND_INREG using SRL and SRA.
00076   SDValue ExpandSEXTINREG(SDValue Op);
00077 
00078   /// \brief Implement expansion for ANY_EXTEND_VECTOR_INREG.
00079   ///
00080   /// Shuffles the low lanes of the operand into place and bitcasts to the proper
00081   /// type. The contents of the bits in the extended part of each element are
00082   /// undef.
00083   SDValue ExpandANY_EXTEND_VECTOR_INREG(SDValue Op);
00084 
00085   /// \brief Implement expansion for SIGN_EXTEND_VECTOR_INREG.
00086   ///
00087   /// Shuffles the low lanes of the operand into place, bitcasts to the proper
00088   /// type, then shifts left and arithmetic shifts right to introduce a sign
00089   /// extension.
00090   SDValue ExpandSIGN_EXTEND_VECTOR_INREG(SDValue Op);
00091 
00092   /// \brief Implement expansion for ZERO_EXTEND_VECTOR_INREG.
00093   ///
00094   /// Shuffles the low lanes of the operand into place and blends zeros into
00095   /// the remaining lanes, finally bitcasting to the proper type.
00096   SDValue ExpandZERO_EXTEND_VECTOR_INREG(SDValue Op);
00097 
00098   /// \brief Expand bswap of vectors into a shuffle if legal.
00099   SDValue ExpandBSWAP(SDValue Op);
00100 
00101   /// \brief Implement vselect in terms of XOR, AND, OR when blend is not
00102   /// supported by the target.
00103   SDValue ExpandVSELECT(SDValue Op);
00104   SDValue ExpandSELECT(SDValue Op);
00105   SDValue ExpandLoad(SDValue Op);
00106   SDValue ExpandStore(SDValue Op);
00107   SDValue ExpandFNEG(SDValue Op);
00108 
00109   /// \brief Implements vector promotion.
00110   ///
00111   /// This is essentially just bitcasting the operands to a different type and
00112   /// bitcasting the result back to the original type.
00113   SDValue Promote(SDValue Op);
00114 
00115   /// \brief Implements [SU]INT_TO_FP vector promotion.
00116   ///
00117   /// This is a [zs]ext of the input operand to the next size up.
00118   SDValue PromoteINT_TO_FP(SDValue Op);
00119 
00120   /// \brief Implements FP_TO_[SU]INT vector promotion of the result type.
00121   ///
00122   /// It is promoted to the next size up integer type.  The result is then
00123   /// truncated back to the original type.
00124   SDValue PromoteFP_TO_INT(SDValue Op, bool isSigned);
00125 
00126 public:
00127   /// \brief Begin legalizer the vector operations in the DAG.
00128   bool Run();
00129   VectorLegalizer(SelectionDAG& dag) :
00130       DAG(dag), TLI(dag.getTargetLoweringInfo()), Changed(false) {}
00131 };
00132 
00133 bool VectorLegalizer::Run() {
00134   // Before we start legalizing vector nodes, check if there are any vectors.
00135   bool HasVectors = false;
00136   for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(),
00137        E = std::prev(DAG.allnodes_end()); I != std::next(E); ++I) {
00138     // Check if the values of the nodes contain vectors. We don't need to check
00139     // the operands because we are going to check their values at some point.
00140     for (SDNode::value_iterator J = I->value_begin(), E = I->value_end();
00141          J != E; ++J)
00142       HasVectors |= J->isVector();
00143 
00144     // If we found a vector node we can start the legalization.
00145     if (HasVectors)
00146       break;
00147   }
00148 
00149   // If this basic block has no vectors then no need to legalize vectors.
00150   if (!HasVectors)
00151     return false;
00152 
00153   // The legalize process is inherently a bottom-up recursive process (users
00154   // legalize their uses before themselves).  Given infinite stack space, we
00155   // could just start legalizing on the root and traverse the whole graph.  In
00156   // practice however, this causes us to run out of stack space on large basic
00157   // blocks.  To avoid this problem, compute an ordering of the nodes where each
00158   // node is only legalized after all of its operands are legalized.
00159   DAG.AssignTopologicalOrder();
00160   for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(),
00161        E = std::prev(DAG.allnodes_end()); I != std::next(E); ++I)
00162     LegalizeOp(SDValue(I, 0));
00163 
00164   // Finally, it's possible the root changed.  Get the new root.
00165   SDValue OldRoot = DAG.getRoot();
00166   assert(LegalizedNodes.count(OldRoot) && "Root didn't get legalized?");
00167   DAG.setRoot(LegalizedNodes[OldRoot]);
00168 
00169   LegalizedNodes.clear();
00170 
00171   // Remove dead nodes now.
00172   DAG.RemoveDeadNodes();
00173 
00174   return Changed;
00175 }
00176 
00177 SDValue VectorLegalizer::TranslateLegalizeResults(SDValue Op, SDValue Result) {
00178   // Generic legalization: just pass the operand through.
00179   for (unsigned i = 0, e = Op.getNode()->getNumValues(); i != e; ++i)
00180     AddLegalizedOperand(Op.getValue(i), Result.getValue(i));
00181   return Result.getValue(Op.getResNo());
00182 }
00183 
00184 SDValue VectorLegalizer::LegalizeOp(SDValue Op) {
00185   // Note that LegalizeOp may be reentered even from single-use nodes, which
00186   // means that we always must cache transformed nodes.
00187   DenseMap<SDValue, SDValue>::iterator I = LegalizedNodes.find(Op);
00188   if (I != LegalizedNodes.end()) return I->second;
00189 
00190   SDNode* Node = Op.getNode();
00191 
00192   // Legalize the operands
00193   SmallVector<SDValue, 8> Ops;
00194   for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i)
00195     Ops.push_back(LegalizeOp(Node->getOperand(i)));
00196 
00197   SDValue Result = SDValue(DAG.UpdateNodeOperands(Op.getNode(), Ops), 0);
00198 
00199   if (Op.getOpcode() == ISD::LOAD) {
00200     LoadSDNode *LD = cast<LoadSDNode>(Op.getNode());
00201     ISD::LoadExtType ExtType = LD->getExtensionType();
00202     if (LD->getMemoryVT().isVector() && ExtType != ISD::NON_EXTLOAD)
00203       switch (TLI.getLoadExtAction(LD->getExtensionType(), LD->getMemoryVT())) {
00204       default: llvm_unreachable("This action is not supported yet!");
00205       case TargetLowering::Legal:
00206         return TranslateLegalizeResults(Op, Result);
00207       case TargetLowering::Custom:
00208         if (SDValue Lowered = TLI.LowerOperation(Result, DAG)) {
00209           Changed = true;
00210           if (Lowered->getNumValues() != Op->getNumValues()) {
00211             // This expanded to something other than the load. Assume the
00212             // lowering code took care of any chain values, and just handle the
00213             // returned value.
00214             assert(Result.getValue(1).use_empty() &&
00215                    "There are still live users of the old chain!");
00216             return LegalizeOp(Lowered);
00217           } else {
00218             return TranslateLegalizeResults(Op, Lowered);
00219           }
00220         }
00221       case TargetLowering::Expand:
00222         Changed = true;
00223         return LegalizeOp(ExpandLoad(Op));
00224       }
00225   } else if (Op.getOpcode() == ISD::STORE) {
00226     StoreSDNode *ST = cast<StoreSDNode>(Op.getNode());
00227     EVT StVT = ST->getMemoryVT();
00228     MVT ValVT = ST->getValue().getSimpleValueType();
00229     if (StVT.isVector() && ST->isTruncatingStore())
00230       switch (TLI.getTruncStoreAction(ValVT, StVT.getSimpleVT())) {
00231       default: llvm_unreachable("This action is not supported yet!");
00232       case TargetLowering::Legal:
00233         return TranslateLegalizeResults(Op, Result);
00234       case TargetLowering::Custom:
00235         Changed = true;
00236         return TranslateLegalizeResults(Op, TLI.LowerOperation(Result, DAG));
00237       case TargetLowering::Expand:
00238         Changed = true;
00239         return LegalizeOp(ExpandStore(Op));
00240       }
00241   }
00242 
00243   bool HasVectorValue = false;
00244   for (SDNode::value_iterator J = Node->value_begin(), E = Node->value_end();
00245        J != E;
00246        ++J)
00247     HasVectorValue |= J->isVector();
00248   if (!HasVectorValue)
00249     return TranslateLegalizeResults(Op, Result);
00250 
00251   EVT QueryType;
00252   switch (Op.getOpcode()) {
00253   default:
00254     return TranslateLegalizeResults(Op, Result);
00255   case ISD::ADD:
00256   case ISD::SUB:
00257   case ISD::MUL:
00258   case ISD::SDIV:
00259   case ISD::UDIV:
00260   case ISD::SREM:
00261   case ISD::UREM:
00262   case ISD::FADD:
00263   case ISD::FSUB:
00264   case ISD::FMUL:
00265   case ISD::FDIV:
00266   case ISD::FREM:
00267   case ISD::AND:
00268   case ISD::OR:
00269   case ISD::XOR:
00270   case ISD::SHL:
00271   case ISD::SRA:
00272   case ISD::SRL:
00273   case ISD::ROTL:
00274   case ISD::ROTR:
00275   case ISD::BSWAP:
00276   case ISD::CTLZ:
00277   case ISD::CTTZ:
00278   case ISD::CTLZ_ZERO_UNDEF:
00279   case ISD::CTTZ_ZERO_UNDEF:
00280   case ISD::CTPOP:
00281   case ISD::SELECT:
00282   case ISD::VSELECT:
00283   case ISD::SELECT_CC:
00284   case ISD::SETCC:
00285   case ISD::ZERO_EXTEND:
00286   case ISD::ANY_EXTEND:
00287   case ISD::TRUNCATE:
00288   case ISD::SIGN_EXTEND:
00289   case ISD::FP_TO_SINT:
00290   case ISD::FP_TO_UINT:
00291   case ISD::FNEG:
00292   case ISD::FABS:
00293   case ISD::FCOPYSIGN:
00294   case ISD::FSQRT:
00295   case ISD::FSIN:
00296   case ISD::FCOS:
00297   case ISD::FPOWI:
00298   case ISD::FPOW:
00299   case ISD::FLOG:
00300   case ISD::FLOG2:
00301   case ISD::FLOG10:
00302   case ISD::FEXP:
00303   case ISD::FEXP2:
00304   case ISD::FCEIL:
00305   case ISD::FTRUNC:
00306   case ISD::FRINT:
00307   case ISD::FNEARBYINT:
00308   case ISD::FROUND:
00309   case ISD::FFLOOR:
00310   case ISD::FP_ROUND:
00311   case ISD::FP_EXTEND:
00312   case ISD::FMA:
00313   case ISD::SIGN_EXTEND_INREG:
00314   case ISD::ANY_EXTEND_VECTOR_INREG:
00315   case ISD::SIGN_EXTEND_VECTOR_INREG:
00316   case ISD::ZERO_EXTEND_VECTOR_INREG:
00317     QueryType = Node->getValueType(0);
00318     break;
00319   case ISD::FP_ROUND_INREG:
00320     QueryType = cast<VTSDNode>(Node->getOperand(1))->getVT();
00321     break;
00322   case ISD::SINT_TO_FP:
00323   case ISD::UINT_TO_FP:
00324     QueryType = Node->getOperand(0).getValueType();
00325     break;
00326   }
00327 
00328   switch (TLI.getOperationAction(Node->getOpcode(), QueryType)) {
00329   case TargetLowering::Promote:
00330     Result = Promote(Op);
00331     Changed = true;
00332     break;
00333   case TargetLowering::Legal:
00334     break;
00335   case TargetLowering::Custom: {
00336     SDValue Tmp1 = TLI.LowerOperation(Op, DAG);
00337     if (Tmp1.getNode()) {
00338       Result = Tmp1;
00339       break;
00340     }
00341     // FALL THROUGH
00342   }
00343   case TargetLowering::Expand:
00344     Result = Expand(Op);
00345   }
00346 
00347   // Make sure that the generated code is itself legal.
00348   if (Result != Op) {
00349     Result = LegalizeOp(Result);
00350     Changed = true;
00351   }
00352 
00353   // Note that LegalizeOp may be reentered even from single-use nodes, which
00354   // means that we always must cache transformed nodes.
00355   AddLegalizedOperand(Op, Result);
00356   return Result;
00357 }
00358 
00359 SDValue VectorLegalizer::Promote(SDValue Op) {
00360   // For a few operations there is a specific concept for promotion based on
00361   // the operand's type.
00362   switch (Op.getOpcode()) {
00363   case ISD::SINT_TO_FP:
00364   case ISD::UINT_TO_FP:
00365     // "Promote" the operation by extending the operand.
00366     return PromoteINT_TO_FP(Op);
00367   case ISD::FP_TO_UINT:
00368   case ISD::FP_TO_SINT:
00369     // Promote the operation by extending the operand.
00370     return PromoteFP_TO_INT(Op, Op->getOpcode() == ISD::FP_TO_SINT);
00371   }
00372 
00373   // There are currently two cases of vector promotion:
00374   // 1) Bitcasting a vector of integers to a different type to a vector of the
00375   //    same overall length. For example, x86 promotes ISD::AND on v2i32 to v1i64.
00376   // 2) Extending a vector of floats to a vector of the same number oflarger
00377   //    floats. For example, AArch64 promotes ISD::FADD on v4f16 to v4f32.
00378   MVT VT = Op.getSimpleValueType();
00379   assert(Op.getNode()->getNumValues() == 1 &&
00380          "Can't promote a vector with multiple results!");
00381   MVT NVT = TLI.getTypeToPromoteTo(Op.getOpcode(), VT);
00382   SDLoc dl(Op);
00383   SmallVector<SDValue, 4> Operands(Op.getNumOperands());
00384 
00385   for (unsigned j = 0; j != Op.getNumOperands(); ++j) {
00386     if (Op.getOperand(j).getValueType().isVector())
00387       if (Op.getOperand(j)
00388               .getValueType()
00389               .getVectorElementType()
00390               .isFloatingPoint())
00391         Operands[j] = DAG.getNode(ISD::FP_EXTEND, dl, NVT, Op.getOperand(j));
00392       else
00393         Operands[j] = DAG.getNode(ISD::BITCAST, dl, NVT, Op.getOperand(j));
00394     else
00395       Operands[j] = Op.getOperand(j);
00396   }
00397 
00398   Op = DAG.getNode(Op.getOpcode(), dl, NVT, Operands);
00399   if (VT.isFloatingPoint() ||
00400       (VT.isVector() && VT.getVectorElementType().isFloatingPoint()))
00401     return DAG.getNode(ISD::FP_ROUND, dl, VT, Op, DAG.getIntPtrConstant(0));
00402   else
00403     return DAG.getNode(ISD::BITCAST, dl, VT, Op);
00404 }
00405 
00406 SDValue VectorLegalizer::PromoteINT_TO_FP(SDValue Op) {
00407   // INT_TO_FP operations may require the input operand be promoted even
00408   // when the type is otherwise legal.
00409   EVT VT = Op.getOperand(0).getValueType();
00410   assert(Op.getNode()->getNumValues() == 1 &&
00411          "Can't promote a vector with multiple results!");
00412 
00413   // Normal getTypeToPromoteTo() doesn't work here, as that will promote
00414   // by widening the vector w/ the same element width and twice the number
00415   // of elements. We want the other way around, the same number of elements,
00416   // each twice the width.
00417   //
00418   // Increase the bitwidth of the element to the next pow-of-two
00419   // (which is greater than 8 bits).
00420 
00421   EVT NVT = VT.widenIntegerVectorElementType(*DAG.getContext());
00422   assert(NVT.isSimple() && "Promoting to a non-simple vector type!");
00423   SDLoc dl(Op);
00424   SmallVector<SDValue, 4> Operands(Op.getNumOperands());
00425 
00426   unsigned Opc = Op.getOpcode() == ISD::UINT_TO_FP ? ISD::ZERO_EXTEND :
00427     ISD::SIGN_EXTEND;
00428   for (unsigned j = 0; j != Op.getNumOperands(); ++j) {
00429     if (Op.getOperand(j).getValueType().isVector())
00430       Operands[j] = DAG.getNode(Opc, dl, NVT, Op.getOperand(j));
00431     else
00432       Operands[j] = Op.getOperand(j);
00433   }
00434 
00435   return DAG.getNode(Op.getOpcode(), dl, Op.getValueType(), Operands);
00436 }
00437 
00438 // For FP_TO_INT we promote the result type to a vector type with wider
00439 // elements and then truncate the result.  This is different from the default
00440 // PromoteVector which uses bitcast to promote thus assumning that the
00441 // promoted vector type has the same overall size.
00442 SDValue VectorLegalizer::PromoteFP_TO_INT(SDValue Op, bool isSigned) {
00443   assert(Op.getNode()->getNumValues() == 1 &&
00444          "Can't promote a vector with multiple results!");
00445   EVT VT = Op.getValueType();
00446 
00447   EVT NewVT;
00448   unsigned NewOpc;
00449   while (1) {
00450     NewVT = VT.widenIntegerVectorElementType(*DAG.getContext());
00451     assert(NewVT.isSimple() && "Promoting to a non-simple vector type!");
00452     if (TLI.isOperationLegalOrCustom(ISD::FP_TO_SINT, NewVT)) {
00453       NewOpc = ISD::FP_TO_SINT;
00454       break;
00455     }
00456     if (!isSigned && TLI.isOperationLegalOrCustom(ISD::FP_TO_UINT, NewVT)) {
00457       NewOpc = ISD::FP_TO_UINT;
00458       break;
00459     }
00460   }
00461 
00462   SDLoc loc(Op);
00463   SDValue promoted  = DAG.getNode(NewOpc, SDLoc(Op), NewVT, Op.getOperand(0));
00464   return DAG.getNode(ISD::TRUNCATE, SDLoc(Op), VT, promoted);
00465 }
00466 
00467 
00468 SDValue VectorLegalizer::ExpandLoad(SDValue Op) {
00469   SDLoc dl(Op);
00470   LoadSDNode *LD = cast<LoadSDNode>(Op.getNode());
00471   SDValue Chain = LD->getChain();
00472   SDValue BasePTR = LD->getBasePtr();
00473   EVT SrcVT = LD->getMemoryVT();
00474   ISD::LoadExtType ExtType = LD->getExtensionType();
00475 
00476   SmallVector<SDValue, 8> Vals;
00477   SmallVector<SDValue, 8> LoadChains;
00478   unsigned NumElem = SrcVT.getVectorNumElements();
00479 
00480   EVT SrcEltVT = SrcVT.getScalarType();
00481   EVT DstEltVT = Op.getNode()->getValueType(0).getScalarType();
00482 
00483   if (SrcVT.getVectorNumElements() > 1 && !SrcEltVT.isByteSized()) {
00484     // When elements in a vector is not byte-addressable, we cannot directly
00485     // load each element by advancing pointer, which could only address bytes.
00486     // Instead, we load all significant words, mask bits off, and concatenate
00487     // them to form each element. Finally, they are extended to destination
00488     // scalar type to build the destination vector.
00489     EVT WideVT = TLI.getPointerTy();
00490 
00491     assert(WideVT.isRound() &&
00492            "Could not handle the sophisticated case when the widest integer is"
00493            " not power of 2.");
00494     assert(WideVT.bitsGE(SrcEltVT) &&
00495            "Type is not legalized?");
00496 
00497     unsigned WideBytes = WideVT.getStoreSize();
00498     unsigned Offset = 0;
00499     unsigned RemainingBytes = SrcVT.getStoreSize();
00500     SmallVector<SDValue, 8> LoadVals;
00501 
00502     while (RemainingBytes > 0) {
00503       SDValue ScalarLoad;
00504       unsigned LoadBytes = WideBytes;
00505 
00506       if (RemainingBytes >= LoadBytes) {
00507         ScalarLoad = DAG.getLoad(WideVT, dl, Chain, BasePTR,
00508                                  LD->getPointerInfo().getWithOffset(Offset),
00509                                  LD->isVolatile(), LD->isNonTemporal(),
00510                                  LD->isInvariant(), LD->getAlignment(),
00511                                  LD->getAAInfo());
00512       } else {
00513         EVT LoadVT = WideVT;
00514         while (RemainingBytes < LoadBytes) {
00515           LoadBytes >>= 1; // Reduce the load size by half.
00516           LoadVT = EVT::getIntegerVT(*DAG.getContext(), LoadBytes << 3);
00517         }
00518         ScalarLoad = DAG.getExtLoad(ISD::EXTLOAD, dl, WideVT, Chain, BasePTR,
00519                                     LD->getPointerInfo().getWithOffset(Offset),
00520                                     LoadVT, LD->isVolatile(),
00521                                     LD->isNonTemporal(), LD->isInvariant(),
00522                                     LD->getAlignment(), LD->getAAInfo());
00523       }
00524 
00525       RemainingBytes -= LoadBytes;
00526       Offset += LoadBytes;
00527       BasePTR = DAG.getNode(ISD::ADD, dl, BasePTR.getValueType(), BasePTR,
00528                             DAG.getConstant(LoadBytes, BasePTR.getValueType()));
00529 
00530       LoadVals.push_back(ScalarLoad.getValue(0));
00531       LoadChains.push_back(ScalarLoad.getValue(1));
00532     }
00533 
00534     // Extract bits, pack and extend/trunc them into destination type.
00535     unsigned SrcEltBits = SrcEltVT.getSizeInBits();
00536     SDValue SrcEltBitMask = DAG.getConstant((1U << SrcEltBits) - 1, WideVT);
00537 
00538     unsigned BitOffset = 0;
00539     unsigned WideIdx = 0;
00540     unsigned WideBits = WideVT.getSizeInBits();
00541 
00542     for (unsigned Idx = 0; Idx != NumElem; ++Idx) {
00543       SDValue Lo, Hi, ShAmt;
00544 
00545       if (BitOffset < WideBits) {
00546         ShAmt = DAG.getConstant(BitOffset, TLI.getShiftAmountTy(WideVT));
00547         Lo = DAG.getNode(ISD::SRL, dl, WideVT, LoadVals[WideIdx], ShAmt);
00548         Lo = DAG.getNode(ISD::AND, dl, WideVT, Lo, SrcEltBitMask);
00549       }
00550 
00551       BitOffset += SrcEltBits;
00552       if (BitOffset >= WideBits) {
00553         WideIdx++;
00554         Offset -= WideBits;
00555         if (Offset > 0) {
00556           ShAmt = DAG.getConstant(SrcEltBits - Offset,
00557                                   TLI.getShiftAmountTy(WideVT));
00558           Hi = DAG.getNode(ISD::SHL, dl, WideVT, LoadVals[WideIdx], ShAmt);
00559           Hi = DAG.getNode(ISD::AND, dl, WideVT, Hi, SrcEltBitMask);
00560         }
00561       }
00562 
00563       if (Hi.getNode())
00564         Lo = DAG.getNode(ISD::OR, dl, WideVT, Lo, Hi);
00565 
00566       switch (ExtType) {
00567       default: llvm_unreachable("Unknown extended-load op!");
00568       case ISD::EXTLOAD:
00569         Lo = DAG.getAnyExtOrTrunc(Lo, dl, DstEltVT);
00570         break;
00571       case ISD::ZEXTLOAD:
00572         Lo = DAG.getZExtOrTrunc(Lo, dl, DstEltVT);
00573         break;
00574       case ISD::SEXTLOAD:
00575         ShAmt = DAG.getConstant(WideBits - SrcEltBits,
00576                                 TLI.getShiftAmountTy(WideVT));
00577         Lo = DAG.getNode(ISD::SHL, dl, WideVT, Lo, ShAmt);
00578         Lo = DAG.getNode(ISD::SRA, dl, WideVT, Lo, ShAmt);
00579         Lo = DAG.getSExtOrTrunc(Lo, dl, DstEltVT);
00580         break;
00581       }
00582       Vals.push_back(Lo);
00583     }
00584   } else {
00585     unsigned Stride = SrcVT.getScalarType().getSizeInBits()/8;
00586 
00587     for (unsigned Idx=0; Idx<NumElem; Idx++) {
00588       SDValue ScalarLoad = DAG.getExtLoad(ExtType, dl,
00589                 Op.getNode()->getValueType(0).getScalarType(),
00590                 Chain, BasePTR, LD->getPointerInfo().getWithOffset(Idx * Stride),
00591                 SrcVT.getScalarType(),
00592                 LD->isVolatile(), LD->isNonTemporal(), LD->isInvariant(),
00593                 LD->getAlignment(), LD->getAAInfo());
00594 
00595       BasePTR = DAG.getNode(ISD::ADD, dl, BasePTR.getValueType(), BasePTR,
00596                          DAG.getConstant(Stride, BasePTR.getValueType()));
00597 
00598       Vals.push_back(ScalarLoad.getValue(0));
00599       LoadChains.push_back(ScalarLoad.getValue(1));
00600     }
00601   }
00602 
00603   SDValue NewChain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, LoadChains);
00604   SDValue Value = DAG.getNode(ISD::BUILD_VECTOR, dl,
00605                               Op.getNode()->getValueType(0), Vals);
00606 
00607   AddLegalizedOperand(Op.getValue(0), Value);
00608   AddLegalizedOperand(Op.getValue(1), NewChain);
00609 
00610   return (Op.getResNo() ? NewChain : Value);
00611 }
00612 
00613 SDValue VectorLegalizer::ExpandStore(SDValue Op) {
00614   SDLoc dl(Op);
00615   StoreSDNode *ST = cast<StoreSDNode>(Op.getNode());
00616   SDValue Chain = ST->getChain();
00617   SDValue BasePTR = ST->getBasePtr();
00618   SDValue Value = ST->getValue();
00619   EVT StVT = ST->getMemoryVT();
00620 
00621   unsigned Alignment = ST->getAlignment();
00622   bool isVolatile = ST->isVolatile();
00623   bool isNonTemporal = ST->isNonTemporal();
00624   AAMDNodes AAInfo = ST->getAAInfo();
00625 
00626   unsigned NumElem = StVT.getVectorNumElements();
00627   // The type of the data we want to save
00628   EVT RegVT = Value.getValueType();
00629   EVT RegSclVT = RegVT.getScalarType();
00630   // The type of data as saved in memory.
00631   EVT MemSclVT = StVT.getScalarType();
00632 
00633   // Cast floats into integers
00634   unsigned ScalarSize = MemSclVT.getSizeInBits();
00635 
00636   // Round odd types to the next pow of two.
00637   if (!isPowerOf2_32(ScalarSize))
00638     ScalarSize = NextPowerOf2(ScalarSize);
00639 
00640   // Store Stride in bytes
00641   unsigned Stride = ScalarSize/8;
00642   // Extract each of the elements from the original vector
00643   // and save them into memory individually.
00644   SmallVector<SDValue, 8> Stores;
00645   for (unsigned Idx = 0; Idx < NumElem; Idx++) {
00646     SDValue Ex = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl,
00647                RegSclVT, Value, DAG.getConstant(Idx, TLI.getVectorIdxTy()));
00648 
00649     // This scalar TruncStore may be illegal, but we legalize it later.
00650     SDValue Store = DAG.getTruncStore(Chain, dl, Ex, BasePTR,
00651                ST->getPointerInfo().getWithOffset(Idx*Stride), MemSclVT,
00652                isVolatile, isNonTemporal, Alignment, AAInfo);
00653 
00654     BasePTR = DAG.getNode(ISD::ADD, dl, BasePTR.getValueType(), BasePTR,
00655                                DAG.getConstant(Stride, BasePTR.getValueType()));
00656 
00657     Stores.push_back(Store);
00658   }
00659   SDValue TF =  DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Stores);
00660   AddLegalizedOperand(Op, TF);
00661   return TF;
00662 }
00663 
00664 SDValue VectorLegalizer::Expand(SDValue Op) {
00665   switch (Op->getOpcode()) {
00666   case ISD::SIGN_EXTEND_INREG:
00667     return ExpandSEXTINREG(Op);
00668   case ISD::ANY_EXTEND_VECTOR_INREG:
00669     return ExpandANY_EXTEND_VECTOR_INREG(Op);
00670   case ISD::SIGN_EXTEND_VECTOR_INREG:
00671     return ExpandSIGN_EXTEND_VECTOR_INREG(Op);
00672   case ISD::ZERO_EXTEND_VECTOR_INREG:
00673     return ExpandZERO_EXTEND_VECTOR_INREG(Op);
00674   case ISD::BSWAP:
00675     return ExpandBSWAP(Op);
00676   case ISD::VSELECT:
00677     return ExpandVSELECT(Op);
00678   case ISD::SELECT:
00679     return ExpandSELECT(Op);
00680   case ISD::UINT_TO_FP:
00681     return ExpandUINT_TO_FLOAT(Op);
00682   case ISD::FNEG:
00683     return ExpandFNEG(Op);
00684   case ISD::SETCC:
00685     return UnrollVSETCC(Op);
00686   default:
00687     return DAG.UnrollVectorOp(Op.getNode());
00688   }
00689 }
00690 
00691 SDValue VectorLegalizer::ExpandSELECT(SDValue Op) {
00692   // Lower a select instruction where the condition is a scalar and the
00693   // operands are vectors. Lower this select to VSELECT and implement it
00694   // using XOR AND OR. The selector bit is broadcasted.
00695   EVT VT = Op.getValueType();
00696   SDLoc DL(Op);
00697 
00698   SDValue Mask = Op.getOperand(0);
00699   SDValue Op1 = Op.getOperand(1);
00700   SDValue Op2 = Op.getOperand(2);
00701 
00702   assert(VT.isVector() && !Mask.getValueType().isVector()
00703          && Op1.getValueType() == Op2.getValueType() && "Invalid type");
00704 
00705   unsigned NumElem = VT.getVectorNumElements();
00706 
00707   // If we can't even use the basic vector operations of
00708   // AND,OR,XOR, we will have to scalarize the op.
00709   // Notice that the operation may be 'promoted' which means that it is
00710   // 'bitcasted' to another type which is handled.
00711   // Also, we need to be able to construct a splat vector using BUILD_VECTOR.
00712   if (TLI.getOperationAction(ISD::AND, VT) == TargetLowering::Expand ||
00713       TLI.getOperationAction(ISD::XOR, VT) == TargetLowering::Expand ||
00714       TLI.getOperationAction(ISD::OR,  VT) == TargetLowering::Expand ||
00715       TLI.getOperationAction(ISD::BUILD_VECTOR,  VT) == TargetLowering::Expand)
00716     return DAG.UnrollVectorOp(Op.getNode());
00717 
00718   // Generate a mask operand.
00719   EVT MaskTy = VT.changeVectorElementTypeToInteger();
00720 
00721   // What is the size of each element in the vector mask.
00722   EVT BitTy = MaskTy.getScalarType();
00723 
00724   Mask = DAG.getSelect(DL, BitTy, Mask,
00725           DAG.getConstant(APInt::getAllOnesValue(BitTy.getSizeInBits()), BitTy),
00726           DAG.getConstant(0, BitTy));
00727 
00728   // Broadcast the mask so that the entire vector is all-one or all zero.
00729   SmallVector<SDValue, 8> Ops(NumElem, Mask);
00730   Mask = DAG.getNode(ISD::BUILD_VECTOR, DL, MaskTy, Ops);
00731 
00732   // Bitcast the operands to be the same type as the mask.
00733   // This is needed when we select between FP types because
00734   // the mask is a vector of integers.
00735   Op1 = DAG.getNode(ISD::BITCAST, DL, MaskTy, Op1);
00736   Op2 = DAG.getNode(ISD::BITCAST, DL, MaskTy, Op2);
00737 
00738   SDValue AllOnes = DAG.getConstant(
00739             APInt::getAllOnesValue(BitTy.getSizeInBits()), MaskTy);
00740   SDValue NotMask = DAG.getNode(ISD::XOR, DL, MaskTy, Mask, AllOnes);
00741 
00742   Op1 = DAG.getNode(ISD::AND, DL, MaskTy, Op1, Mask);
00743   Op2 = DAG.getNode(ISD::AND, DL, MaskTy, Op2, NotMask);
00744   SDValue Val = DAG.getNode(ISD::OR, DL, MaskTy, Op1, Op2);
00745   return DAG.getNode(ISD::BITCAST, DL, Op.getValueType(), Val);
00746 }
00747 
00748 SDValue VectorLegalizer::ExpandSEXTINREG(SDValue Op) {
00749   EVT VT = Op.getValueType();
00750 
00751   // Make sure that the SRA and SHL instructions are available.
00752   if (TLI.getOperationAction(ISD::SRA, VT) == TargetLowering::Expand ||
00753       TLI.getOperationAction(ISD::SHL, VT) == TargetLowering::Expand)
00754     return DAG.UnrollVectorOp(Op.getNode());
00755 
00756   SDLoc DL(Op);
00757   EVT OrigTy = cast<VTSDNode>(Op->getOperand(1))->getVT();
00758 
00759   unsigned BW = VT.getScalarType().getSizeInBits();
00760   unsigned OrigBW = OrigTy.getScalarType().getSizeInBits();
00761   SDValue ShiftSz = DAG.getConstant(BW - OrigBW, VT);
00762 
00763   Op = Op.getOperand(0);
00764   Op =   DAG.getNode(ISD::SHL, DL, VT, Op, ShiftSz);
00765   return DAG.getNode(ISD::SRA, DL, VT, Op, ShiftSz);
00766 }
00767 
00768 // Generically expand a vector anyext in register to a shuffle of the relevant
00769 // lanes into the appropriate locations, with other lanes left undef.
00770 SDValue VectorLegalizer::ExpandANY_EXTEND_VECTOR_INREG(SDValue Op) {
00771   SDLoc DL(Op);
00772   EVT VT = Op.getValueType();
00773   int NumElements = VT.getVectorNumElements();
00774   SDValue Src = Op.getOperand(0);
00775   EVT SrcVT = Src.getValueType();
00776   int NumSrcElements = SrcVT.getVectorNumElements();
00777 
00778   // Build a base mask of undef shuffles.
00779   SmallVector<int, 16> ShuffleMask;
00780   ShuffleMask.resize(NumSrcElements, -1);
00781 
00782   // Place the extended lanes into the correct locations.
00783   int ExtLaneScale = NumSrcElements / NumElements;
00784   int EndianOffset = TLI.isBigEndian() ? ExtLaneScale - 1 : 0;
00785   for (int i = 0; i < NumElements; ++i)
00786     ShuffleMask[i * ExtLaneScale + EndianOffset] = i;
00787 
00788   return DAG.getNode(
00789       ISD::BITCAST, DL, VT,
00790       DAG.getVectorShuffle(SrcVT, DL, Src, DAG.getUNDEF(SrcVT), ShuffleMask));
00791 }
00792 
00793 SDValue VectorLegalizer::ExpandSIGN_EXTEND_VECTOR_INREG(SDValue Op) {
00794   SDLoc DL(Op);
00795   EVT VT = Op.getValueType();
00796   SDValue Src = Op.getOperand(0);
00797   EVT SrcVT = Src.getValueType();
00798 
00799   // First build an any-extend node which can be legalized above when we
00800   // recurse through it.
00801   Op = DAG.getAnyExtendVectorInReg(Src, DL, VT);
00802 
00803   // Now we need sign extend. Do this by shifting the elements. Even if these
00804   // aren't legal operations, they have a better chance of being legalized
00805   // without full scalarization than the sign extension does.
00806   unsigned EltWidth = VT.getVectorElementType().getSizeInBits();
00807   unsigned SrcEltWidth = SrcVT.getVectorElementType().getSizeInBits();
00808   SDValue ShiftAmount = DAG.getConstant(EltWidth - SrcEltWidth, VT);
00809   return DAG.getNode(ISD::SRA, DL, VT,
00810                      DAG.getNode(ISD::SHL, DL, VT, Op, ShiftAmount),
00811                      ShiftAmount);
00812 }
00813 
00814 // Generically expand a vector zext in register to a shuffle of the relevant
00815 // lanes into the appropriate locations, a blend of zero into the high bits,
00816 // and a bitcast to the wider element type.
00817 SDValue VectorLegalizer::ExpandZERO_EXTEND_VECTOR_INREG(SDValue Op) {
00818   SDLoc DL(Op);
00819   EVT VT = Op.getValueType();
00820   int NumElements = VT.getVectorNumElements();
00821   SDValue Src = Op.getOperand(0);
00822   EVT SrcVT = Src.getValueType();
00823   int NumSrcElements = SrcVT.getVectorNumElements();
00824 
00825   // Build up a zero vector to blend into this one.
00826   EVT SrcScalarVT = SrcVT.getScalarType();
00827   SDValue ScalarZero = DAG.getTargetConstant(0, SrcScalarVT);
00828   SmallVector<SDValue, 4> BuildVectorOperands(NumSrcElements, ScalarZero);
00829   SDValue Zero = DAG.getNode(ISD::BUILD_VECTOR, DL, SrcVT, BuildVectorOperands);
00830 
00831   // Shuffle the incoming lanes into the correct position, and pull all other
00832   // lanes from the zero vector.
00833   SmallVector<int, 16> ShuffleMask;
00834   ShuffleMask.reserve(NumSrcElements);
00835   for (int i = 0; i < NumSrcElements; ++i)
00836     ShuffleMask.push_back(i);
00837 
00838   int ExtLaneScale = NumSrcElements / NumElements;
00839   int EndianOffset = TLI.isBigEndian() ? ExtLaneScale - 1 : 0;
00840   for (int i = 0; i < NumElements; ++i)
00841     ShuffleMask[i * ExtLaneScale + EndianOffset] = NumSrcElements + i;
00842 
00843   return DAG.getNode(ISD::BITCAST, DL, VT,
00844                      DAG.getVectorShuffle(SrcVT, DL, Zero, Src, ShuffleMask));
00845 }
00846 
00847 SDValue VectorLegalizer::ExpandBSWAP(SDValue Op) {
00848   EVT VT = Op.getValueType();
00849 
00850   // Generate a byte wise shuffle mask for the BSWAP.
00851   SmallVector<int, 16> ShuffleMask;
00852   int ScalarSizeInBytes = VT.getScalarSizeInBits() / 8;
00853   for (int I = 0, E = VT.getVectorNumElements(); I != E; ++I)
00854     for (int J = ScalarSizeInBytes - 1; J >= 0; --J)
00855       ShuffleMask.push_back((I * ScalarSizeInBytes) + J);
00856 
00857   EVT ByteVT = EVT::getVectorVT(*DAG.getContext(), MVT::i8, ShuffleMask.size());
00858 
00859   // Only emit a shuffle if the mask is legal.
00860   if (!TLI.isShuffleMaskLegal(ShuffleMask, ByteVT))
00861     return DAG.UnrollVectorOp(Op.getNode());
00862 
00863   SDLoc DL(Op);
00864   Op = DAG.getNode(ISD::BITCAST, DL, ByteVT, Op.getOperand(0));
00865   Op = DAG.getVectorShuffle(ByteVT, DL, Op, DAG.getUNDEF(ByteVT),
00866                             ShuffleMask.data());
00867   return DAG.getNode(ISD::BITCAST, DL, VT, Op);
00868 }
00869 
00870 SDValue VectorLegalizer::ExpandVSELECT(SDValue Op) {
00871   // Implement VSELECT in terms of XOR, AND, OR
00872   // on platforms which do not support blend natively.
00873   SDLoc DL(Op);
00874 
00875   SDValue Mask = Op.getOperand(0);
00876   SDValue Op1 = Op.getOperand(1);
00877   SDValue Op2 = Op.getOperand(2);
00878 
00879   EVT VT = Mask.getValueType();
00880 
00881   // If we can't even use the basic vector operations of
00882   // AND,OR,XOR, we will have to scalarize the op.
00883   // Notice that the operation may be 'promoted' which means that it is
00884   // 'bitcasted' to another type which is handled.
00885   // This operation also isn't safe with AND, OR, XOR when the boolean
00886   // type is 0/1 as we need an all ones vector constant to mask with.
00887   // FIXME: Sign extend 1 to all ones if thats legal on the target.
00888   if (TLI.getOperationAction(ISD::AND, VT) == TargetLowering::Expand ||
00889       TLI.getOperationAction(ISD::XOR, VT) == TargetLowering::Expand ||
00890       TLI.getOperationAction(ISD::OR, VT) == TargetLowering::Expand ||
00891       TLI.getBooleanContents(Op1.getValueType()) !=
00892           TargetLowering::ZeroOrNegativeOneBooleanContent)
00893     return DAG.UnrollVectorOp(Op.getNode());
00894 
00895   // If the mask and the type are different sizes, unroll the vector op. This
00896   // can occur when getSetCCResultType returns something that is different in
00897   // size from the operand types. For example, v4i8 = select v4i32, v4i8, v4i8.
00898   if (VT.getSizeInBits() != Op1.getValueType().getSizeInBits())
00899     return DAG.UnrollVectorOp(Op.getNode());
00900 
00901   // Bitcast the operands to be the same type as the mask.
00902   // This is needed when we select between FP types because
00903   // the mask is a vector of integers.
00904   Op1 = DAG.getNode(ISD::BITCAST, DL, VT, Op1);
00905   Op2 = DAG.getNode(ISD::BITCAST, DL, VT, Op2);
00906 
00907   SDValue AllOnes = DAG.getConstant(
00908     APInt::getAllOnesValue(VT.getScalarType().getSizeInBits()), VT);
00909   SDValue NotMask = DAG.getNode(ISD::XOR, DL, VT, Mask, AllOnes);
00910 
00911   Op1 = DAG.getNode(ISD::AND, DL, VT, Op1, Mask);
00912   Op2 = DAG.getNode(ISD::AND, DL, VT, Op2, NotMask);
00913   SDValue Val = DAG.getNode(ISD::OR, DL, VT, Op1, Op2);
00914   return DAG.getNode(ISD::BITCAST, DL, Op.getValueType(), Val);
00915 }
00916 
00917 SDValue VectorLegalizer::ExpandUINT_TO_FLOAT(SDValue Op) {
00918   EVT VT = Op.getOperand(0).getValueType();
00919   SDLoc DL(Op);
00920 
00921   // Make sure that the SINT_TO_FP and SRL instructions are available.
00922   if (TLI.getOperationAction(ISD::SINT_TO_FP, VT) == TargetLowering::Expand ||
00923       TLI.getOperationAction(ISD::SRL,        VT) == TargetLowering::Expand)
00924     return DAG.UnrollVectorOp(Op.getNode());
00925 
00926  EVT SVT = VT.getScalarType();
00927   assert((SVT.getSizeInBits() == 64 || SVT.getSizeInBits() == 32) &&
00928       "Elements in vector-UINT_TO_FP must be 32 or 64 bits wide");
00929 
00930   unsigned BW = SVT.getSizeInBits();
00931   SDValue HalfWord = DAG.getConstant(BW/2, VT);
00932 
00933   // Constants to clear the upper part of the word.
00934   // Notice that we can also use SHL+SHR, but using a constant is slightly
00935   // faster on x86.
00936   uint64_t HWMask = (SVT.getSizeInBits()==64)?0x00000000FFFFFFFF:0x0000FFFF;
00937   SDValue HalfWordMask = DAG.getConstant(HWMask, VT);
00938 
00939   // Two to the power of half-word-size.
00940   SDValue TWOHW = DAG.getConstantFP((1<<(BW/2)), Op.getValueType());
00941 
00942   // Clear upper part of LO, lower HI
00943   SDValue HI = DAG.getNode(ISD::SRL, DL, VT, Op.getOperand(0), HalfWord);
00944   SDValue LO = DAG.getNode(ISD::AND, DL, VT, Op.getOperand(0), HalfWordMask);
00945 
00946   // Convert hi and lo to floats
00947   // Convert the hi part back to the upper values
00948   SDValue fHI = DAG.getNode(ISD::SINT_TO_FP, DL, Op.getValueType(), HI);
00949           fHI = DAG.getNode(ISD::FMUL, DL, Op.getValueType(), fHI, TWOHW);
00950   SDValue fLO = DAG.getNode(ISD::SINT_TO_FP, DL, Op.getValueType(), LO);
00951 
00952   // Add the two halves
00953   return DAG.getNode(ISD::FADD, DL, Op.getValueType(), fHI, fLO);
00954 }
00955 
00956 
00957 SDValue VectorLegalizer::ExpandFNEG(SDValue Op) {
00958   if (TLI.isOperationLegalOrCustom(ISD::FSUB, Op.getValueType())) {
00959     SDValue Zero = DAG.getConstantFP(-0.0, Op.getValueType());
00960     return DAG.getNode(ISD::FSUB, SDLoc(Op), Op.getValueType(),
00961                        Zero, Op.getOperand(0));
00962   }
00963   return DAG.UnrollVectorOp(Op.getNode());
00964 }
00965 
00966 SDValue VectorLegalizer::UnrollVSETCC(SDValue Op) {
00967   EVT VT = Op.getValueType();
00968   unsigned NumElems = VT.getVectorNumElements();
00969   EVT EltVT = VT.getVectorElementType();
00970   SDValue LHS = Op.getOperand(0), RHS = Op.getOperand(1), CC = Op.getOperand(2);
00971   EVT TmpEltVT = LHS.getValueType().getVectorElementType();
00972   SDLoc dl(Op);
00973   SmallVector<SDValue, 8> Ops(NumElems);
00974   for (unsigned i = 0; i < NumElems; ++i) {
00975     SDValue LHSElem = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, TmpEltVT, LHS,
00976                                   DAG.getConstant(i, TLI.getVectorIdxTy()));
00977     SDValue RHSElem = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, TmpEltVT, RHS,
00978                                   DAG.getConstant(i, TLI.getVectorIdxTy()));
00979     Ops[i] = DAG.getNode(ISD::SETCC, dl,
00980                          TLI.getSetCCResultType(*DAG.getContext(), TmpEltVT),
00981                          LHSElem, RHSElem, CC);
00982     Ops[i] = DAG.getSelect(dl, EltVT, Ops[i],
00983                            DAG.getConstant(APInt::getAllOnesValue
00984                                            (EltVT.getSizeInBits()), EltVT),
00985                            DAG.getConstant(0, EltVT));
00986   }
00987   return DAG.getNode(ISD::BUILD_VECTOR, dl, VT, Ops);
00988 }
00989 
00990 }
00991 
00992 bool SelectionDAG::LegalizeVectors() {
00993   return VectorLegalizer(*this).Run();
00994 }