1 //===-- LegalizeVectorOps.cpp - Implement SelectionDAG::LegalizeVectors ---===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file implements the SelectionDAG::LegalizeVectors method. 11 // 12 // The vector legalizer looks for vector operations which might need to be 13 // scalarized and legalizes them. This is a separate step from Legalize because 14 // scalarizing can introduce illegal types. For example, suppose we have an 15 // ISD::SDIV of type v2i64 on x86-32. The type is legal (for example, addition 16 // on a v2i64 is legal), but ISD::SDIV isn't legal, so we have to unroll the 17 // operation, which introduces nodes with the illegal type i64 which must be 18 // expanded. Similarly, suppose we have an ISD::SRA of type v16i8 on PowerPC; 19 // the operation must be unrolled, which introduces nodes with the illegal 20 // type i8 which must be promoted. 21 // 22 // This does not legalize vector manipulations like ISD::BUILD_VECTOR, 23 // or operations that happen to take a vector which are custom-lowered; 24 // the legalization for such operations never produces nodes 25 // with illegal types, so it's okay to put off legalizing them until 26 // SelectionDAG::Legalize runs. 27 // 28 //===----------------------------------------------------------------------===// 29 30 #include "llvm/CodeGen/SelectionDAG.h" 31 #include "llvm/Target/TargetLowering.h" 32 using namespace llvm; 33 34 namespace { 35 class VectorLegalizer { 36 SelectionDAG& DAG; 37 const TargetLowering &TLI; 38 bool Changed; // Keep track of whether anything changed 39 40 /// LegalizedNodes - For nodes that are of legal width, and that have more 41 /// than one use, this map indicates what regularized operand to use. This 42 /// allows us to avoid legalizing the same thing more than once. 43 DenseMap<SDValue, SDValue> LegalizedNodes; 44 45 // Adds a node to the translation cache 46 void AddLegalizedOperand(SDValue From, SDValue To) { 47 LegalizedNodes.insert(std::make_pair(From, To)); 48 // If someone requests legalization of the new node, return itself. 49 if (From != To) 50 LegalizedNodes.insert(std::make_pair(To, To)); 51 } 52 53 // Legalizes the given node 54 SDValue LegalizeOp(SDValue Op); 55 // Assuming the node is legal, "legalize" the results 56 SDValue TranslateLegalizeResults(SDValue Op, SDValue Result); 57 // Implements unrolling a VSETCC. 58 SDValue UnrollVSETCC(SDValue Op); 59 // Implements expansion for FNEG; falls back to UnrollVectorOp if FSUB 60 // isn't legal. 61 // Implements expansion for UINT_TO_FLOAT; falls back to UnrollVectorOp if 62 // SINT_TO_FLOAT and SHR on vectors isn't legal. 63 SDValue ExpandUINT_TO_FLOAT(SDValue Op); 64 // Implement vselect in terms of XOR, AND, OR when blend is not supported 65 // by the target. 66 SDValue ExpandVSELECT(SDValue Op); 67 SDValue ExpandLoad(SDValue Op); 68 SDValue ExpandStore(SDValue Op); 69 SDValue ExpandFNEG(SDValue Op); 70 // Implements vector promotion; this is essentially just bitcasting the 71 // operands to a different type and bitcasting the result back to the 72 // original type. 73 SDValue PromoteVectorOp(SDValue Op); 74 // Implements [SU]INT_TO_FP vector promotion; this is a [zs]ext of the input 75 // operand to the next size up. 76 SDValue PromoteVectorOpINT_TO_FP(SDValue Op); 77 78 public: 79 bool Run(); 80 VectorLegalizer(SelectionDAG& dag) : 81 DAG(dag), TLI(dag.getTargetLoweringInfo()), Changed(false) {} 82 }; 83 84 bool VectorLegalizer::Run() { 85 // The legalize process is inherently a bottom-up recursive process (users 86 // legalize their uses before themselves). Given infinite stack space, we 87 // could just start legalizing on the root and traverse the whole graph. In 88 // practice however, this causes us to run out of stack space on large basic 89 // blocks. To avoid this problem, compute an ordering of the nodes where each 90 // node is only legalized after all of its operands are legalized. 91 DAG.AssignTopologicalOrder(); 92 for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(), 93 E = prior(DAG.allnodes_end()); I != llvm::next(E); ++I) 94 LegalizeOp(SDValue(I, 0)); 95 96 // Finally, it's possible the root changed. Get the new root. 97 SDValue OldRoot = DAG.getRoot(); 98 assert(LegalizedNodes.count(OldRoot) && "Root didn't get legalized?"); 99 DAG.setRoot(LegalizedNodes[OldRoot]); 100 101 LegalizedNodes.clear(); 102 103 // Remove dead nodes now. 104 DAG.RemoveDeadNodes(); 105 106 return Changed; 107 } 108 109 SDValue VectorLegalizer::TranslateLegalizeResults(SDValue Op, SDValue Result) { 110 // Generic legalization: just pass the operand through. 111 for (unsigned i = 0, e = Op.getNode()->getNumValues(); i != e; ++i) 112 AddLegalizedOperand(Op.getValue(i), Result.getValue(i)); 113 return Result.getValue(Op.getResNo()); 114 } 115 116 SDValue VectorLegalizer::LegalizeOp(SDValue Op) { 117 // Note that LegalizeOp may be reentered even from single-use nodes, which 118 // means that we always must cache transformed nodes. 119 DenseMap<SDValue, SDValue>::iterator I = LegalizedNodes.find(Op); 120 if (I != LegalizedNodes.end()) return I->second; 121 122 SDNode* Node = Op.getNode(); 123 124 // Legalize the operands 125 SmallVector<SDValue, 8> Ops; 126 for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) 127 Ops.push_back(LegalizeOp(Node->getOperand(i))); 128 129 SDValue Result = 130 SDValue(DAG.UpdateNodeOperands(Op.getNode(), Ops.data(), Ops.size()), 0); 131 132 if (Op.getOpcode() == ISD::LOAD) { 133 LoadSDNode *LD = cast<LoadSDNode>(Op.getNode()); 134 ISD::LoadExtType ExtType = LD->getExtensionType(); 135 if (LD->getMemoryVT().isVector() && ExtType != ISD::NON_EXTLOAD) { 136 if (TLI.isLoadExtLegal(LD->getExtensionType(), LD->getMemoryVT())) 137 return TranslateLegalizeResults(Op, Result); 138 Changed = true; 139 return LegalizeOp(ExpandLoad(Op)); 140 } 141 } else if (Op.getOpcode() == ISD::STORE) { 142 StoreSDNode *ST = cast<StoreSDNode>(Op.getNode()); 143 EVT StVT = ST->getMemoryVT(); 144 EVT ValVT = ST->getValue().getValueType(); 145 if (StVT.isVector() && ST->isTruncatingStore()) 146 switch (TLI.getTruncStoreAction(ValVT, StVT)) { 147 default: llvm_unreachable("This action is not supported yet!"); 148 case TargetLowering::Legal: 149 return TranslateLegalizeResults(Op, Result); 150 case TargetLowering::Custom: 151 Changed = true; 152 return LegalizeOp(TLI.LowerOperation(Result, DAG)); 153 case TargetLowering::Expand: 154 Changed = true; 155 return LegalizeOp(ExpandStore(Op)); 156 } 157 } 158 159 bool HasVectorValue = false; 160 for (SDNode::value_iterator J = Node->value_begin(), E = Node->value_end(); 161 J != E; 162 ++J) 163 HasVectorValue |= J->isVector(); 164 if (!HasVectorValue) 165 return TranslateLegalizeResults(Op, Result); 166 167 EVT QueryType; 168 switch (Op.getOpcode()) { 169 default: 170 return TranslateLegalizeResults(Op, Result); 171 case ISD::ADD: 172 case ISD::SUB: 173 case ISD::MUL: 174 case ISD::SDIV: 175 case ISD::UDIV: 176 case ISD::SREM: 177 case ISD::UREM: 178 case ISD::FADD: 179 case ISD::FSUB: 180 case ISD::FMUL: 181 case ISD::FDIV: 182 case ISD::FREM: 183 case ISD::AND: 184 case ISD::OR: 185 case ISD::XOR: 186 case ISD::SHL: 187 case ISD::SRA: 188 case ISD::SRL: 189 case ISD::ROTL: 190 case ISD::ROTR: 191 case ISD::CTLZ: 192 case ISD::CTTZ: 193 case ISD::CTLZ_ZERO_UNDEF: 194 case ISD::CTTZ_ZERO_UNDEF: 195 case ISD::CTPOP: 196 case ISD::SELECT: 197 case ISD::VSELECT: 198 case ISD::SELECT_CC: 199 case ISD::SETCC: 200 case ISD::ZERO_EXTEND: 201 case ISD::ANY_EXTEND: 202 case ISD::TRUNCATE: 203 case ISD::SIGN_EXTEND: 204 case ISD::FP_TO_SINT: 205 case ISD::FP_TO_UINT: 206 case ISD::FNEG: 207 case ISD::FABS: 208 case ISD::FSQRT: 209 case ISD::FSIN: 210 case ISD::FCOS: 211 case ISD::FPOWI: 212 case ISD::FPOW: 213 case ISD::FLOG: 214 case ISD::FLOG2: 215 case ISD::FLOG10: 216 case ISD::FEXP: 217 case ISD::FEXP2: 218 case ISD::FCEIL: 219 case ISD::FTRUNC: 220 case ISD::FRINT: 221 case ISD::FNEARBYINT: 222 case ISD::FFLOOR: 223 case ISD::SIGN_EXTEND_INREG: 224 QueryType = Node->getValueType(0); 225 break; 226 case ISD::FP_ROUND_INREG: 227 QueryType = cast<VTSDNode>(Node->getOperand(1))->getVT(); 228 break; 229 case ISD::SINT_TO_FP: 230 case ISD::UINT_TO_FP: 231 QueryType = Node->getOperand(0).getValueType(); 232 break; 233 } 234 235 switch (TLI.getOperationAction(Node->getOpcode(), QueryType)) { 236 case TargetLowering::Promote: 237 switch (Op.getOpcode()) { 238 default: 239 // "Promote" the operation by bitcasting 240 Result = PromoteVectorOp(Op); 241 Changed = true; 242 break; 243 case ISD::SINT_TO_FP: 244 case ISD::UINT_TO_FP: 245 // "Promote" the operation by extending the operand. 246 Result = PromoteVectorOpINT_TO_FP(Op); 247 Changed = true; 248 break; 249 } 250 break; 251 case TargetLowering::Legal: break; 252 case TargetLowering::Custom: { 253 SDValue Tmp1 = TLI.LowerOperation(Op, DAG); 254 if (Tmp1.getNode()) { 255 Result = Tmp1; 256 break; 257 } 258 // FALL THROUGH 259 } 260 case TargetLowering::Expand: 261 if (Node->getOpcode() == ISD::VSELECT) 262 Result = ExpandVSELECT(Op); 263 else if (Node->getOpcode() == ISD::UINT_TO_FP) 264 Result = ExpandUINT_TO_FLOAT(Op); 265 else if (Node->getOpcode() == ISD::FNEG) 266 Result = ExpandFNEG(Op); 267 else if (Node->getOpcode() == ISD::SETCC) 268 Result = UnrollVSETCC(Op); 269 else 270 Result = DAG.UnrollVectorOp(Op.getNode()); 271 break; 272 } 273 274 // Make sure that the generated code is itself legal. 275 if (Result != Op) { 276 Result = LegalizeOp(Result); 277 Changed = true; 278 } 279 280 // Note that LegalizeOp may be reentered even from single-use nodes, which 281 // means that we always must cache transformed nodes. 282 AddLegalizedOperand(Op, Result); 283 return Result; 284 } 285 286 SDValue VectorLegalizer::PromoteVectorOp(SDValue Op) { 287 // Vector "promotion" is basically just bitcasting and doing the operation 288 // in a different type. For example, x86 promotes ISD::AND on v2i32 to 289 // v1i64. 290 EVT VT = Op.getValueType(); 291 assert(Op.getNode()->getNumValues() == 1 && 292 "Can't promote a vector with multiple results!"); 293 EVT NVT = TLI.getTypeToPromoteTo(Op.getOpcode(), VT); 294 DebugLoc dl = Op.getDebugLoc(); 295 SmallVector<SDValue, 4> Operands(Op.getNumOperands()); 296 297 for (unsigned j = 0; j != Op.getNumOperands(); ++j) { 298 if (Op.getOperand(j).getValueType().isVector()) 299 Operands[j] = DAG.getNode(ISD::BITCAST, dl, NVT, Op.getOperand(j)); 300 else 301 Operands[j] = Op.getOperand(j); 302 } 303 304 Op = DAG.getNode(Op.getOpcode(), dl, NVT, &Operands[0], Operands.size()); 305 306 return DAG.getNode(ISD::BITCAST, dl, VT, Op); 307 } 308 309 SDValue VectorLegalizer::PromoteVectorOpINT_TO_FP(SDValue Op) { 310 // INT_TO_FP operations may require the input operand be promoted even 311 // when the type is otherwise legal. 312 EVT VT = Op.getOperand(0).getValueType(); 313 assert(Op.getNode()->getNumValues() == 1 && 314 "Can't promote a vector with multiple results!"); 315 316 // Normal getTypeToPromoteTo() doesn't work here, as that will promote 317 // by widening the vector w/ the same element width and twice the number 318 // of elements. We want the other way around, the same number of elements, 319 // each twice the width. 320 // 321 // Increase the bitwidth of the element to the next pow-of-two 322 // (which is greater than 8 bits). 323 unsigned NumElts = VT.getVectorNumElements(); 324 EVT EltVT = VT.getVectorElementType(); 325 EltVT = EVT::getIntegerVT(*DAG.getContext(), 2 * EltVT.getSizeInBits()); 326 assert(EltVT.isSimple() && "Promoting to a non-simple vector type!"); 327 328 // Build a new vector type and check if it is legal. 329 MVT NVT = MVT::getVectorVT(EltVT.getSimpleVT(), NumElts); 330 331 DebugLoc dl = Op.getDebugLoc(); 332 SmallVector<SDValue, 4> Operands(Op.getNumOperands()); 333 334 unsigned Opc = Op.getOpcode() == ISD::UINT_TO_FP ? ISD::ZERO_EXTEND : 335 ISD::SIGN_EXTEND; 336 for (unsigned j = 0; j != Op.getNumOperands(); ++j) { 337 if (Op.getOperand(j).getValueType().isVector()) 338 Operands[j] = DAG.getNode(Opc, dl, NVT, Op.getOperand(j)); 339 else 340 Operands[j] = Op.getOperand(j); 341 } 342 343 return DAG.getNode(Op.getOpcode(), dl, Op.getValueType(), &Operands[0], 344 Operands.size()); 345 } 346 347 348 SDValue VectorLegalizer::ExpandLoad(SDValue Op) { 349 DebugLoc dl = Op.getDebugLoc(); 350 LoadSDNode *LD = cast<LoadSDNode>(Op.getNode()); 351 SDValue Chain = LD->getChain(); 352 SDValue BasePTR = LD->getBasePtr(); 353 EVT SrcVT = LD->getMemoryVT(); 354 ISD::LoadExtType ExtType = LD->getExtensionType(); 355 356 SmallVector<SDValue, 8> LoadVals; 357 SmallVector<SDValue, 8> LoadChains; 358 unsigned NumElem = SrcVT.getVectorNumElements(); 359 unsigned Stride = SrcVT.getScalarType().getSizeInBits()/8; 360 361 for (unsigned Idx=0; Idx<NumElem; Idx++) { 362 SDValue ScalarLoad = DAG.getExtLoad(ExtType, dl, 363 Op.getNode()->getValueType(0).getScalarType(), 364 Chain, BasePTR, LD->getPointerInfo().getWithOffset(Idx * Stride), 365 SrcVT.getScalarType(), 366 LD->isVolatile(), LD->isNonTemporal(), 367 LD->getAlignment()); 368 369 BasePTR = DAG.getNode(ISD::ADD, dl, BasePTR.getValueType(), BasePTR, 370 DAG.getIntPtrConstant(Stride)); 371 372 LoadVals.push_back(ScalarLoad.getValue(0)); 373 LoadChains.push_back(ScalarLoad.getValue(1)); 374 } 375 376 SDValue NewChain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, 377 &LoadChains[0], LoadChains.size()); 378 SDValue Value = DAG.getNode(ISD::BUILD_VECTOR, dl, 379 Op.getNode()->getValueType(0), &LoadVals[0], LoadVals.size()); 380 381 AddLegalizedOperand(Op.getValue(0), Value); 382 AddLegalizedOperand(Op.getValue(1), NewChain); 383 384 return (Op.getResNo() ? NewChain : Value); 385 } 386 387 SDValue VectorLegalizer::ExpandStore(SDValue Op) { 388 DebugLoc dl = Op.getDebugLoc(); 389 StoreSDNode *ST = cast<StoreSDNode>(Op.getNode()); 390 SDValue Chain = ST->getChain(); 391 SDValue BasePTR = ST->getBasePtr(); 392 SDValue Value = ST->getValue(); 393 EVT StVT = ST->getMemoryVT(); 394 395 unsigned Alignment = ST->getAlignment(); 396 bool isVolatile = ST->isVolatile(); 397 bool isNonTemporal = ST->isNonTemporal(); 398 399 unsigned NumElem = StVT.getVectorNumElements(); 400 // The type of the data we want to save 401 EVT RegVT = Value.getValueType(); 402 EVT RegSclVT = RegVT.getScalarType(); 403 // The type of data as saved in memory. 404 EVT MemSclVT = StVT.getScalarType(); 405 406 // Cast floats into integers 407 unsigned ScalarSize = MemSclVT.getSizeInBits(); 408 409 // Round odd types to the next pow of two. 410 if (!isPowerOf2_32(ScalarSize)) 411 ScalarSize = NextPowerOf2(ScalarSize); 412 413 // Store Stride in bytes 414 unsigned Stride = ScalarSize/8; 415 // Extract each of the elements from the original vector 416 // and save them into memory individually. 417 SmallVector<SDValue, 8> Stores; 418 for (unsigned Idx = 0; Idx < NumElem; Idx++) { 419 SDValue Ex = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, 420 RegSclVT, Value, DAG.getIntPtrConstant(Idx)); 421 422 // This scalar TruncStore may be illegal, but we legalize it later. 423 SDValue Store = DAG.getTruncStore(Chain, dl, Ex, BasePTR, 424 ST->getPointerInfo().getWithOffset(Idx*Stride), MemSclVT, 425 isVolatile, isNonTemporal, Alignment); 426 427 BasePTR = DAG.getNode(ISD::ADD, dl, BasePTR.getValueType(), BasePTR, 428 DAG.getIntPtrConstant(Stride)); 429 430 Stores.push_back(Store); 431 } 432 SDValue TF = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, 433 &Stores[0], Stores.size()); 434 AddLegalizedOperand(Op, TF); 435 return TF; 436 } 437 438 SDValue VectorLegalizer::ExpandVSELECT(SDValue Op) { 439 // Implement VSELECT in terms of XOR, AND, OR 440 // on platforms which do not support blend natively. 441 EVT VT = Op.getOperand(0).getValueType(); 442 DebugLoc DL = Op.getDebugLoc(); 443 444 SDValue Mask = Op.getOperand(0); 445 SDValue Op1 = Op.getOperand(1); 446 SDValue Op2 = Op.getOperand(2); 447 448 // If we can't even use the basic vector operations of 449 // AND,OR,XOR, we will have to scalarize the op. 450 // Notice that the operation may be 'promoted' which means that it is 451 // 'bitcasted' to another type which is handled. 452 if (TLI.getOperationAction(ISD::AND, VT) == TargetLowering::Expand || 453 TLI.getOperationAction(ISD::XOR, VT) == TargetLowering::Expand || 454 TLI.getOperationAction(ISD::OR, VT) == TargetLowering::Expand) 455 return DAG.UnrollVectorOp(Op.getNode()); 456 457 assert(VT.getSizeInBits() == Op.getOperand(1).getValueType().getSizeInBits() 458 && "Invalid mask size"); 459 // Bitcast the operands to be the same type as the mask. 460 // This is needed when we select between FP types because 461 // the mask is a vector of integers. 462 Op1 = DAG.getNode(ISD::BITCAST, DL, VT, Op1); 463 Op2 = DAG.getNode(ISD::BITCAST, DL, VT, Op2); 464 465 SDValue AllOnes = DAG.getConstant( 466 APInt::getAllOnesValue(VT.getScalarType().getSizeInBits()), VT); 467 SDValue NotMask = DAG.getNode(ISD::XOR, DL, VT, Mask, AllOnes); 468 469 Op1 = DAG.getNode(ISD::AND, DL, VT, Op1, Mask); 470 Op2 = DAG.getNode(ISD::AND, DL, VT, Op2, NotMask); 471 SDValue Val = DAG.getNode(ISD::OR, DL, VT, Op1, Op2); 472 return DAG.getNode(ISD::BITCAST, DL, Op.getValueType(), Val); 473 } 474 475 SDValue VectorLegalizer::ExpandUINT_TO_FLOAT(SDValue Op) { 476 EVT VT = Op.getOperand(0).getValueType(); 477 DebugLoc DL = Op.getDebugLoc(); 478 479 // Make sure that the SINT_TO_FP and SRL instructions are available. 480 if (TLI.getOperationAction(ISD::SINT_TO_FP, VT) == TargetLowering::Expand || 481 TLI.getOperationAction(ISD::SRL, VT) == TargetLowering::Expand) 482 return DAG.UnrollVectorOp(Op.getNode()); 483 484 EVT SVT = VT.getScalarType(); 485 assert((SVT.getSizeInBits() == 64 || SVT.getSizeInBits() == 32) && 486 "Elements in vector-UINT_TO_FP must be 32 or 64 bits wide"); 487 488 unsigned BW = SVT.getSizeInBits(); 489 SDValue HalfWord = DAG.getConstant(BW/2, VT); 490 491 // Constants to clear the upper part of the word. 492 // Notice that we can also use SHL+SHR, but using a constant is slightly 493 // faster on x86. 494 uint64_t HWMask = (SVT.getSizeInBits()==64)?0x00000000FFFFFFFF:0x0000FFFF; 495 SDValue HalfWordMask = DAG.getConstant(HWMask, VT); 496 497 // Two to the power of half-word-size. 498 SDValue TWOHW = DAG.getConstantFP((1<<(BW/2)), Op.getValueType()); 499 500 // Clear upper part of LO, lower HI 501 SDValue HI = DAG.getNode(ISD::SRL, DL, VT, Op.getOperand(0), HalfWord); 502 SDValue LO = DAG.getNode(ISD::AND, DL, VT, Op.getOperand(0), HalfWordMask); 503 504 // Convert hi and lo to floats 505 // Convert the hi part back to the upper values 506 SDValue fHI = DAG.getNode(ISD::SINT_TO_FP, DL, Op.getValueType(), HI); 507 fHI = DAG.getNode(ISD::FMUL, DL, Op.getValueType(), fHI, TWOHW); 508 SDValue fLO = DAG.getNode(ISD::SINT_TO_FP, DL, Op.getValueType(), LO); 509 510 // Add the two halves 511 return DAG.getNode(ISD::FADD, DL, Op.getValueType(), fHI, fLO); 512 } 513 514 515 SDValue VectorLegalizer::ExpandFNEG(SDValue Op) { 516 if (TLI.isOperationLegalOrCustom(ISD::FSUB, Op.getValueType())) { 517 SDValue Zero = DAG.getConstantFP(-0.0, Op.getValueType()); 518 return DAG.getNode(ISD::FSUB, Op.getDebugLoc(), Op.getValueType(), 519 Zero, Op.getOperand(0)); 520 } 521 return DAG.UnrollVectorOp(Op.getNode()); 522 } 523 524 SDValue VectorLegalizer::UnrollVSETCC(SDValue Op) { 525 EVT VT = Op.getValueType(); 526 unsigned NumElems = VT.getVectorNumElements(); 527 EVT EltVT = VT.getVectorElementType(); 528 SDValue LHS = Op.getOperand(0), RHS = Op.getOperand(1), CC = Op.getOperand(2); 529 EVT TmpEltVT = LHS.getValueType().getVectorElementType(); 530 DebugLoc dl = Op.getDebugLoc(); 531 SmallVector<SDValue, 8> Ops(NumElems); 532 for (unsigned i = 0; i < NumElems; ++i) { 533 SDValue LHSElem = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, TmpEltVT, LHS, 534 DAG.getIntPtrConstant(i)); 535 SDValue RHSElem = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, TmpEltVT, RHS, 536 DAG.getIntPtrConstant(i)); 537 Ops[i] = DAG.getNode(ISD::SETCC, dl, TLI.getSetCCResultType(TmpEltVT), 538 LHSElem, RHSElem, CC); 539 Ops[i] = DAG.getNode(ISD::SELECT, dl, EltVT, Ops[i], 540 DAG.getConstant(APInt::getAllOnesValue 541 (EltVT.getSizeInBits()), EltVT), 542 DAG.getConstant(0, EltVT)); 543 } 544 return DAG.getNode(ISD::BUILD_VECTOR, dl, VT, &Ops[0], NumElems); 545 } 546 547 } 548 549 bool SelectionDAG::LegalizeVectors() { 550 return VectorLegalizer(*this).Run(); 551 } 552