1 //===- LegalizeVectorOps.cpp - Implement SelectionDAG::LegalizeVectors ----===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file implements the SelectionDAG::LegalizeVectors method. 10 // 11 // The vector legalizer looks for vector operations which might need to be 12 // scalarized and legalizes them. This is a separate step from Legalize because 13 // scalarizing can introduce illegal types. For example, suppose we have an 14 // ISD::SDIV of type v2i64 on x86-32. The type is legal (for example, addition 15 // on a v2i64 is legal), but ISD::SDIV isn't legal, so we have to unroll the 16 // operation, which introduces nodes with the illegal type i64 which must be 17 // expanded. Similarly, suppose we have an ISD::SRA of type v16i8 on PowerPC; 18 // the operation must be unrolled, which introduces nodes with the illegal 19 // type i8 which must be promoted. 20 // 21 // This does not legalize vector manipulations like ISD::BUILD_VECTOR, 22 // or operations that happen to take a vector which are custom-lowered; 23 // the legalization for such operations never produces nodes 24 // with illegal types, so it's okay to put off legalizing them until 25 // SelectionDAG::Legalize runs. 26 // 27 //===----------------------------------------------------------------------===// 28 29 #include "llvm/ADT/APInt.h" 30 #include "llvm/ADT/DenseMap.h" 31 #include "llvm/ADT/SmallVector.h" 32 #include "llvm/CodeGen/ISDOpcodes.h" 33 #include "llvm/CodeGen/MachineMemOperand.h" 34 #include "llvm/CodeGen/SelectionDAG.h" 35 #include "llvm/CodeGen/SelectionDAGNodes.h" 36 #include "llvm/CodeGen/TargetLowering.h" 37 #include "llvm/CodeGen/ValueTypes.h" 38 #include "llvm/IR/DataLayout.h" 39 #include "llvm/Support/Casting.h" 40 #include "llvm/Support/Compiler.h" 41 #include "llvm/Support/Debug.h" 42 #include "llvm/Support/ErrorHandling.h" 43 #include "llvm/Support/MachineValueType.h" 44 #include "llvm/Support/MathExtras.h" 45 #include <cassert> 46 #include <cstdint> 47 #include <iterator> 48 #include <utility> 49 50 using namespace llvm; 51 52 #define DEBUG_TYPE "legalizevectorops" 53 54 namespace { 55 56 class VectorLegalizer { 57 SelectionDAG& DAG; 58 const TargetLowering &TLI; 59 bool Changed = false; // Keep track of whether anything changed 60 61 /// For nodes that are of legal width, and that have more than one use, this 62 /// map indicates what regularized operand to use. This allows us to avoid 63 /// legalizing the same thing more than once. 64 SmallDenseMap<SDValue, SDValue, 64> LegalizedNodes; 65 66 /// Adds a node to the translation cache. 67 void AddLegalizedOperand(SDValue From, SDValue To) { 68 LegalizedNodes.insert(std::make_pair(From, To)); 69 // If someone requests legalization of the new node, return itself. 70 if (From != To) 71 LegalizedNodes.insert(std::make_pair(To, To)); 72 } 73 74 /// Legalizes the given node. 75 SDValue LegalizeOp(SDValue Op); 76 77 /// Assuming the node is legal, "legalize" the results. 78 SDValue TranslateLegalizeResults(SDValue Op, SDNode *Result); 79 80 /// Make sure Results are legal and update the translation cache. 81 SDValue RecursivelyLegalizeResults(SDValue Op, 82 MutableArrayRef<SDValue> Results); 83 84 /// Wrapper to interface LowerOperation with a vector of Results. 85 /// Returns false if the target wants to use default expansion. Otherwise 86 /// returns true. If return is true and the Results are empty, then the 87 /// target wants to keep the input node as is. 88 bool LowerOperationWrapper(SDNode *N, SmallVectorImpl<SDValue> &Results); 89 90 /// Implements unrolling a VSETCC. 91 SDValue UnrollVSETCC(SDNode *Node); 92 93 /// Implement expand-based legalization of vector operations. 94 /// 95 /// This is just a high-level routine to dispatch to specific code paths for 96 /// operations to legalize them. 97 void Expand(SDNode *Node, SmallVectorImpl<SDValue> &Results); 98 99 /// Implements expansion for FP_TO_UINT; falls back to UnrollVectorOp if 100 /// FP_TO_SINT isn't legal. 101 void ExpandFP_TO_UINT(SDNode *Node, SmallVectorImpl<SDValue> &Results); 102 103 /// Implements expansion for UINT_TO_FLOAT; falls back to UnrollVectorOp if 104 /// SINT_TO_FLOAT and SHR on vectors isn't legal. 105 void ExpandUINT_TO_FLOAT(SDNode *Node, SmallVectorImpl<SDValue> &Results); 106 107 /// Implement expansion for SIGN_EXTEND_INREG using SRL and SRA. 108 SDValue ExpandSEXTINREG(SDNode *Node); 109 110 /// Implement expansion for ANY_EXTEND_VECTOR_INREG. 111 /// 112 /// Shuffles the low lanes of the operand into place and bitcasts to the proper 113 /// type. The contents of the bits in the extended part of each element are 114 /// undef. 115 SDValue ExpandANY_EXTEND_VECTOR_INREG(SDNode *Node); 116 117 /// Implement expansion for SIGN_EXTEND_VECTOR_INREG. 118 /// 119 /// Shuffles the low lanes of the operand into place, bitcasts to the proper 120 /// type, then shifts left and arithmetic shifts right to introduce a sign 121 /// extension. 122 SDValue ExpandSIGN_EXTEND_VECTOR_INREG(SDNode *Node); 123 124 /// Implement expansion for ZERO_EXTEND_VECTOR_INREG. 125 /// 126 /// Shuffles the low lanes of the operand into place and blends zeros into 127 /// the remaining lanes, finally bitcasting to the proper type. 128 SDValue ExpandZERO_EXTEND_VECTOR_INREG(SDNode *Node); 129 130 /// Expand bswap of vectors into a shuffle if legal. 131 SDValue ExpandBSWAP(SDNode *Node); 132 133 /// Implement vselect in terms of XOR, AND, OR when blend is not 134 /// supported by the target. 135 SDValue ExpandVSELECT(SDNode *Node); 136 SDValue ExpandSELECT(SDNode *Node); 137 std::pair<SDValue, SDValue> ExpandLoad(SDNode *N); 138 SDValue ExpandStore(SDNode *N); 139 SDValue ExpandFNEG(SDNode *Node); 140 void ExpandFSUB(SDNode *Node, SmallVectorImpl<SDValue> &Results); 141 void ExpandBITREVERSE(SDNode *Node, SmallVectorImpl<SDValue> &Results); 142 void ExpandUADDSUBO(SDNode *Node, SmallVectorImpl<SDValue> &Results); 143 void ExpandSADDSUBO(SDNode *Node, SmallVectorImpl<SDValue> &Results); 144 void ExpandMULO(SDNode *Node, SmallVectorImpl<SDValue> &Results); 145 void ExpandFixedPointDiv(SDNode *Node, SmallVectorImpl<SDValue> &Results); 146 SDValue ExpandStrictFPOp(SDNode *Node); 147 void ExpandStrictFPOp(SDNode *Node, SmallVectorImpl<SDValue> &Results); 148 149 void UnrollStrictFPOp(SDNode *Node, SmallVectorImpl<SDValue> &Results); 150 151 /// Implements vector promotion. 152 /// 153 /// This is essentially just bitcasting the operands to a different type and 154 /// bitcasting the result back to the original type. 155 void Promote(SDNode *Node, SmallVectorImpl<SDValue> &Results); 156 157 /// Implements [SU]INT_TO_FP vector promotion. 158 /// 159 /// This is a [zs]ext of the input operand to a larger integer type. 160 void PromoteINT_TO_FP(SDNode *Node, SmallVectorImpl<SDValue> &Results); 161 162 /// Implements FP_TO_[SU]INT vector promotion of the result type. 163 /// 164 /// It is promoted to a larger integer type. The result is then 165 /// truncated back to the original type. 166 void PromoteFP_TO_INT(SDNode *Node, SmallVectorImpl<SDValue> &Results); 167 168 public: 169 VectorLegalizer(SelectionDAG& dag) : 170 DAG(dag), TLI(dag.getTargetLoweringInfo()) {} 171 172 /// Begin legalizer the vector operations in the DAG. 173 bool Run(); 174 }; 175 176 } // end anonymous namespace 177 178 bool VectorLegalizer::Run() { 179 // Before we start legalizing vector nodes, check if there are any vectors. 180 bool HasVectors = false; 181 for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(), 182 E = std::prev(DAG.allnodes_end()); I != std::next(E); ++I) { 183 // Check if the values of the nodes contain vectors. We don't need to check 184 // the operands because we are going to check their values at some point. 185 HasVectors = llvm::any_of(I->values(), [](EVT T) { return T.isVector(); }); 186 187 // If we found a vector node we can start the legalization. 188 if (HasVectors) 189 break; 190 } 191 192 // If this basic block has no vectors then no need to legalize vectors. 193 if (!HasVectors) 194 return false; 195 196 // The legalize process is inherently a bottom-up recursive process (users 197 // legalize their uses before themselves). Given infinite stack space, we 198 // could just start legalizing on the root and traverse the whole graph. In 199 // practice however, this causes us to run out of stack space on large basic 200 // blocks. To avoid this problem, compute an ordering of the nodes where each 201 // node is only legalized after all of its operands are legalized. 202 DAG.AssignTopologicalOrder(); 203 for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(), 204 E = std::prev(DAG.allnodes_end()); I != std::next(E); ++I) 205 LegalizeOp(SDValue(&*I, 0)); 206 207 // Finally, it's possible the root changed. Get the new root. 208 SDValue OldRoot = DAG.getRoot(); 209 assert(LegalizedNodes.count(OldRoot) && "Root didn't get legalized?"); 210 DAG.setRoot(LegalizedNodes[OldRoot]); 211 212 LegalizedNodes.clear(); 213 214 // Remove dead nodes now. 215 DAG.RemoveDeadNodes(); 216 217 return Changed; 218 } 219 220 SDValue VectorLegalizer::TranslateLegalizeResults(SDValue Op, SDNode *Result) { 221 assert(Op->getNumValues() == Result->getNumValues() && 222 "Unexpected number of results"); 223 // Generic legalization: just pass the operand through. 224 for (unsigned i = 0, e = Op->getNumValues(); i != e; ++i) 225 AddLegalizedOperand(Op.getValue(i), SDValue(Result, i)); 226 return SDValue(Result, Op.getResNo()); 227 } 228 229 SDValue 230 VectorLegalizer::RecursivelyLegalizeResults(SDValue Op, 231 MutableArrayRef<SDValue> Results) { 232 assert(Results.size() == Op->getNumValues() && 233 "Unexpected number of results"); 234 // Make sure that the generated code is itself legal. 235 for (unsigned i = 0, e = Results.size(); i != e; ++i) { 236 Results[i] = LegalizeOp(Results[i]); 237 AddLegalizedOperand(Op.getValue(i), Results[i]); 238 } 239 240 return Results[Op.getResNo()]; 241 } 242 243 SDValue VectorLegalizer::LegalizeOp(SDValue Op) { 244 // Note that LegalizeOp may be reentered even from single-use nodes, which 245 // means that we always must cache transformed nodes. 246 DenseMap<SDValue, SDValue>::iterator I = LegalizedNodes.find(Op); 247 if (I != LegalizedNodes.end()) return I->second; 248 249 // Legalize the operands 250 SmallVector<SDValue, 8> Ops; 251 for (const SDValue &Oper : Op->op_values()) 252 Ops.push_back(LegalizeOp(Oper)); 253 254 SDNode *Node = DAG.UpdateNodeOperands(Op.getNode(), Ops); 255 256 if (Op.getOpcode() == ISD::LOAD) { 257 LoadSDNode *LD = cast<LoadSDNode>(Node); 258 ISD::LoadExtType ExtType = LD->getExtensionType(); 259 if (LD->getMemoryVT().isVector() && ExtType != ISD::NON_EXTLOAD) { 260 LLVM_DEBUG(dbgs() << "\nLegalizing extending vector load: "; 261 Node->dump(&DAG)); 262 switch (TLI.getLoadExtAction(LD->getExtensionType(), LD->getValueType(0), 263 LD->getMemoryVT())) { 264 default: llvm_unreachable("This action is not supported yet!"); 265 case TargetLowering::Legal: 266 return TranslateLegalizeResults(Op, Node); 267 case TargetLowering::Custom: { 268 SmallVector<SDValue, 2> ResultVals; 269 if (LowerOperationWrapper(Node, ResultVals)) { 270 if (ResultVals.empty()) 271 return TranslateLegalizeResults(Op, Node); 272 273 Changed = true; 274 return RecursivelyLegalizeResults(Op, ResultVals); 275 } 276 LLVM_FALLTHROUGH; 277 } 278 case TargetLowering::Expand: { 279 Changed = true; 280 std::pair<SDValue, SDValue> Tmp = ExpandLoad(Node); 281 AddLegalizedOperand(Op.getValue(0), Tmp.first); 282 AddLegalizedOperand(Op.getValue(1), Tmp.second); 283 return Op.getResNo() ? Tmp.first : Tmp.second; 284 } 285 } 286 } 287 } else if (Op.getOpcode() == ISD::STORE) { 288 StoreSDNode *ST = cast<StoreSDNode>(Node); 289 EVT StVT = ST->getMemoryVT(); 290 MVT ValVT = ST->getValue().getSimpleValueType(); 291 if (StVT.isVector() && ST->isTruncatingStore()) { 292 LLVM_DEBUG(dbgs() << "\nLegalizing truncating vector store: "; 293 Node->dump(&DAG)); 294 switch (TLI.getTruncStoreAction(ValVT, StVT)) { 295 default: llvm_unreachable("This action is not supported yet!"); 296 case TargetLowering::Legal: 297 return TranslateLegalizeResults(Op, Node); 298 case TargetLowering::Custom: { 299 SmallVector<SDValue, 1> ResultVals; 300 if (LowerOperationWrapper(Node, ResultVals)) { 301 if (ResultVals.empty()) 302 return TranslateLegalizeResults(Op, Node); 303 304 Changed = true; 305 return RecursivelyLegalizeResults(Op, ResultVals); 306 } 307 LLVM_FALLTHROUGH; 308 } 309 case TargetLowering::Expand: { 310 Changed = true; 311 SDValue Chain = ExpandStore(Node); 312 AddLegalizedOperand(Op, Chain); 313 return Chain; 314 } 315 } 316 } 317 } 318 319 bool HasVectorValueOrOp = 320 llvm::any_of(Node->values(), [](EVT T) { return T.isVector(); }) || 321 llvm::any_of(Node->op_values(), 322 [](SDValue O) { return O.getValueType().isVector(); }); 323 if (!HasVectorValueOrOp) 324 return TranslateLegalizeResults(Op, Node); 325 326 TargetLowering::LegalizeAction Action = TargetLowering::Legal; 327 EVT ValVT; 328 switch (Op.getOpcode()) { 329 default: 330 return TranslateLegalizeResults(Op, Node); 331 case ISD::MERGE_VALUES: 332 Action = TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)); 333 // This operation lies about being legal: when it claims to be legal, 334 // it should actually be expanded. 335 if (Action == TargetLowering::Legal) 336 Action = TargetLowering::Expand; 337 break; 338 #define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \ 339 case ISD::STRICT_##DAGN: 340 #include "llvm/IR/ConstrainedOps.def" 341 ValVT = Node->getValueType(0); 342 if (Op.getOpcode() == ISD::STRICT_SINT_TO_FP || 343 Op.getOpcode() == ISD::STRICT_UINT_TO_FP) 344 ValVT = Node->getOperand(1).getValueType(); 345 Action = TLI.getOperationAction(Node->getOpcode(), ValVT); 346 // If we're asked to expand a strict vector floating-point operation, 347 // by default we're going to simply unroll it. That is usually the 348 // best approach, except in the case where the resulting strict (scalar) 349 // operations would themselves use the fallback mutation to non-strict. 350 // In that specific case, just do the fallback on the vector op. 351 if (Action == TargetLowering::Expand && !TLI.isStrictFPEnabled() && 352 TLI.getStrictFPOperationAction(Node->getOpcode(), ValVT) == 353 TargetLowering::Legal) { 354 EVT EltVT = ValVT.getVectorElementType(); 355 if (TLI.getOperationAction(Node->getOpcode(), EltVT) 356 == TargetLowering::Expand && 357 TLI.getStrictFPOperationAction(Node->getOpcode(), EltVT) 358 == TargetLowering::Legal) 359 Action = TargetLowering::Legal; 360 } 361 break; 362 case ISD::ADD: 363 case ISD::SUB: 364 case ISD::MUL: 365 case ISD::MULHS: 366 case ISD::MULHU: 367 case ISD::SDIV: 368 case ISD::UDIV: 369 case ISD::SREM: 370 case ISD::UREM: 371 case ISD::SDIVREM: 372 case ISD::UDIVREM: 373 case ISD::FADD: 374 case ISD::FSUB: 375 case ISD::FMUL: 376 case ISD::FDIV: 377 case ISD::FREM: 378 case ISD::AND: 379 case ISD::OR: 380 case ISD::XOR: 381 case ISD::SHL: 382 case ISD::SRA: 383 case ISD::SRL: 384 case ISD::FSHL: 385 case ISD::FSHR: 386 case ISD::ROTL: 387 case ISD::ROTR: 388 case ISD::ABS: 389 case ISD::BSWAP: 390 case ISD::BITREVERSE: 391 case ISD::CTLZ: 392 case ISD::CTTZ: 393 case ISD::CTLZ_ZERO_UNDEF: 394 case ISD::CTTZ_ZERO_UNDEF: 395 case ISD::CTPOP: 396 case ISD::SELECT: 397 case ISD::VSELECT: 398 case ISD::SELECT_CC: 399 case ISD::SETCC: 400 case ISD::ZERO_EXTEND: 401 case ISD::ANY_EXTEND: 402 case ISD::TRUNCATE: 403 case ISD::SIGN_EXTEND: 404 case ISD::FP_TO_SINT: 405 case ISD::FP_TO_UINT: 406 case ISD::FNEG: 407 case ISD::FABS: 408 case ISD::FMINNUM: 409 case ISD::FMAXNUM: 410 case ISD::FMINNUM_IEEE: 411 case ISD::FMAXNUM_IEEE: 412 case ISD::FMINIMUM: 413 case ISD::FMAXIMUM: 414 case ISD::FCOPYSIGN: 415 case ISD::FSQRT: 416 case ISD::FSIN: 417 case ISD::FCOS: 418 case ISD::FPOWI: 419 case ISD::FPOW: 420 case ISD::FLOG: 421 case ISD::FLOG2: 422 case ISD::FLOG10: 423 case ISD::FEXP: 424 case ISD::FEXP2: 425 case ISD::FCEIL: 426 case ISD::FTRUNC: 427 case ISD::FRINT: 428 case ISD::FNEARBYINT: 429 case ISD::FROUND: 430 case ISD::FFLOOR: 431 case ISD::FP_ROUND: 432 case ISD::FP_EXTEND: 433 case ISD::FMA: 434 case ISD::SIGN_EXTEND_INREG: 435 case ISD::ANY_EXTEND_VECTOR_INREG: 436 case ISD::SIGN_EXTEND_VECTOR_INREG: 437 case ISD::ZERO_EXTEND_VECTOR_INREG: 438 case ISD::SMIN: 439 case ISD::SMAX: 440 case ISD::UMIN: 441 case ISD::UMAX: 442 case ISD::SMUL_LOHI: 443 case ISD::UMUL_LOHI: 444 case ISD::SADDO: 445 case ISD::UADDO: 446 case ISD::SSUBO: 447 case ISD::USUBO: 448 case ISD::SMULO: 449 case ISD::UMULO: 450 case ISD::FCANONICALIZE: 451 case ISD::SADDSAT: 452 case ISD::UADDSAT: 453 case ISD::SSUBSAT: 454 case ISD::USUBSAT: 455 Action = TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)); 456 break; 457 case ISD::SMULFIX: 458 case ISD::SMULFIXSAT: 459 case ISD::UMULFIX: 460 case ISD::UMULFIXSAT: 461 case ISD::SDIVFIX: 462 case ISD::SDIVFIXSAT: 463 case ISD::UDIVFIX: 464 case ISD::UDIVFIXSAT: { 465 unsigned Scale = Node->getConstantOperandVal(2); 466 Action = TLI.getFixedPointOperationAction(Node->getOpcode(), 467 Node->getValueType(0), Scale); 468 break; 469 } 470 case ISD::SINT_TO_FP: 471 case ISD::UINT_TO_FP: 472 case ISD::VECREDUCE_ADD: 473 case ISD::VECREDUCE_MUL: 474 case ISD::VECREDUCE_AND: 475 case ISD::VECREDUCE_OR: 476 case ISD::VECREDUCE_XOR: 477 case ISD::VECREDUCE_SMAX: 478 case ISD::VECREDUCE_SMIN: 479 case ISD::VECREDUCE_UMAX: 480 case ISD::VECREDUCE_UMIN: 481 case ISD::VECREDUCE_FADD: 482 case ISD::VECREDUCE_FMUL: 483 case ISD::VECREDUCE_FMAX: 484 case ISD::VECREDUCE_FMIN: 485 Action = TLI.getOperationAction(Node->getOpcode(), 486 Node->getOperand(0).getValueType()); 487 break; 488 } 489 490 LLVM_DEBUG(dbgs() << "\nLegalizing vector op: "; Node->dump(&DAG)); 491 492 SmallVector<SDValue, 8> ResultVals; 493 switch (Action) { 494 default: llvm_unreachable("This action is not supported yet!"); 495 case TargetLowering::Promote: 496 LLVM_DEBUG(dbgs() << "Promoting\n"); 497 Promote(Node, ResultVals); 498 assert(!ResultVals.empty() && "No results for promotion?"); 499 break; 500 case TargetLowering::Legal: 501 LLVM_DEBUG(dbgs() << "Legal node: nothing to do\n"); 502 break; 503 case TargetLowering::Custom: 504 LLVM_DEBUG(dbgs() << "Trying custom legalization\n"); 505 if (LowerOperationWrapper(Node, ResultVals)) 506 break; 507 LLVM_DEBUG(dbgs() << "Could not custom legalize node\n"); 508 LLVM_FALLTHROUGH; 509 case TargetLowering::Expand: 510 LLVM_DEBUG(dbgs() << "Expanding\n"); 511 Expand(Node, ResultVals); 512 break; 513 } 514 515 if (ResultVals.empty()) 516 return TranslateLegalizeResults(Op, Node); 517 518 Changed = true; 519 return RecursivelyLegalizeResults(Op, ResultVals); 520 } 521 522 // FIME: This is very similar to the X86 override of 523 // TargetLowering::LowerOperationWrapper. Can we merge them somehow? 524 bool VectorLegalizer::LowerOperationWrapper(SDNode *Node, 525 SmallVectorImpl<SDValue> &Results) { 526 SDValue Res = TLI.LowerOperation(SDValue(Node, 0), DAG); 527 528 if (!Res.getNode()) 529 return false; 530 531 if (Res == SDValue(Node, 0)) 532 return true; 533 534 // If the original node has one result, take the return value from 535 // LowerOperation as is. It might not be result number 0. 536 if (Node->getNumValues() == 1) { 537 Results.push_back(Res); 538 return true; 539 } 540 541 // If the original node has multiple results, then the return node should 542 // have the same number of results. 543 assert((Node->getNumValues() == Res->getNumValues()) && 544 "Lowering returned the wrong number of results!"); 545 546 // Places new result values base on N result number. 547 for (unsigned I = 0, E = Node->getNumValues(); I != E; ++I) 548 Results.push_back(Res.getValue(I)); 549 550 return true; 551 } 552 553 void VectorLegalizer::Promote(SDNode *Node, SmallVectorImpl<SDValue> &Results) { 554 // For a few operations there is a specific concept for promotion based on 555 // the operand's type. 556 switch (Node->getOpcode()) { 557 case ISD::SINT_TO_FP: 558 case ISD::UINT_TO_FP: 559 case ISD::STRICT_SINT_TO_FP: 560 case ISD::STRICT_UINT_TO_FP: 561 // "Promote" the operation by extending the operand. 562 PromoteINT_TO_FP(Node, Results); 563 return; 564 case ISD::FP_TO_UINT: 565 case ISD::FP_TO_SINT: 566 case ISD::STRICT_FP_TO_UINT: 567 case ISD::STRICT_FP_TO_SINT: 568 // Promote the operation by extending the operand. 569 PromoteFP_TO_INT(Node, Results); 570 return; 571 case ISD::FP_ROUND: 572 case ISD::FP_EXTEND: 573 // These operations are used to do promotion so they can't be promoted 574 // themselves. 575 llvm_unreachable("Don't know how to promote this operation!"); 576 } 577 578 // There are currently two cases of vector promotion: 579 // 1) Bitcasting a vector of integers to a different type to a vector of the 580 // same overall length. For example, x86 promotes ISD::AND v2i32 to v1i64. 581 // 2) Extending a vector of floats to a vector of the same number of larger 582 // floats. For example, AArch64 promotes ISD::FADD on v4f16 to v4f32. 583 assert(Node->getNumValues() == 1 && 584 "Can't promote a vector with multiple results!"); 585 MVT VT = Node->getSimpleValueType(0); 586 MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VT); 587 SDLoc dl(Node); 588 SmallVector<SDValue, 4> Operands(Node->getNumOperands()); 589 590 for (unsigned j = 0; j != Node->getNumOperands(); ++j) { 591 if (Node->getOperand(j).getValueType().isVector()) 592 if (Node->getOperand(j) 593 .getValueType() 594 .getVectorElementType() 595 .isFloatingPoint() && 596 NVT.isVector() && NVT.getVectorElementType().isFloatingPoint()) 597 Operands[j] = DAG.getNode(ISD::FP_EXTEND, dl, NVT, Node->getOperand(j)); 598 else 599 Operands[j] = DAG.getNode(ISD::BITCAST, dl, NVT, Node->getOperand(j)); 600 else 601 Operands[j] = Node->getOperand(j); 602 } 603 604 SDValue Res = 605 DAG.getNode(Node->getOpcode(), dl, NVT, Operands, Node->getFlags()); 606 607 if ((VT.isFloatingPoint() && NVT.isFloatingPoint()) || 608 (VT.isVector() && VT.getVectorElementType().isFloatingPoint() && 609 NVT.isVector() && NVT.getVectorElementType().isFloatingPoint())) 610 Res = DAG.getNode(ISD::FP_ROUND, dl, VT, Res, DAG.getIntPtrConstant(0, dl)); 611 else 612 Res = DAG.getNode(ISD::BITCAST, dl, VT, Res); 613 614 Results.push_back(Res); 615 } 616 617 void VectorLegalizer::PromoteINT_TO_FP(SDNode *Node, 618 SmallVectorImpl<SDValue> &Results) { 619 // INT_TO_FP operations may require the input operand be promoted even 620 // when the type is otherwise legal. 621 bool IsStrict = Node->isStrictFPOpcode(); 622 MVT VT = Node->getOperand(IsStrict ? 1 : 0).getSimpleValueType(); 623 MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VT); 624 assert(NVT.getVectorNumElements() == VT.getVectorNumElements() && 625 "Vectors have different number of elements!"); 626 627 SDLoc dl(Node); 628 SmallVector<SDValue, 4> Operands(Node->getNumOperands()); 629 630 unsigned Opc = (Node->getOpcode() == ISD::UINT_TO_FP || 631 Node->getOpcode() == ISD::STRICT_UINT_TO_FP) 632 ? ISD::ZERO_EXTEND 633 : ISD::SIGN_EXTEND; 634 for (unsigned j = 0; j != Node->getNumOperands(); ++j) { 635 if (Node->getOperand(j).getValueType().isVector()) 636 Operands[j] = DAG.getNode(Opc, dl, NVT, Node->getOperand(j)); 637 else 638 Operands[j] = Node->getOperand(j); 639 } 640 641 if (IsStrict) { 642 SDValue Res = DAG.getNode(Node->getOpcode(), dl, 643 {Node->getValueType(0), MVT::Other}, Operands); 644 Results.push_back(Res); 645 Results.push_back(Res.getValue(1)); 646 return; 647 } 648 649 SDValue Res = 650 DAG.getNode(Node->getOpcode(), dl, Node->getValueType(0), Operands); 651 Results.push_back(Res); 652 } 653 654 // For FP_TO_INT we promote the result type to a vector type with wider 655 // elements and then truncate the result. This is different from the default 656 // PromoteVector which uses bitcast to promote thus assumning that the 657 // promoted vector type has the same overall size. 658 void VectorLegalizer::PromoteFP_TO_INT(SDNode *Node, 659 SmallVectorImpl<SDValue> &Results) { 660 MVT VT = Node->getSimpleValueType(0); 661 MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VT); 662 bool IsStrict = Node->isStrictFPOpcode(); 663 assert(NVT.getVectorNumElements() == VT.getVectorNumElements() && 664 "Vectors have different number of elements!"); 665 666 unsigned NewOpc = Node->getOpcode(); 667 // Change FP_TO_UINT to FP_TO_SINT if possible. 668 // TODO: Should we only do this if FP_TO_UINT itself isn't legal? 669 if (NewOpc == ISD::FP_TO_UINT && 670 TLI.isOperationLegalOrCustom(ISD::FP_TO_SINT, NVT)) 671 NewOpc = ISD::FP_TO_SINT; 672 673 if (NewOpc == ISD::STRICT_FP_TO_UINT && 674 TLI.isOperationLegalOrCustom(ISD::STRICT_FP_TO_SINT, NVT)) 675 NewOpc = ISD::STRICT_FP_TO_SINT; 676 677 SDLoc dl(Node); 678 SDValue Promoted, Chain; 679 if (IsStrict) { 680 Promoted = DAG.getNode(NewOpc, dl, {NVT, MVT::Other}, 681 {Node->getOperand(0), Node->getOperand(1)}); 682 Chain = Promoted.getValue(1); 683 } else 684 Promoted = DAG.getNode(NewOpc, dl, NVT, Node->getOperand(0)); 685 686 // Assert that the converted value fits in the original type. If it doesn't 687 // (eg: because the value being converted is too big), then the result of the 688 // original operation was undefined anyway, so the assert is still correct. 689 if (Node->getOpcode() == ISD::FP_TO_UINT || 690 Node->getOpcode() == ISD::STRICT_FP_TO_UINT) 691 NewOpc = ISD::AssertZext; 692 else 693 NewOpc = ISD::AssertSext; 694 695 Promoted = DAG.getNode(NewOpc, dl, NVT, Promoted, 696 DAG.getValueType(VT.getScalarType())); 697 Promoted = DAG.getNode(ISD::TRUNCATE, dl, VT, Promoted); 698 Results.push_back(Promoted); 699 if (IsStrict) 700 Results.push_back(Chain); 701 } 702 703 std::pair<SDValue, SDValue> VectorLegalizer::ExpandLoad(SDNode *N) { 704 LoadSDNode *LD = cast<LoadSDNode>(N); 705 706 EVT SrcVT = LD->getMemoryVT(); 707 EVT SrcEltVT = SrcVT.getScalarType(); 708 unsigned NumElem = SrcVT.getVectorNumElements(); 709 710 SDValue NewChain; 711 SDValue Value; 712 if (SrcVT.getVectorNumElements() > 1 && !SrcEltVT.isByteSized()) { 713 SDLoc dl(N); 714 715 SmallVector<SDValue, 8> Vals; 716 SmallVector<SDValue, 8> LoadChains; 717 718 EVT DstEltVT = LD->getValueType(0).getScalarType(); 719 SDValue Chain = LD->getChain(); 720 SDValue BasePTR = LD->getBasePtr(); 721 ISD::LoadExtType ExtType = LD->getExtensionType(); 722 723 // When elements in a vector is not byte-addressable, we cannot directly 724 // load each element by advancing pointer, which could only address bytes. 725 // Instead, we load all significant words, mask bits off, and concatenate 726 // them to form each element. Finally, they are extended to destination 727 // scalar type to build the destination vector. 728 EVT WideVT = TLI.getPointerTy(DAG.getDataLayout()); 729 730 assert(WideVT.isRound() && 731 "Could not handle the sophisticated case when the widest integer is" 732 " not power of 2."); 733 assert(WideVT.bitsGE(SrcEltVT) && 734 "Type is not legalized?"); 735 736 unsigned WideBytes = WideVT.getStoreSize(); 737 unsigned Offset = 0; 738 unsigned RemainingBytes = SrcVT.getStoreSize(); 739 SmallVector<SDValue, 8> LoadVals; 740 while (RemainingBytes > 0) { 741 SDValue ScalarLoad; 742 unsigned LoadBytes = WideBytes; 743 744 if (RemainingBytes >= LoadBytes) { 745 ScalarLoad = DAG.getLoad( 746 WideVT, dl, Chain, BasePTR, 747 LD->getPointerInfo().getWithOffset(Offset), LD->getOriginalAlign(), 748 LD->getMemOperand()->getFlags(), LD->getAAInfo()); 749 } else { 750 EVT LoadVT = WideVT; 751 while (RemainingBytes < LoadBytes) { 752 LoadBytes >>= 1; // Reduce the load size by half. 753 LoadVT = EVT::getIntegerVT(*DAG.getContext(), LoadBytes << 3); 754 } 755 ScalarLoad = 756 DAG.getExtLoad(ISD::EXTLOAD, dl, WideVT, Chain, BasePTR, 757 LD->getPointerInfo().getWithOffset(Offset), LoadVT, 758 LD->getOriginalAlign(), 759 LD->getMemOperand()->getFlags(), LD->getAAInfo()); 760 } 761 762 RemainingBytes -= LoadBytes; 763 Offset += LoadBytes; 764 765 BasePTR = DAG.getObjectPtrOffset(dl, BasePTR, LoadBytes); 766 767 LoadVals.push_back(ScalarLoad.getValue(0)); 768 LoadChains.push_back(ScalarLoad.getValue(1)); 769 } 770 771 unsigned BitOffset = 0; 772 unsigned WideIdx = 0; 773 unsigned WideBits = WideVT.getSizeInBits(); 774 775 // Extract bits, pack and extend/trunc them into destination type. 776 unsigned SrcEltBits = SrcEltVT.getSizeInBits(); 777 SDValue SrcEltBitMask = DAG.getConstant( 778 APInt::getLowBitsSet(WideBits, SrcEltBits), dl, WideVT); 779 780 for (unsigned Idx = 0; Idx != NumElem; ++Idx) { 781 assert(BitOffset < WideBits && "Unexpected offset!"); 782 783 SDValue ShAmt = DAG.getConstant( 784 BitOffset, dl, TLI.getShiftAmountTy(WideVT, DAG.getDataLayout())); 785 SDValue Lo = DAG.getNode(ISD::SRL, dl, WideVT, LoadVals[WideIdx], ShAmt); 786 787 BitOffset += SrcEltBits; 788 if (BitOffset >= WideBits) { 789 WideIdx++; 790 BitOffset -= WideBits; 791 if (BitOffset > 0) { 792 ShAmt = DAG.getConstant( 793 SrcEltBits - BitOffset, dl, 794 TLI.getShiftAmountTy(WideVT, DAG.getDataLayout())); 795 SDValue Hi = 796 DAG.getNode(ISD::SHL, dl, WideVT, LoadVals[WideIdx], ShAmt); 797 Lo = DAG.getNode(ISD::OR, dl, WideVT, Lo, Hi); 798 } 799 } 800 801 Lo = DAG.getNode(ISD::AND, dl, WideVT, Lo, SrcEltBitMask); 802 803 switch (ExtType) { 804 default: llvm_unreachable("Unknown extended-load op!"); 805 case ISD::EXTLOAD: 806 Lo = DAG.getAnyExtOrTrunc(Lo, dl, DstEltVT); 807 break; 808 case ISD::ZEXTLOAD: 809 Lo = DAG.getZExtOrTrunc(Lo, dl, DstEltVT); 810 break; 811 case ISD::SEXTLOAD: 812 ShAmt = 813 DAG.getConstant(WideBits - SrcEltBits, dl, 814 TLI.getShiftAmountTy(WideVT, DAG.getDataLayout())); 815 Lo = DAG.getNode(ISD::SHL, dl, WideVT, Lo, ShAmt); 816 Lo = DAG.getNode(ISD::SRA, dl, WideVT, Lo, ShAmt); 817 Lo = DAG.getSExtOrTrunc(Lo, dl, DstEltVT); 818 break; 819 } 820 Vals.push_back(Lo); 821 } 822 823 NewChain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, LoadChains); 824 Value = DAG.getBuildVector(N->getValueType(0), dl, Vals); 825 } else { 826 std::tie(Value, NewChain) = TLI.scalarizeVectorLoad(LD, DAG); 827 } 828 829 return std::make_pair(Value, NewChain); 830 } 831 832 SDValue VectorLegalizer::ExpandStore(SDNode *N) { 833 StoreSDNode *ST = cast<StoreSDNode>(N); 834 SDValue TF = TLI.scalarizeVectorStore(ST, DAG); 835 return TF; 836 } 837 838 void VectorLegalizer::Expand(SDNode *Node, SmallVectorImpl<SDValue> &Results) { 839 SDValue Tmp; 840 switch (Node->getOpcode()) { 841 case ISD::MERGE_VALUES: 842 for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) 843 Results.push_back(Node->getOperand(i)); 844 return; 845 case ISD::SIGN_EXTEND_INREG: 846 Results.push_back(ExpandSEXTINREG(Node)); 847 return; 848 case ISD::ANY_EXTEND_VECTOR_INREG: 849 Results.push_back(ExpandANY_EXTEND_VECTOR_INREG(Node)); 850 return; 851 case ISD::SIGN_EXTEND_VECTOR_INREG: 852 Results.push_back(ExpandSIGN_EXTEND_VECTOR_INREG(Node)); 853 return; 854 case ISD::ZERO_EXTEND_VECTOR_INREG: 855 Results.push_back(ExpandZERO_EXTEND_VECTOR_INREG(Node)); 856 return; 857 case ISD::BSWAP: 858 Results.push_back(ExpandBSWAP(Node)); 859 return; 860 case ISD::VSELECT: 861 Results.push_back(ExpandVSELECT(Node)); 862 return; 863 case ISD::SELECT: 864 Results.push_back(ExpandSELECT(Node)); 865 return; 866 case ISD::FP_TO_UINT: 867 ExpandFP_TO_UINT(Node, Results); 868 return; 869 case ISD::UINT_TO_FP: 870 ExpandUINT_TO_FLOAT(Node, Results); 871 return; 872 case ISD::FNEG: 873 Results.push_back(ExpandFNEG(Node)); 874 return; 875 case ISD::FSUB: 876 ExpandFSUB(Node, Results); 877 return; 878 case ISD::SETCC: 879 Results.push_back(UnrollVSETCC(Node)); 880 return; 881 case ISD::ABS: 882 if (TLI.expandABS(Node, Tmp, DAG)) { 883 Results.push_back(Tmp); 884 return; 885 } 886 break; 887 case ISD::BITREVERSE: 888 ExpandBITREVERSE(Node, Results); 889 return; 890 case ISD::CTPOP: 891 if (TLI.expandCTPOP(Node, Tmp, DAG)) { 892 Results.push_back(Tmp); 893 return; 894 } 895 break; 896 case ISD::CTLZ: 897 case ISD::CTLZ_ZERO_UNDEF: 898 if (TLI.expandCTLZ(Node, Tmp, DAG)) { 899 Results.push_back(Tmp); 900 return; 901 } 902 break; 903 case ISD::CTTZ: 904 case ISD::CTTZ_ZERO_UNDEF: 905 if (TLI.expandCTTZ(Node, Tmp, DAG)) { 906 Results.push_back(Tmp); 907 return; 908 } 909 break; 910 case ISD::FSHL: 911 case ISD::FSHR: 912 if (TLI.expandFunnelShift(Node, Tmp, DAG)) { 913 Results.push_back(Tmp); 914 return; 915 } 916 break; 917 case ISD::ROTL: 918 case ISD::ROTR: 919 if (TLI.expandROT(Node, Tmp, DAG)) { 920 Results.push_back(Tmp); 921 return; 922 } 923 break; 924 case ISD::FMINNUM: 925 case ISD::FMAXNUM: 926 if (SDValue Expanded = TLI.expandFMINNUM_FMAXNUM(Node, DAG)) { 927 Results.push_back(Expanded); 928 return; 929 } 930 break; 931 case ISD::UADDO: 932 case ISD::USUBO: 933 ExpandUADDSUBO(Node, Results); 934 return; 935 case ISD::SADDO: 936 case ISD::SSUBO: 937 ExpandSADDSUBO(Node, Results); 938 return; 939 case ISD::UMULO: 940 case ISD::SMULO: 941 ExpandMULO(Node, Results); 942 return; 943 case ISD::USUBSAT: 944 case ISD::SSUBSAT: 945 case ISD::UADDSAT: 946 case ISD::SADDSAT: 947 if (SDValue Expanded = TLI.expandAddSubSat(Node, DAG)) { 948 Results.push_back(Expanded); 949 return; 950 } 951 break; 952 case ISD::SMULFIX: 953 case ISD::UMULFIX: 954 if (SDValue Expanded = TLI.expandFixedPointMul(Node, DAG)) { 955 Results.push_back(Expanded); 956 return; 957 } 958 break; 959 case ISD::SMULFIXSAT: 960 case ISD::UMULFIXSAT: 961 // FIXME: We do not expand SMULFIXSAT/UMULFIXSAT here yet, not sure exactly 962 // why. Maybe it results in worse codegen compared to the unroll for some 963 // targets? This should probably be investigated. And if we still prefer to 964 // unroll an explanation could be helpful. 965 break; 966 case ISD::SDIVFIX: 967 case ISD::UDIVFIX: 968 ExpandFixedPointDiv(Node, Results); 969 return; 970 case ISD::SDIVFIXSAT: 971 case ISD::UDIVFIXSAT: 972 break; 973 #define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \ 974 case ISD::STRICT_##DAGN: 975 #include "llvm/IR/ConstrainedOps.def" 976 ExpandStrictFPOp(Node, Results); 977 return; 978 case ISD::VECREDUCE_ADD: 979 case ISD::VECREDUCE_MUL: 980 case ISD::VECREDUCE_AND: 981 case ISD::VECREDUCE_OR: 982 case ISD::VECREDUCE_XOR: 983 case ISD::VECREDUCE_SMAX: 984 case ISD::VECREDUCE_SMIN: 985 case ISD::VECREDUCE_UMAX: 986 case ISD::VECREDUCE_UMIN: 987 case ISD::VECREDUCE_FADD: 988 case ISD::VECREDUCE_FMUL: 989 case ISD::VECREDUCE_FMAX: 990 case ISD::VECREDUCE_FMIN: 991 Results.push_back(TLI.expandVecReduce(Node, DAG)); 992 return; 993 } 994 995 Results.push_back(DAG.UnrollVectorOp(Node)); 996 } 997 998 SDValue VectorLegalizer::ExpandSELECT(SDNode *Node) { 999 // Lower a select instruction where the condition is a scalar and the 1000 // operands are vectors. Lower this select to VSELECT and implement it 1001 // using XOR AND OR. The selector bit is broadcasted. 1002 EVT VT = Node->getValueType(0); 1003 SDLoc DL(Node); 1004 1005 SDValue Mask = Node->getOperand(0); 1006 SDValue Op1 = Node->getOperand(1); 1007 SDValue Op2 = Node->getOperand(2); 1008 1009 assert(VT.isVector() && !Mask.getValueType().isVector() 1010 && Op1.getValueType() == Op2.getValueType() && "Invalid type"); 1011 1012 // If we can't even use the basic vector operations of 1013 // AND,OR,XOR, we will have to scalarize the op. 1014 // Notice that the operation may be 'promoted' which means that it is 1015 // 'bitcasted' to another type which is handled. 1016 // Also, we need to be able to construct a splat vector using BUILD_VECTOR. 1017 if (TLI.getOperationAction(ISD::AND, VT) == TargetLowering::Expand || 1018 TLI.getOperationAction(ISD::XOR, VT) == TargetLowering::Expand || 1019 TLI.getOperationAction(ISD::OR, VT) == TargetLowering::Expand || 1020 TLI.getOperationAction(ISD::BUILD_VECTOR, VT) == TargetLowering::Expand) 1021 return DAG.UnrollVectorOp(Node); 1022 1023 // Generate a mask operand. 1024 EVT MaskTy = VT.changeVectorElementTypeToInteger(); 1025 1026 // What is the size of each element in the vector mask. 1027 EVT BitTy = MaskTy.getScalarType(); 1028 1029 Mask = DAG.getSelect(DL, BitTy, Mask, 1030 DAG.getConstant(APInt::getAllOnesValue(BitTy.getSizeInBits()), DL, 1031 BitTy), 1032 DAG.getConstant(0, DL, BitTy)); 1033 1034 // Broadcast the mask so that the entire vector is all-one or all zero. 1035 Mask = DAG.getSplatBuildVector(MaskTy, DL, Mask); 1036 1037 // Bitcast the operands to be the same type as the mask. 1038 // This is needed when we select between FP types because 1039 // the mask is a vector of integers. 1040 Op1 = DAG.getNode(ISD::BITCAST, DL, MaskTy, Op1); 1041 Op2 = DAG.getNode(ISD::BITCAST, DL, MaskTy, Op2); 1042 1043 SDValue AllOnes = DAG.getConstant( 1044 APInt::getAllOnesValue(BitTy.getSizeInBits()), DL, MaskTy); 1045 SDValue NotMask = DAG.getNode(ISD::XOR, DL, MaskTy, Mask, AllOnes); 1046 1047 Op1 = DAG.getNode(ISD::AND, DL, MaskTy, Op1, Mask); 1048 Op2 = DAG.getNode(ISD::AND, DL, MaskTy, Op2, NotMask); 1049 SDValue Val = DAG.getNode(ISD::OR, DL, MaskTy, Op1, Op2); 1050 return DAG.getNode(ISD::BITCAST, DL, Node->getValueType(0), Val); 1051 } 1052 1053 SDValue VectorLegalizer::ExpandSEXTINREG(SDNode *Node) { 1054 EVT VT = Node->getValueType(0); 1055 1056 // Make sure that the SRA and SHL instructions are available. 1057 if (TLI.getOperationAction(ISD::SRA, VT) == TargetLowering::Expand || 1058 TLI.getOperationAction(ISD::SHL, VT) == TargetLowering::Expand) 1059 return DAG.UnrollVectorOp(Node); 1060 1061 SDLoc DL(Node); 1062 EVT OrigTy = cast<VTSDNode>(Node->getOperand(1))->getVT(); 1063 1064 unsigned BW = VT.getScalarSizeInBits(); 1065 unsigned OrigBW = OrigTy.getScalarSizeInBits(); 1066 SDValue ShiftSz = DAG.getConstant(BW - OrigBW, DL, VT); 1067 1068 SDValue Op = DAG.getNode(ISD::SHL, DL, VT, Node->getOperand(0), ShiftSz); 1069 return DAG.getNode(ISD::SRA, DL, VT, Op, ShiftSz); 1070 } 1071 1072 // Generically expand a vector anyext in register to a shuffle of the relevant 1073 // lanes into the appropriate locations, with other lanes left undef. 1074 SDValue VectorLegalizer::ExpandANY_EXTEND_VECTOR_INREG(SDNode *Node) { 1075 SDLoc DL(Node); 1076 EVT VT = Node->getValueType(0); 1077 int NumElements = VT.getVectorNumElements(); 1078 SDValue Src = Node->getOperand(0); 1079 EVT SrcVT = Src.getValueType(); 1080 int NumSrcElements = SrcVT.getVectorNumElements(); 1081 1082 // *_EXTEND_VECTOR_INREG SrcVT can be smaller than VT - so insert the vector 1083 // into a larger vector type. 1084 if (SrcVT.bitsLE(VT)) { 1085 assert((VT.getSizeInBits() % SrcVT.getScalarSizeInBits()) == 0 && 1086 "ANY_EXTEND_VECTOR_INREG vector size mismatch"); 1087 NumSrcElements = VT.getSizeInBits() / SrcVT.getScalarSizeInBits(); 1088 SrcVT = EVT::getVectorVT(*DAG.getContext(), SrcVT.getScalarType(), 1089 NumSrcElements); 1090 Src = DAG.getNode(ISD::INSERT_SUBVECTOR, DL, SrcVT, DAG.getUNDEF(SrcVT), 1091 Src, DAG.getVectorIdxConstant(0, DL)); 1092 } 1093 1094 // Build a base mask of undef shuffles. 1095 SmallVector<int, 16> ShuffleMask; 1096 ShuffleMask.resize(NumSrcElements, -1); 1097 1098 // Place the extended lanes into the correct locations. 1099 int ExtLaneScale = NumSrcElements / NumElements; 1100 int EndianOffset = DAG.getDataLayout().isBigEndian() ? ExtLaneScale - 1 : 0; 1101 for (int i = 0; i < NumElements; ++i) 1102 ShuffleMask[i * ExtLaneScale + EndianOffset] = i; 1103 1104 return DAG.getNode( 1105 ISD::BITCAST, DL, VT, 1106 DAG.getVectorShuffle(SrcVT, DL, Src, DAG.getUNDEF(SrcVT), ShuffleMask)); 1107 } 1108 1109 SDValue VectorLegalizer::ExpandSIGN_EXTEND_VECTOR_INREG(SDNode *Node) { 1110 SDLoc DL(Node); 1111 EVT VT = Node->getValueType(0); 1112 SDValue Src = Node->getOperand(0); 1113 EVT SrcVT = Src.getValueType(); 1114 1115 // First build an any-extend node which can be legalized above when we 1116 // recurse through it. 1117 SDValue Op = DAG.getNode(ISD::ANY_EXTEND_VECTOR_INREG, DL, VT, Src); 1118 1119 // Now we need sign extend. Do this by shifting the elements. Even if these 1120 // aren't legal operations, they have a better chance of being legalized 1121 // without full scalarization than the sign extension does. 1122 unsigned EltWidth = VT.getScalarSizeInBits(); 1123 unsigned SrcEltWidth = SrcVT.getScalarSizeInBits(); 1124 SDValue ShiftAmount = DAG.getConstant(EltWidth - SrcEltWidth, DL, VT); 1125 return DAG.getNode(ISD::SRA, DL, VT, 1126 DAG.getNode(ISD::SHL, DL, VT, Op, ShiftAmount), 1127 ShiftAmount); 1128 } 1129 1130 // Generically expand a vector zext in register to a shuffle of the relevant 1131 // lanes into the appropriate locations, a blend of zero into the high bits, 1132 // and a bitcast to the wider element type. 1133 SDValue VectorLegalizer::ExpandZERO_EXTEND_VECTOR_INREG(SDNode *Node) { 1134 SDLoc DL(Node); 1135 EVT VT = Node->getValueType(0); 1136 int NumElements = VT.getVectorNumElements(); 1137 SDValue Src = Node->getOperand(0); 1138 EVT SrcVT = Src.getValueType(); 1139 int NumSrcElements = SrcVT.getVectorNumElements(); 1140 1141 // *_EXTEND_VECTOR_INREG SrcVT can be smaller than VT - so insert the vector 1142 // into a larger vector type. 1143 if (SrcVT.bitsLE(VT)) { 1144 assert((VT.getSizeInBits() % SrcVT.getScalarSizeInBits()) == 0 && 1145 "ZERO_EXTEND_VECTOR_INREG vector size mismatch"); 1146 NumSrcElements = VT.getSizeInBits() / SrcVT.getScalarSizeInBits(); 1147 SrcVT = EVT::getVectorVT(*DAG.getContext(), SrcVT.getScalarType(), 1148 NumSrcElements); 1149 Src = DAG.getNode(ISD::INSERT_SUBVECTOR, DL, SrcVT, DAG.getUNDEF(SrcVT), 1150 Src, DAG.getVectorIdxConstant(0, DL)); 1151 } 1152 1153 // Build up a zero vector to blend into this one. 1154 SDValue Zero = DAG.getConstant(0, DL, SrcVT); 1155 1156 // Shuffle the incoming lanes into the correct position, and pull all other 1157 // lanes from the zero vector. 1158 SmallVector<int, 16> ShuffleMask; 1159 ShuffleMask.reserve(NumSrcElements); 1160 for (int i = 0; i < NumSrcElements; ++i) 1161 ShuffleMask.push_back(i); 1162 1163 int ExtLaneScale = NumSrcElements / NumElements; 1164 int EndianOffset = DAG.getDataLayout().isBigEndian() ? ExtLaneScale - 1 : 0; 1165 for (int i = 0; i < NumElements; ++i) 1166 ShuffleMask[i * ExtLaneScale + EndianOffset] = NumSrcElements + i; 1167 1168 return DAG.getNode(ISD::BITCAST, DL, VT, 1169 DAG.getVectorShuffle(SrcVT, DL, Zero, Src, ShuffleMask)); 1170 } 1171 1172 static void createBSWAPShuffleMask(EVT VT, SmallVectorImpl<int> &ShuffleMask) { 1173 int ScalarSizeInBytes = VT.getScalarSizeInBits() / 8; 1174 for (int I = 0, E = VT.getVectorNumElements(); I != E; ++I) 1175 for (int J = ScalarSizeInBytes - 1; J >= 0; --J) 1176 ShuffleMask.push_back((I * ScalarSizeInBytes) + J); 1177 } 1178 1179 SDValue VectorLegalizer::ExpandBSWAP(SDNode *Node) { 1180 EVT VT = Node->getValueType(0); 1181 1182 // Generate a byte wise shuffle mask for the BSWAP. 1183 SmallVector<int, 16> ShuffleMask; 1184 createBSWAPShuffleMask(VT, ShuffleMask); 1185 EVT ByteVT = EVT::getVectorVT(*DAG.getContext(), MVT::i8, ShuffleMask.size()); 1186 1187 // Only emit a shuffle if the mask is legal. 1188 if (!TLI.isShuffleMaskLegal(ShuffleMask, ByteVT)) 1189 return DAG.UnrollVectorOp(Node); 1190 1191 SDLoc DL(Node); 1192 SDValue Op = DAG.getNode(ISD::BITCAST, DL, ByteVT, Node->getOperand(0)); 1193 Op = DAG.getVectorShuffle(ByteVT, DL, Op, DAG.getUNDEF(ByteVT), ShuffleMask); 1194 return DAG.getNode(ISD::BITCAST, DL, VT, Op); 1195 } 1196 1197 void VectorLegalizer::ExpandBITREVERSE(SDNode *Node, 1198 SmallVectorImpl<SDValue> &Results) { 1199 EVT VT = Node->getValueType(0); 1200 1201 // If we have the scalar operation, it's probably cheaper to unroll it. 1202 if (TLI.isOperationLegalOrCustom(ISD::BITREVERSE, VT.getScalarType())) { 1203 SDValue Tmp = DAG.UnrollVectorOp(Node); 1204 Results.push_back(Tmp); 1205 return; 1206 } 1207 1208 // If the vector element width is a whole number of bytes, test if its legal 1209 // to BSWAP shuffle the bytes and then perform the BITREVERSE on the byte 1210 // vector. This greatly reduces the number of bit shifts necessary. 1211 unsigned ScalarSizeInBits = VT.getScalarSizeInBits(); 1212 if (ScalarSizeInBits > 8 && (ScalarSizeInBits % 8) == 0) { 1213 SmallVector<int, 16> BSWAPMask; 1214 createBSWAPShuffleMask(VT, BSWAPMask); 1215 1216 EVT ByteVT = EVT::getVectorVT(*DAG.getContext(), MVT::i8, BSWAPMask.size()); 1217 if (TLI.isShuffleMaskLegal(BSWAPMask, ByteVT) && 1218 (TLI.isOperationLegalOrCustom(ISD::BITREVERSE, ByteVT) || 1219 (TLI.isOperationLegalOrCustom(ISD::SHL, ByteVT) && 1220 TLI.isOperationLegalOrCustom(ISD::SRL, ByteVT) && 1221 TLI.isOperationLegalOrCustomOrPromote(ISD::AND, ByteVT) && 1222 TLI.isOperationLegalOrCustomOrPromote(ISD::OR, ByteVT)))) { 1223 SDLoc DL(Node); 1224 SDValue Op = DAG.getNode(ISD::BITCAST, DL, ByteVT, Node->getOperand(0)); 1225 Op = DAG.getVectorShuffle(ByteVT, DL, Op, DAG.getUNDEF(ByteVT), 1226 BSWAPMask); 1227 Op = DAG.getNode(ISD::BITREVERSE, DL, ByteVT, Op); 1228 Op = DAG.getNode(ISD::BITCAST, DL, VT, Op); 1229 Results.push_back(Op); 1230 return; 1231 } 1232 } 1233 1234 // If we have the appropriate vector bit operations, it is better to use them 1235 // than unrolling and expanding each component. 1236 if (TLI.isOperationLegalOrCustom(ISD::SHL, VT) && 1237 TLI.isOperationLegalOrCustom(ISD::SRL, VT) && 1238 TLI.isOperationLegalOrCustomOrPromote(ISD::AND, VT) && 1239 TLI.isOperationLegalOrCustomOrPromote(ISD::OR, VT)) 1240 // Let LegalizeDAG handle this later. 1241 return; 1242 1243 // Otherwise unroll. 1244 SDValue Tmp = DAG.UnrollVectorOp(Node); 1245 Results.push_back(Tmp); 1246 } 1247 1248 SDValue VectorLegalizer::ExpandVSELECT(SDNode *Node) { 1249 // Implement VSELECT in terms of XOR, AND, OR 1250 // on platforms which do not support blend natively. 1251 SDLoc DL(Node); 1252 1253 SDValue Mask = Node->getOperand(0); 1254 SDValue Op1 = Node->getOperand(1); 1255 SDValue Op2 = Node->getOperand(2); 1256 1257 EVT VT = Mask.getValueType(); 1258 1259 // If we can't even use the basic vector operations of 1260 // AND,OR,XOR, we will have to scalarize the op. 1261 // Notice that the operation may be 'promoted' which means that it is 1262 // 'bitcasted' to another type which is handled. 1263 // This operation also isn't safe with AND, OR, XOR when the boolean 1264 // type is 0/1 as we need an all ones vector constant to mask with. 1265 // FIXME: Sign extend 1 to all ones if thats legal on the target. 1266 if (TLI.getOperationAction(ISD::AND, VT) == TargetLowering::Expand || 1267 TLI.getOperationAction(ISD::XOR, VT) == TargetLowering::Expand || 1268 TLI.getOperationAction(ISD::OR, VT) == TargetLowering::Expand || 1269 TLI.getBooleanContents(Op1.getValueType()) != 1270 TargetLowering::ZeroOrNegativeOneBooleanContent) 1271 return DAG.UnrollVectorOp(Node); 1272 1273 // If the mask and the type are different sizes, unroll the vector op. This 1274 // can occur when getSetCCResultType returns something that is different in 1275 // size from the operand types. For example, v4i8 = select v4i32, v4i8, v4i8. 1276 if (VT.getSizeInBits() != Op1.getValueSizeInBits()) 1277 return DAG.UnrollVectorOp(Node); 1278 1279 // Bitcast the operands to be the same type as the mask. 1280 // This is needed when we select between FP types because 1281 // the mask is a vector of integers. 1282 Op1 = DAG.getNode(ISD::BITCAST, DL, VT, Op1); 1283 Op2 = DAG.getNode(ISD::BITCAST, DL, VT, Op2); 1284 1285 SDValue AllOnes = DAG.getConstant( 1286 APInt::getAllOnesValue(VT.getScalarSizeInBits()), DL, VT); 1287 SDValue NotMask = DAG.getNode(ISD::XOR, DL, VT, Mask, AllOnes); 1288 1289 Op1 = DAG.getNode(ISD::AND, DL, VT, Op1, Mask); 1290 Op2 = DAG.getNode(ISD::AND, DL, VT, Op2, NotMask); 1291 SDValue Val = DAG.getNode(ISD::OR, DL, VT, Op1, Op2); 1292 return DAG.getNode(ISD::BITCAST, DL, Node->getValueType(0), Val); 1293 } 1294 1295 void VectorLegalizer::ExpandFP_TO_UINT(SDNode *Node, 1296 SmallVectorImpl<SDValue> &Results) { 1297 // Attempt to expand using TargetLowering. 1298 SDValue Result, Chain; 1299 if (TLI.expandFP_TO_UINT(Node, Result, Chain, DAG)) { 1300 Results.push_back(Result); 1301 if (Node->isStrictFPOpcode()) 1302 Results.push_back(Chain); 1303 return; 1304 } 1305 1306 // Otherwise go ahead and unroll. 1307 if (Node->isStrictFPOpcode()) { 1308 UnrollStrictFPOp(Node, Results); 1309 return; 1310 } 1311 1312 Results.push_back(DAG.UnrollVectorOp(Node)); 1313 } 1314 1315 void VectorLegalizer::ExpandUINT_TO_FLOAT(SDNode *Node, 1316 SmallVectorImpl<SDValue> &Results) { 1317 bool IsStrict = Node->isStrictFPOpcode(); 1318 unsigned OpNo = IsStrict ? 1 : 0; 1319 SDValue Src = Node->getOperand(OpNo); 1320 EVT VT = Src.getValueType(); 1321 SDLoc DL(Node); 1322 1323 // Attempt to expand using TargetLowering. 1324 SDValue Result; 1325 SDValue Chain; 1326 if (TLI.expandUINT_TO_FP(Node, Result, Chain, DAG)) { 1327 Results.push_back(Result); 1328 if (IsStrict) 1329 Results.push_back(Chain); 1330 return; 1331 } 1332 1333 // Make sure that the SINT_TO_FP and SRL instructions are available. 1334 if (((!IsStrict && TLI.getOperationAction(ISD::SINT_TO_FP, VT) == 1335 TargetLowering::Expand) || 1336 (IsStrict && TLI.getOperationAction(ISD::STRICT_SINT_TO_FP, VT) == 1337 TargetLowering::Expand)) || 1338 TLI.getOperationAction(ISD::SRL, VT) == TargetLowering::Expand) { 1339 if (IsStrict) { 1340 UnrollStrictFPOp(Node, Results); 1341 return; 1342 } 1343 1344 Results.push_back(DAG.UnrollVectorOp(Node)); 1345 return; 1346 } 1347 1348 unsigned BW = VT.getScalarSizeInBits(); 1349 assert((BW == 64 || BW == 32) && 1350 "Elements in vector-UINT_TO_FP must be 32 or 64 bits wide"); 1351 1352 SDValue HalfWord = DAG.getConstant(BW / 2, DL, VT); 1353 1354 // Constants to clear the upper part of the word. 1355 // Notice that we can also use SHL+SHR, but using a constant is slightly 1356 // faster on x86. 1357 uint64_t HWMask = (BW == 64) ? 0x00000000FFFFFFFF : 0x0000FFFF; 1358 SDValue HalfWordMask = DAG.getConstant(HWMask, DL, VT); 1359 1360 // Two to the power of half-word-size. 1361 SDValue TWOHW = 1362 DAG.getConstantFP(1ULL << (BW / 2), DL, Node->getValueType(0)); 1363 1364 // Clear upper part of LO, lower HI 1365 SDValue HI = DAG.getNode(ISD::SRL, DL, VT, Src, HalfWord); 1366 SDValue LO = DAG.getNode(ISD::AND, DL, VT, Src, HalfWordMask); 1367 1368 if (IsStrict) { 1369 // Convert hi and lo to floats 1370 // Convert the hi part back to the upper values 1371 // TODO: Can any fast-math-flags be set on these nodes? 1372 SDValue fHI = DAG.getNode(ISD::STRICT_SINT_TO_FP, DL, 1373 {Node->getValueType(0), MVT::Other}, 1374 {Node->getOperand(0), HI}); 1375 fHI = DAG.getNode(ISD::STRICT_FMUL, DL, {Node->getValueType(0), MVT::Other}, 1376 {fHI.getValue(1), fHI, TWOHW}); 1377 SDValue fLO = DAG.getNode(ISD::STRICT_SINT_TO_FP, DL, 1378 {Node->getValueType(0), MVT::Other}, 1379 {Node->getOperand(0), LO}); 1380 1381 SDValue TF = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, fHI.getValue(1), 1382 fLO.getValue(1)); 1383 1384 // Add the two halves 1385 SDValue Result = 1386 DAG.getNode(ISD::STRICT_FADD, DL, {Node->getValueType(0), MVT::Other}, 1387 {TF, fHI, fLO}); 1388 1389 Results.push_back(Result); 1390 Results.push_back(Result.getValue(1)); 1391 return; 1392 } 1393 1394 // Convert hi and lo to floats 1395 // Convert the hi part back to the upper values 1396 // TODO: Can any fast-math-flags be set on these nodes? 1397 SDValue fHI = DAG.getNode(ISD::SINT_TO_FP, DL, Node->getValueType(0), HI); 1398 fHI = DAG.getNode(ISD::FMUL, DL, Node->getValueType(0), fHI, TWOHW); 1399 SDValue fLO = DAG.getNode(ISD::SINT_TO_FP, DL, Node->getValueType(0), LO); 1400 1401 // Add the two halves 1402 Results.push_back( 1403 DAG.getNode(ISD::FADD, DL, Node->getValueType(0), fHI, fLO)); 1404 } 1405 1406 SDValue VectorLegalizer::ExpandFNEG(SDNode *Node) { 1407 if (TLI.isOperationLegalOrCustom(ISD::FSUB, Node->getValueType(0))) { 1408 SDLoc DL(Node); 1409 SDValue Zero = DAG.getConstantFP(-0.0, DL, Node->getValueType(0)); 1410 // TODO: If FNEG had fast-math-flags, they'd get propagated to this FSUB. 1411 return DAG.getNode(ISD::FSUB, DL, Node->getValueType(0), Zero, 1412 Node->getOperand(0)); 1413 } 1414 return DAG.UnrollVectorOp(Node); 1415 } 1416 1417 void VectorLegalizer::ExpandFSUB(SDNode *Node, 1418 SmallVectorImpl<SDValue> &Results) { 1419 // For floating-point values, (a-b) is the same as a+(-b). If FNEG is legal, 1420 // we can defer this to operation legalization where it will be lowered as 1421 // a+(-b). 1422 EVT VT = Node->getValueType(0); 1423 if (TLI.isOperationLegalOrCustom(ISD::FNEG, VT) && 1424 TLI.isOperationLegalOrCustom(ISD::FADD, VT)) 1425 return; // Defer to LegalizeDAG 1426 1427 SDValue Tmp = DAG.UnrollVectorOp(Node); 1428 Results.push_back(Tmp); 1429 } 1430 1431 void VectorLegalizer::ExpandUADDSUBO(SDNode *Node, 1432 SmallVectorImpl<SDValue> &Results) { 1433 SDValue Result, Overflow; 1434 TLI.expandUADDSUBO(Node, Result, Overflow, DAG); 1435 Results.push_back(Result); 1436 Results.push_back(Overflow); 1437 } 1438 1439 void VectorLegalizer::ExpandSADDSUBO(SDNode *Node, 1440 SmallVectorImpl<SDValue> &Results) { 1441 SDValue Result, Overflow; 1442 TLI.expandSADDSUBO(Node, Result, Overflow, DAG); 1443 Results.push_back(Result); 1444 Results.push_back(Overflow); 1445 } 1446 1447 void VectorLegalizer::ExpandMULO(SDNode *Node, 1448 SmallVectorImpl<SDValue> &Results) { 1449 SDValue Result, Overflow; 1450 if (!TLI.expandMULO(Node, Result, Overflow, DAG)) 1451 std::tie(Result, Overflow) = DAG.UnrollVectorOverflowOp(Node); 1452 1453 Results.push_back(Result); 1454 Results.push_back(Overflow); 1455 } 1456 1457 void VectorLegalizer::ExpandFixedPointDiv(SDNode *Node, 1458 SmallVectorImpl<SDValue> &Results) { 1459 SDNode *N = Node; 1460 if (SDValue Expanded = TLI.expandFixedPointDiv(N->getOpcode(), SDLoc(N), 1461 N->getOperand(0), N->getOperand(1), N->getConstantOperandVal(2), DAG)) 1462 Results.push_back(Expanded); 1463 } 1464 1465 void VectorLegalizer::ExpandStrictFPOp(SDNode *Node, 1466 SmallVectorImpl<SDValue> &Results) { 1467 if (Node->getOpcode() == ISD::STRICT_UINT_TO_FP) { 1468 ExpandUINT_TO_FLOAT(Node, Results); 1469 return; 1470 } 1471 if (Node->getOpcode() == ISD::STRICT_FP_TO_UINT) { 1472 ExpandFP_TO_UINT(Node, Results); 1473 return; 1474 } 1475 1476 UnrollStrictFPOp(Node, Results); 1477 } 1478 1479 void VectorLegalizer::UnrollStrictFPOp(SDNode *Node, 1480 SmallVectorImpl<SDValue> &Results) { 1481 EVT VT = Node->getValueType(0); 1482 EVT EltVT = VT.getVectorElementType(); 1483 unsigned NumElems = VT.getVectorNumElements(); 1484 unsigned NumOpers = Node->getNumOperands(); 1485 const TargetLowering &TLI = DAG.getTargetLoweringInfo(); 1486 1487 EVT TmpEltVT = EltVT; 1488 if (Node->getOpcode() == ISD::STRICT_FSETCC || 1489 Node->getOpcode() == ISD::STRICT_FSETCCS) 1490 TmpEltVT = TLI.getSetCCResultType(DAG.getDataLayout(), 1491 *DAG.getContext(), TmpEltVT); 1492 1493 EVT ValueVTs[] = {TmpEltVT, MVT::Other}; 1494 SDValue Chain = Node->getOperand(0); 1495 SDLoc dl(Node); 1496 1497 SmallVector<SDValue, 32> OpValues; 1498 SmallVector<SDValue, 32> OpChains; 1499 for (unsigned i = 0; i < NumElems; ++i) { 1500 SmallVector<SDValue, 4> Opers; 1501 SDValue Idx = DAG.getVectorIdxConstant(i, dl); 1502 1503 // The Chain is the first operand. 1504 Opers.push_back(Chain); 1505 1506 // Now process the remaining operands. 1507 for (unsigned j = 1; j < NumOpers; ++j) { 1508 SDValue Oper = Node->getOperand(j); 1509 EVT OperVT = Oper.getValueType(); 1510 1511 if (OperVT.isVector()) 1512 Oper = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, 1513 OperVT.getVectorElementType(), Oper, Idx); 1514 1515 Opers.push_back(Oper); 1516 } 1517 1518 SDValue ScalarOp = DAG.getNode(Node->getOpcode(), dl, ValueVTs, Opers); 1519 SDValue ScalarResult = ScalarOp.getValue(0); 1520 SDValue ScalarChain = ScalarOp.getValue(1); 1521 1522 if (Node->getOpcode() == ISD::STRICT_FSETCC || 1523 Node->getOpcode() == ISD::STRICT_FSETCCS) 1524 ScalarResult = DAG.getSelect(dl, EltVT, ScalarResult, 1525 DAG.getConstant(APInt::getAllOnesValue 1526 (EltVT.getSizeInBits()), dl, EltVT), 1527 DAG.getConstant(0, dl, EltVT)); 1528 1529 OpValues.push_back(ScalarResult); 1530 OpChains.push_back(ScalarChain); 1531 } 1532 1533 SDValue Result = DAG.getBuildVector(VT, dl, OpValues); 1534 SDValue NewChain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, OpChains); 1535 1536 Results.push_back(Result); 1537 Results.push_back(NewChain); 1538 } 1539 1540 SDValue VectorLegalizer::UnrollVSETCC(SDNode *Node) { 1541 EVT VT = Node->getValueType(0); 1542 unsigned NumElems = VT.getVectorNumElements(); 1543 EVT EltVT = VT.getVectorElementType(); 1544 SDValue LHS = Node->getOperand(0); 1545 SDValue RHS = Node->getOperand(1); 1546 SDValue CC = Node->getOperand(2); 1547 EVT TmpEltVT = LHS.getValueType().getVectorElementType(); 1548 SDLoc dl(Node); 1549 SmallVector<SDValue, 8> Ops(NumElems); 1550 for (unsigned i = 0; i < NumElems; ++i) { 1551 SDValue LHSElem = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, TmpEltVT, LHS, 1552 DAG.getVectorIdxConstant(i, dl)); 1553 SDValue RHSElem = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, TmpEltVT, RHS, 1554 DAG.getVectorIdxConstant(i, dl)); 1555 Ops[i] = DAG.getNode(ISD::SETCC, dl, 1556 TLI.getSetCCResultType(DAG.getDataLayout(), 1557 *DAG.getContext(), TmpEltVT), 1558 LHSElem, RHSElem, CC); 1559 Ops[i] = DAG.getSelect(dl, EltVT, Ops[i], 1560 DAG.getConstant(APInt::getAllOnesValue 1561 (EltVT.getSizeInBits()), dl, EltVT), 1562 DAG.getConstant(0, dl, EltVT)); 1563 } 1564 return DAG.getBuildVector(VT, dl, Ops); 1565 } 1566 1567 bool SelectionDAG::LegalizeVectors() { 1568 return VectorLegalizer(*this).Run(); 1569 } 1570