< prev index next >

src/hotspot/share/opto/vectornode.cpp

Print this page




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 #include "precompiled.hpp"
  25 #include "memory/allocation.inline.hpp"
  26 #include "opto/connode.hpp"

  27 #include "opto/vectornode.hpp"
  28 #include "utilities/powerOfTwo.hpp"
  29 
  30 //------------------------------VectorNode--------------------------------------
  31 
  32 // Return the vector operator for the specified scalar operation
  33 // and vector length.
  34 int VectorNode::opcode(int sopc, BasicType bt) {
  35   switch (sopc) {
  36   case Op_AddI:
  37     switch (bt) {
  38     case T_BOOLEAN:
  39     case T_BYTE:      return Op_AddVB;
  40     case T_CHAR:
  41     case T_SHORT:     return Op_AddVS;
  42     case T_INT:       return Op_AddVI;
  43     default:          ShouldNotReachHere(); return 0;
  44     }
  45   case Op_AddL:
  46     assert(bt == T_LONG, "must be");


 100     assert(bt == T_DOUBLE, "must be");
 101     return Op_CMoveVD;
 102   case Op_DivF:
 103     assert(bt == T_FLOAT, "must be");
 104     return Op_DivVF;
 105   case Op_DivD:
 106     assert(bt == T_DOUBLE, "must be");
 107     return Op_DivVD;
 108   case Op_AbsI:
 109     switch (bt) {
 110     case T_BOOLEAN:
 111     case T_CHAR:  return 0; // abs does not make sense for unsigned
 112     case T_BYTE:  return Op_AbsVB;
 113     case T_SHORT: return Op_AbsVS;
 114     case T_INT:   return Op_AbsVI;
 115     default: ShouldNotReachHere(); return 0;
 116     }
 117   case Op_AbsL:
 118     assert(bt == T_LONG, "must be");
 119     return Op_AbsVL;




































 120   case Op_AbsF:
 121     assert(bt == T_FLOAT, "must be");
 122     return Op_AbsVF;
 123   case Op_AbsD:
 124     assert(bt == T_DOUBLE, "must be");
 125     return Op_AbsVD;



 126   case Op_NegF:
 127     assert(bt == T_FLOAT, "must be");
 128     return Op_NegVF;
 129   case Op_NegD:
 130     assert(bt == T_DOUBLE, "must be");
 131     return Op_NegVD;
 132   case Op_RoundDoubleMode:
 133     assert(bt == T_DOUBLE, "must be");
 134     return Op_RoundDoubleModeV;
 135   case Op_SqrtF:
 136     assert(bt == T_FLOAT, "must be");
 137     return Op_SqrtVF;
 138   case Op_SqrtD:
 139     assert(bt == T_DOUBLE, "must be");
 140     return Op_SqrtVD;
 141   case Op_PopCountI:
 142     if (bt == T_INT) {
 143       return Op_PopCountVI;
 144     }
 145     // Unimplemented for subword types since bit count changes


 152     case T_CHAR:
 153     case T_SHORT:  return Op_LShiftVS;
 154     case T_INT:    return Op_LShiftVI;
 155       default:       ShouldNotReachHere(); return 0;
 156     }
 157   case Op_LShiftL:
 158     assert(bt == T_LONG, "must be");
 159     return Op_LShiftVL;
 160   case Op_RShiftI:
 161     switch (bt) {
 162     case T_BOOLEAN:return Op_URShiftVB; // boolean is unsigned value
 163     case T_CHAR:   return Op_URShiftVS; // char is unsigned value
 164     case T_BYTE:   return Op_RShiftVB;
 165     case T_SHORT:  return Op_RShiftVS;
 166     case T_INT:    return Op_RShiftVI;
 167     default:       ShouldNotReachHere(); return 0;
 168     }
 169   case Op_RShiftL:
 170     assert(bt == T_LONG, "must be");
 171     return Op_RShiftVL;






 172   case Op_URShiftI:
 173     switch (bt) {
 174     case T_BOOLEAN:return Op_URShiftVB;
 175     case T_CHAR:   return Op_URShiftVS;
 176     case T_BYTE:
 177     case T_SHORT:  return 0; // Vector logical right shift for signed short
 178                              // values produces incorrect Java result for
 179                              // negative data because java code should convert
 180                              // a short value into int value with sign
 181                              // extension before a shift.
 182     case T_INT:    return Op_URShiftVI;
 183     default:       ShouldNotReachHere(); return 0;
 184     }
 185   case Op_URShiftL:
 186     assert(bt == T_LONG, "must be");
 187     return Op_URShiftVL;
 188   case Op_AndI:
 189   case Op_AndL:
 190     return Op_AndV;
 191   case Op_OrI:
 192   case Op_OrL:
 193     return Op_OrV;
 194   case Op_XorI:
 195   case Op_XorL:
 196     return Op_XorV;
 197   case Op_MinF:
 198     assert(bt == T_FLOAT, "must be");
 199     return Op_MinV;
 200   case Op_MinD:
 201     assert(bt == T_DOUBLE, "must be");
 202     return Op_MinV;
 203   case Op_MaxF:
 204     assert(bt == T_FLOAT, "must be");
 205     return Op_MaxV;
 206   case Op_MaxD:
 207     assert(bt == T_DOUBLE, "must be");
 208     return Op_MaxV;
 209 
 210   case Op_LoadB:
 211   case Op_LoadUB:
 212   case Op_LoadUS:
 213   case Op_LoadS:
 214   case Op_LoadI:
 215   case Op_LoadL:
 216   case Op_LoadF:
 217   case Op_LoadD:
 218     return Op_LoadVector;
 219 
 220   case Op_StoreB:
 221   case Op_StoreC:
 222   case Op_StoreI:
 223   case Op_StoreL:
 224   case Op_StoreF:
 225   case Op_StoreD:
 226     return Op_StoreVector;
 227   case Op_MulAddS2I:
 228     return Op_MulAddVS2VI;
 229 
 230   default:
 231     return 0; // Unimplemented
 232   }
 233 }
 234 






















 235 // Also used to check if the code generator
 236 // supports the vector operation.
 237 bool VectorNode::implemented(int opc, uint vlen, BasicType bt) {
 238   if (is_java_primitive(bt) &&
 239       (vlen > 1) && is_power_of_2(vlen) &&
 240       Matcher::vector_size_supported(bt, vlen)) {
 241     int vopc = VectorNode::opcode(opc, bt);
 242     return vopc > 0 && Matcher::match_rule_supported_vector(vopc, vlen, bt);
 243   }
 244   return false;
 245 }
 246 
 247 bool VectorNode::is_type_transition_short_to_int(Node* n) {
 248   switch (n->Opcode()) {
 249   case Op_MulAddS2I:
 250     return true;
 251   }
 252   return false;
 253 }
 254 


 267   if (n->Opcode() == Op_RoundDoubleMode) {
 268     return true;
 269   }
 270   return false;
 271 }
 272 
 273 bool VectorNode::is_shift(Node* n) {
 274   switch (n->Opcode()) {
 275   case Op_LShiftI:
 276   case Op_LShiftL:
 277   case Op_RShiftI:
 278   case Op_RShiftL:
 279   case Op_URShiftI:
 280   case Op_URShiftL:
 281     return true;
 282   default:
 283     return false;
 284   }
 285 }
 286 










 287 // Check if input is loop invariant vector.
 288 bool VectorNode::is_invariant_vector(Node* n) {
 289   // Only Replicate vector nodes are loop invariant for now.
 290   switch (n->Opcode()) {
 291   case Op_ReplicateB:
 292   case Op_ReplicateS:
 293   case Op_ReplicateI:
 294   case Op_ReplicateL:
 295   case Op_ReplicateF:
 296   case Op_ReplicateD:
 297     return true;
 298   default:
 299     return false;
 300   }
 301 }
 302 
 303 // [Start, end) half-open range defining which operands are vectors
 304 void VectorNode::vector_operands(Node* n, uint* start, uint* end) {
 305   switch (n->Opcode()) {
 306   case Op_LoadB:   case Op_LoadUB:


 333   case Op_XorI: case Op_XorL:
 334   case Op_MulAddS2I:
 335     *start = 1;
 336     *end   = 3; // 2 vector operands
 337     break;
 338   case Op_CMoveI:  case Op_CMoveL:  case Op_CMoveF:  case Op_CMoveD:
 339     *start = 2;
 340     *end   = n->req();
 341     break;
 342   case Op_FmaD:
 343   case Op_FmaF:
 344     *start = 1;
 345     *end   = 4; // 3 vector operands
 346     break;
 347   default:
 348     *start = 1;
 349     *end   = n->req(); // default is all operands
 350   }
 351 }
 352 
 353 // Return the vector version of a scalar operation node.
 354 VectorNode* VectorNode::make(int opc, Node* n1, Node* n2, uint vlen, BasicType bt) {
 355   const TypeVect* vt = TypeVect::make(bt, vlen);
 356   int vopc = VectorNode::opcode(opc, bt);
 357   // This method should not be called for unimplemented vectors.
 358   guarantee(vopc > 0, "Vector for '%s' is not implemented", NodeClassNames[opc]);
 359   switch (vopc) {
 360   case Op_AddVB: return new AddVBNode(n1, n2, vt);
 361   case Op_AddVS: return new AddVSNode(n1, n2, vt);
 362   case Op_AddVI: return new AddVINode(n1, n2, vt);
 363   case Op_AddVL: return new AddVLNode(n1, n2, vt);
 364   case Op_AddVF: return new AddVFNode(n1, n2, vt);
 365   case Op_AddVD: return new AddVDNode(n1, n2, vt);
 366 
 367   case Op_SubVB: return new SubVBNode(n1, n2, vt);
 368   case Op_SubVS: return new SubVSNode(n1, n2, vt);
 369   case Op_SubVI: return new SubVINode(n1, n2, vt);
 370   case Op_SubVL: return new SubVLNode(n1, n2, vt);
 371   case Op_SubVF: return new SubVFNode(n1, n2, vt);
 372   case Op_SubVD: return new SubVDNode(n1, n2, vt);
 373 
 374   case Op_MulVB: return new MulVBNode(n1, n2, vt);
 375   case Op_MulVS: return new MulVSNode(n1, n2, vt);
 376   case Op_MulVI: return new MulVINode(n1, n2, vt);
 377   case Op_MulVL: return new MulVLNode(n1, n2, vt);
 378   case Op_MulVF: return new MulVFNode(n1, n2, vt);
 379   case Op_MulVD: return new MulVDNode(n1, n2, vt);
 380 
 381   case Op_DivVF: return new DivVFNode(n1, n2, vt);
 382   case Op_DivVD: return new DivVDNode(n1, n2, vt);
 383 





 384   case Op_AbsVB: return new AbsVBNode(n1, vt);
 385   case Op_AbsVS: return new AbsVSNode(n1, vt);
 386   case Op_AbsVI: return new AbsVINode(n1, vt);
 387   case Op_AbsVL: return new AbsVLNode(n1, vt);
 388   case Op_AbsVF: return new AbsVFNode(n1, vt);
 389   case Op_AbsVD: return new AbsVDNode(n1, vt);
 390 

 391   case Op_NegVF: return new NegVFNode(n1, vt);
 392   case Op_NegVD: return new NegVDNode(n1, vt);
 393 
 394   case Op_SqrtVF: return new SqrtVFNode(n1, vt);
 395   case Op_SqrtVD: return new SqrtVDNode(n1, vt);
 396 
 397   case Op_PopCountVI: return new PopCountVINode(n1, vt);
 398 
 399   case Op_LShiftVB: return new LShiftVBNode(n1, n2, vt);
 400   case Op_LShiftVS: return new LShiftVSNode(n1, n2, vt);
 401   case Op_LShiftVI: return new LShiftVINode(n1, n2, vt);
 402   case Op_LShiftVL: return new LShiftVLNode(n1, n2, vt);
 403 
 404   case Op_RShiftVB: return new RShiftVBNode(n1, n2, vt);
 405   case Op_RShiftVS: return new RShiftVSNode(n1, n2, vt);
 406   case Op_RShiftVI: return new RShiftVINode(n1, n2, vt);
 407   case Op_RShiftVL: return new RShiftVLNode(n1, n2, vt);
 408 
 409   case Op_URShiftVB: return new URShiftVBNode(n1, n2, vt);
 410   case Op_URShiftVS: return new URShiftVSNode(n1, n2, vt);
 411   case Op_URShiftVI: return new URShiftVINode(n1, n2, vt);
 412   case Op_URShiftVL: return new URShiftVLNode(n1, n2, vt);
 413 
 414   case Op_AndV: return new AndVNode(n1, n2, vt);
 415   case Op_OrV:  return new OrVNode (n1, n2, vt);
 416   case Op_XorV: return new XorVNode(n1, n2, vt);
 417 
 418   case Op_MinV: return new MinVNode(n1, n2, vt);
 419   case Op_MaxV: return new MaxVNode(n1, n2, vt);
 420 
 421   case Op_RoundDoubleModeV: return new RoundDoubleModeVNode(n1, n2, vt);
 422 
 423   case Op_MulAddVS2VI: return new MulAddVS2VINode(n1, n2, vt);
 424   default:
 425     fatal("Missed vector creation for '%s'", NodeClassNames[vopc]);
 426     return NULL;
 427   }
 428 }
 429 
 430 VectorNode* VectorNode::make(int opc, Node* n1, Node* n2, Node* n3, uint vlen, BasicType bt) {

 431   const TypeVect* vt = TypeVect::make(bt, vlen);
 432   int vopc = VectorNode::opcode(opc, bt);
 433   // This method should not be called for unimplemented vectors.
 434   guarantee(vopc > 0, "Vector for '%s' is not implemented", NodeClassNames[opc]);







 435   switch (vopc) {
 436   case Op_FmaVD: return new FmaVDNode(n1, n2, n3, vt);
 437   case Op_FmaVF: return new FmaVFNode(n1, n2, n3, vt);
 438   default:
 439     fatal("Missed vector creation for '%s'", NodeClassNames[vopc]);
 440     return NULL;
 441   }
 442 }
 443 









 444 // Scalar promotion
 445 VectorNode* VectorNode::scalar2vector(Node* s, uint vlen, const Type* opd_t) {
 446   BasicType bt = opd_t->array_element_basic_type();
 447   const TypeVect* vt = opd_t->singleton() ? TypeVect::make(opd_t, vlen)
 448                                           : TypeVect::make(bt, vlen);
 449   switch (bt) {
 450   case T_BOOLEAN:
 451   case T_BYTE:
 452     return new ReplicateBNode(s, vt);
 453   case T_CHAR:
 454   case T_SHORT:
 455     return new ReplicateSNode(s, vt);
 456   case T_INT:
 457     return new ReplicateINode(s, vt);
 458   case T_LONG:
 459     return new ReplicateLNode(s, vt);
 460   case T_FLOAT:
 461     return new ReplicateFNode(s, vt);
 462   case T_DOUBLE:
 463     return new ReplicateDNode(s, vt);
 464   default:
 465     fatal("Type '%s' is not supported for vectors", type2name(bt));
 466     return NULL;
 467   }
 468 }
 469 
 470 VectorNode* VectorNode::shift_count(Node* shift, Node* cnt, uint vlen, BasicType bt) {
 471   assert(VectorNode::is_shift(shift), "sanity");
 472   // Match shift count type with shift vector type.
 473   const TypeVect* vt = TypeVect::make(bt, vlen);
 474   switch (shift->Opcode()) {
 475   case Op_LShiftI:
 476   case Op_LShiftL:
 477     return new LShiftCntVNode(cnt, vt);
 478   case Op_RShiftI:
 479   case Op_RShiftL:


 480   case Op_URShiftI:
 481   case Op_URShiftL:
 482     return new RShiftCntVNode(cnt, vt);
 483   default:
 484     fatal("Missed vector creation for '%s'", NodeClassNames[shift->Opcode()]);
 485     return NULL;
 486   }
 487 }
 488 
 489 bool VectorNode::is_vector_shift(int opc) {
 490   assert(opc > _last_machine_leaf && opc < _last_opcode, "invalid opcode");
 491   switch (opc) {
 492   case Op_LShiftVB:
 493   case Op_LShiftVS:
 494   case Op_LShiftVI:
 495   case Op_LShiftVL:
 496   case Op_RShiftVB:
 497   case Op_RShiftVS:
 498   case Op_RShiftVI:
 499   case Op_RShiftVL:
 500   case Op_URShiftVB:
 501   case Op_URShiftVS:
 502   case Op_URShiftVI:
 503   case Op_URShiftVL:
 504     return true;


 611     }
 612   }
 613 }
 614 
 615 // Return the vector version of a scalar load node.
 616 LoadVectorNode* LoadVectorNode::make(int opc, Node* ctl, Node* mem,
 617                                      Node* adr, const TypePtr* atyp,
 618                                      uint vlen, BasicType bt,
 619                                      ControlDependency control_dependency) {
 620   const TypeVect* vt = TypeVect::make(bt, vlen);
 621   return new LoadVectorNode(ctl, mem, adr, atyp, vt, control_dependency);
 622 }
 623 
 624 // Return the vector version of a scalar store node.
 625 StoreVectorNode* StoreVectorNode::make(int opc, Node* ctl, Node* mem,
 626                                        Node* adr, const TypePtr* atyp, Node* val,
 627                                        uint vlen) {
 628   return new StoreVectorNode(ctl, mem, adr, atyp, val);
 629 }
 630 
















 631 // Extract a scalar element of vector.
 632 Node* ExtractNode::make(Node* v, uint position, BasicType bt) {
 633   assert((int)position < Matcher::max_vector_size(bt), "pos in range");
 634   ConINode* pos = ConINode::make((int)position);
 635   switch (bt) {
 636   case T_BOOLEAN:
 637     return new ExtractUBNode(v, pos);
 638   case T_BYTE:
 639     return new ExtractBNode(v, pos);
 640   case T_CHAR:
 641     return new ExtractCNode(v, pos);
 642   case T_SHORT:
 643     return new ExtractSNode(v, pos);
 644   case T_INT:
 645     return new ExtractINode(v, pos);
 646   case T_LONG:
 647     return new ExtractLNode(v, pos);
 648   case T_FLOAT:
 649     return new ExtractFNode(v, pos);
 650   case T_DOUBLE:
 651     return new ExtractDNode(v, pos);
 652   default:
 653     fatal("Type '%s' is not supported for vectors", type2name(bt));
 654     return NULL;
 655   }
 656 }
 657 
 658 int ReductionNode::opcode(int opc, BasicType bt) {
 659   int vopc = opc;
 660   switch (opc) {
 661     case Op_AddI:
 662       assert(bt == T_INT, "must be");





 663       vopc = Op_AddReductionVI;
 664       break;



 665     case Op_AddL:
 666       assert(bt == T_LONG, "must be");
 667       vopc = Op_AddReductionVL;
 668       break;
 669     case Op_AddF:
 670       assert(bt == T_FLOAT, "must be");
 671       vopc = Op_AddReductionVF;
 672       break;
 673     case Op_AddD:
 674       assert(bt == T_DOUBLE, "must be");
 675       vopc = Op_AddReductionVD;
 676       break;
 677     case Op_MulI:
 678       assert(bt == T_INT, "must be");





 679       vopc = Op_MulReductionVI;
 680       break;



 681     case Op_MulL:
 682       assert(bt == T_LONG, "must be");
 683       vopc = Op_MulReductionVL;
 684       break;
 685     case Op_MulF:
 686       assert(bt == T_FLOAT, "must be");
 687       vopc = Op_MulReductionVF;
 688       break;
 689     case Op_MulD:
 690       assert(bt == T_DOUBLE, "must be");
 691       vopc = Op_MulReductionVD;
 692       break;
















 693     case Op_MinF:
 694       assert(bt == T_FLOAT, "must be");
 695       vopc = Op_MinReductionV;
 696       break;
 697     case Op_MinD:
 698       assert(bt == T_DOUBLE, "must be");
 699       vopc = Op_MinReductionV;
 700       break;
















 701     case Op_MaxF:
 702       assert(bt == T_FLOAT, "must be");
 703       vopc = Op_MaxReductionV;
 704       break;
 705     case Op_MaxD:
 706       assert(bt == T_DOUBLE, "must be");
 707       vopc = Op_MaxReductionV;
 708       break;
 709     case Op_AndI:
 710       assert(bt == T_INT, "must be");





 711       vopc = Op_AndReductionV;
 712       break;



 713     case Op_AndL:
 714       assert(bt == T_LONG, "must be");
 715       vopc = Op_AndReductionV;
 716       break;
 717     case Op_OrI:
 718       assert(bt == T_INT, "must be");





 719       vopc = Op_OrReductionV;
 720       break;



 721     case Op_OrL:
 722       assert(bt == T_LONG, "must be");
 723       vopc = Op_OrReductionV;
 724       break;
 725     case Op_XorI:
 726       assert(bt == T_INT, "must be");





 727       vopc = Op_XorReductionV;
 728       break;



 729     case Op_XorL:
 730       assert(bt == T_LONG, "must be");
 731       vopc = Op_XorReductionV;
 732       break;
 733     default:
 734       break;
 735   }
 736   return vopc;
 737 }
 738 
 739 // Return the appropriate reduction node.
 740 ReductionNode* ReductionNode::make(int opc, Node *ctrl, Node* n1, Node* n2, BasicType bt) {
 741 
 742   int vopc = opcode(opc, bt);
 743 
 744   // This method should not be called for unimplemented vectors.
 745   guarantee(vopc != opc, "Vector for '%s' is not implemented", NodeClassNames[opc]);
 746 
 747   switch (vopc) {
 748   case Op_AddReductionVI: return new AddReductionVINode(ctrl, n1, n2);
 749   case Op_AddReductionVL: return new AddReductionVLNode(ctrl, n1, n2);
 750   case Op_AddReductionVF: return new AddReductionVFNode(ctrl, n1, n2);
 751   case Op_AddReductionVD: return new AddReductionVDNode(ctrl, n1, n2);
 752   case Op_MulReductionVI: return new MulReductionVINode(ctrl, n1, n2);
 753   case Op_MulReductionVL: return new MulReductionVLNode(ctrl, n1, n2);
 754   case Op_MulReductionVF: return new MulReductionVFNode(ctrl, n1, n2);
 755   case Op_MulReductionVD: return new MulReductionVDNode(ctrl, n1, n2);
 756   case Op_MinReductionV:  return new MinReductionVNode(ctrl, n1, n2);
 757   case Op_MaxReductionV:  return new MaxReductionVNode(ctrl, n1, n2);
 758   case Op_AndReductionV:  return new AndReductionVNode(ctrl, n1, n2);
 759   case Op_OrReductionV:   return new OrReductionVNode(ctrl, n1, n2);
 760   case Op_XorReductionV:  return new XorReductionVNode(ctrl, n1, n2);
 761   default:









































































































 762     fatal("Missed vector creation for '%s'", NodeClassNames[vopc]);
 763     return NULL;
 764   }
 765 }
 766 
 767 bool ReductionNode::implemented(int opc, uint vlen, BasicType bt) {
 768   if (is_java_primitive(bt) &&
 769       (vlen > 1) && is_power_of_2(vlen) &&
 770       Matcher::vector_size_supported(bt, vlen)) {
 771     int vopc = ReductionNode::opcode(opc, bt);
 772     return vopc != opc && Matcher::match_rule_supported(vopc);
 773   }
 774   return false;
 775 }
 776 
 777 MacroLogicVNode* MacroLogicVNode::make(PhaseGVN& gvn, Node* in1, Node* in2, Node* in3,
 778                                       uint truth_table, const TypeVect* vt) {
 779   assert(truth_table <= 0xFF, "invalid");
 780   assert(in1->bottom_type()->is_vect()->length_in_bytes() == vt->length_in_bytes(), "mismatch");
 781   assert(in2->bottom_type()->is_vect()->length_in_bytes() == vt->length_in_bytes(), "mismatch");
 782   assert(in3->bottom_type()->is_vect()->length_in_bytes() == vt->length_in_bytes(), "mismatch");
 783   Node* fn = gvn.intcon(truth_table);
 784   return new MacroLogicVNode(in1, in2, in3, fn, vt);
 785 }
 786 


















































   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 #include "precompiled.hpp"
  25 #include "memory/allocation.inline.hpp"
  26 #include "opto/connode.hpp"
  27 #include "opto/subnode.hpp"
  28 #include "opto/vectornode.hpp"
  29 #include "utilities/powerOfTwo.hpp"
  30 
  31 //------------------------------VectorNode--------------------------------------
  32 
  33 // Return the vector operator for the specified scalar operation
  34 // and vector length.
  35 int VectorNode::opcode(int sopc, BasicType bt) {
  36   switch (sopc) {
  37   case Op_AddI:
  38     switch (bt) {
  39     case T_BOOLEAN:
  40     case T_BYTE:      return Op_AddVB;
  41     case T_CHAR:
  42     case T_SHORT:     return Op_AddVS;
  43     case T_INT:       return Op_AddVI;
  44     default:          ShouldNotReachHere(); return 0;
  45     }
  46   case Op_AddL:
  47     assert(bt == T_LONG, "must be");


 101     assert(bt == T_DOUBLE, "must be");
 102     return Op_CMoveVD;
 103   case Op_DivF:
 104     assert(bt == T_FLOAT, "must be");
 105     return Op_DivVF;
 106   case Op_DivD:
 107     assert(bt == T_DOUBLE, "must be");
 108     return Op_DivVD;
 109   case Op_AbsI:
 110     switch (bt) {
 111     case T_BOOLEAN:
 112     case T_CHAR:  return 0; // abs does not make sense for unsigned
 113     case T_BYTE:  return Op_AbsVB;
 114     case T_SHORT: return Op_AbsVS;
 115     case T_INT:   return Op_AbsVI;
 116     default: ShouldNotReachHere(); return 0;
 117     }
 118   case Op_AbsL:
 119     assert(bt == T_LONG, "must be");
 120     return Op_AbsVL;
 121   case Op_MinI:
 122     switch (bt) {
 123     case T_BOOLEAN:
 124     case T_CHAR:   return 0;
 125     case T_BYTE:
 126     case T_SHORT:
 127     case T_INT:    return Op_MinV;
 128     default:       ShouldNotReachHere(); return 0;
 129     }
 130   case Op_MinL:
 131     assert(bt == T_LONG, "must be");
 132     return Op_MinV;
 133   case Op_MinF:
 134     assert(bt == T_FLOAT, "must be");
 135     return Op_MinV;
 136   case Op_MinD:
 137     assert(bt == T_DOUBLE, "must be");
 138     return Op_MinV;
 139   case Op_MaxI:
 140     switch (bt) {
 141     case T_BOOLEAN:
 142     case T_CHAR:   return 0;
 143     case T_BYTE:
 144     case T_SHORT:
 145     case T_INT:    return Op_MaxV;
 146     default:       ShouldNotReachHere(); return 0;
 147     }
 148   case Op_MaxL:
 149     assert(bt == T_LONG, "must be");
 150     return Op_MaxV;
 151   case Op_MaxF:
 152     assert(bt == T_FLOAT, "must be");
 153     return Op_MaxV;
 154   case Op_MaxD:
 155     assert(bt == T_DOUBLE, "must be");
 156     return Op_MaxV;
 157   case Op_AbsF:
 158     assert(bt == T_FLOAT, "must be");
 159     return Op_AbsVF;
 160   case Op_AbsD:
 161     assert(bt == T_DOUBLE, "must be");
 162     return Op_AbsVD;
 163   case Op_NegI:
 164     assert(bt == T_INT, "must be");
 165     return Op_NegVI;
 166   case Op_NegF:
 167     assert(bt == T_FLOAT, "must be");
 168     return Op_NegVF;
 169   case Op_NegD:
 170     assert(bt == T_DOUBLE, "must be");
 171     return Op_NegVD;
 172   case Op_RoundDoubleMode:
 173     assert(bt == T_DOUBLE, "must be");
 174     return Op_RoundDoubleModeV;
 175   case Op_SqrtF:
 176     assert(bt == T_FLOAT, "must be");
 177     return Op_SqrtVF;
 178   case Op_SqrtD:
 179     assert(bt == T_DOUBLE, "must be");
 180     return Op_SqrtVD;
 181   case Op_PopCountI:
 182     if (bt == T_INT) {
 183       return Op_PopCountVI;
 184     }
 185     // Unimplemented for subword types since bit count changes


 192     case T_CHAR:
 193     case T_SHORT:  return Op_LShiftVS;
 194     case T_INT:    return Op_LShiftVI;
 195       default:       ShouldNotReachHere(); return 0;
 196     }
 197   case Op_LShiftL:
 198     assert(bt == T_LONG, "must be");
 199     return Op_LShiftVL;
 200   case Op_RShiftI:
 201     switch (bt) {
 202     case T_BOOLEAN:return Op_URShiftVB; // boolean is unsigned value
 203     case T_CHAR:   return Op_URShiftVS; // char is unsigned value
 204     case T_BYTE:   return Op_RShiftVB;
 205     case T_SHORT:  return Op_RShiftVS;
 206     case T_INT:    return Op_RShiftVI;
 207     default:       ShouldNotReachHere(); return 0;
 208     }
 209   case Op_RShiftL:
 210     assert(bt == T_LONG, "must be");
 211     return Op_RShiftVL;
 212   case Op_URShiftB:
 213     assert(bt == T_BYTE, "must be");
 214     return Op_URShiftVB;
 215   case Op_URShiftS:
 216     assert(bt == T_SHORT, "must be");
 217     return Op_URShiftVS;
 218   case Op_URShiftI:
 219     switch (bt) {
 220     case T_BOOLEAN:return Op_URShiftVB;
 221     case T_CHAR:   return Op_URShiftVS;
 222     case T_BYTE:
 223     case T_SHORT:  return 0; // Vector logical right shift for signed short
 224                              // values produces incorrect Java result for
 225                              // negative data because java code should convert
 226                              // a short value into int value with sign
 227                              // extension before a shift.
 228     case T_INT:    return Op_URShiftVI;
 229     default:       ShouldNotReachHere(); return 0;
 230     }
 231   case Op_URShiftL:
 232     assert(bt == T_LONG, "must be");
 233     return Op_URShiftVL;
 234   case Op_AndI:
 235   case Op_AndL:
 236     return Op_AndV;
 237   case Op_OrI:
 238   case Op_OrL:
 239     return Op_OrV;
 240   case Op_XorI:
 241   case Op_XorL:
 242     return Op_XorV;












 243 
 244   case Op_LoadB:
 245   case Op_LoadUB:
 246   case Op_LoadUS:
 247   case Op_LoadS:
 248   case Op_LoadI:
 249   case Op_LoadL:
 250   case Op_LoadF:
 251   case Op_LoadD:
 252     return Op_LoadVector;
 253 
 254   case Op_StoreB:
 255   case Op_StoreC:
 256   case Op_StoreI:
 257   case Op_StoreL:
 258   case Op_StoreF:
 259   case Op_StoreD:
 260     return Op_StoreVector;
 261   case Op_MulAddS2I:
 262     return Op_MulAddVS2VI;
 263 
 264   default:
 265     return 0; // Unimplemented
 266   }
 267 }
 268 
 269 int VectorNode::replicate_opcode(BasicType bt) {
 270   switch(bt) {
 271     case T_BOOLEAN:
 272     case T_BYTE:
 273       return Op_ReplicateB;
 274     case T_SHORT:
 275     case T_CHAR:
 276       return Op_ReplicateS;
 277     case T_INT:
 278       return Op_ReplicateI;
 279     case T_LONG:
 280       return Op_ReplicateL;
 281     case T_FLOAT:
 282       return Op_ReplicateF;
 283     case T_DOUBLE:
 284       return Op_ReplicateD;
 285     default:
 286       assert(false, "wrong type: %s", type2name(bt));
 287       return 0;
 288   }
 289 }
 290 
 291 // Also used to check if the code generator
 292 // supports the vector operation.
 293 bool VectorNode::implemented(int opc, uint vlen, BasicType bt) {
 294   if (is_java_primitive(bt) &&
 295       (vlen > 1) && is_power_of_2(vlen) &&
 296       Matcher::vector_size_supported(bt, vlen)) {
 297     int vopc = VectorNode::opcode(opc, bt);
 298     return vopc > 0 && Matcher::match_rule_supported_vector(vopc, vlen, bt);
 299   }
 300   return false;
 301 }
 302 
 303 bool VectorNode::is_type_transition_short_to_int(Node* n) {
 304   switch (n->Opcode()) {
 305   case Op_MulAddS2I:
 306     return true;
 307   }
 308   return false;
 309 }
 310 


 323   if (n->Opcode() == Op_RoundDoubleMode) {
 324     return true;
 325   }
 326   return false;
 327 }
 328 
 329 bool VectorNode::is_shift(Node* n) {
 330   switch (n->Opcode()) {
 331   case Op_LShiftI:
 332   case Op_LShiftL:
 333   case Op_RShiftI:
 334   case Op_RShiftL:
 335   case Op_URShiftI:
 336   case Op_URShiftL:
 337     return true;
 338   default:
 339     return false;
 340   }
 341 }
 342 
 343 bool VectorNode::is_vshift_cnt(Node* n) {
 344   switch (n->Opcode()) {
 345   case Op_LShiftCntV:
 346   case Op_RShiftCntV:
 347     return true;
 348   default:
 349     return false;
 350   }
 351 }
 352 
 353 // Check if input is loop invariant vector.
 354 bool VectorNode::is_invariant_vector(Node* n) {
 355   // Only Replicate vector nodes are loop invariant for now.
 356   switch (n->Opcode()) {
 357   case Op_ReplicateB:
 358   case Op_ReplicateS:
 359   case Op_ReplicateI:
 360   case Op_ReplicateL:
 361   case Op_ReplicateF:
 362   case Op_ReplicateD:
 363     return true;
 364   default:
 365     return false;
 366   }
 367 }
 368 
 369 // [Start, end) half-open range defining which operands are vectors
 370 void VectorNode::vector_operands(Node* n, uint* start, uint* end) {
 371   switch (n->Opcode()) {
 372   case Op_LoadB:   case Op_LoadUB:


 399   case Op_XorI: case Op_XorL:
 400   case Op_MulAddS2I:
 401     *start = 1;
 402     *end   = 3; // 2 vector operands
 403     break;
 404   case Op_CMoveI:  case Op_CMoveL:  case Op_CMoveF:  case Op_CMoveD:
 405     *start = 2;
 406     *end   = n->req();
 407     break;
 408   case Op_FmaD:
 409   case Op_FmaF:
 410     *start = 1;
 411     *end   = 4; // 3 vector operands
 412     break;
 413   default:
 414     *start = 1;
 415     *end   = n->req(); // default is all operands
 416   }
 417 }
 418 
 419 // Make a vector node for binary operation
 420 VectorNode* VectorNode::make(int vopc, Node* n1, Node* n2, const TypeVect* vt) {


 421   // This method should not be called for unimplemented vectors.
 422   guarantee(vopc > 0, "vopc must be > 0");
 423   switch (vopc) {
 424   case Op_AddVB: return new AddVBNode(n1, n2, vt);
 425   case Op_AddVS: return new AddVSNode(n1, n2, vt);
 426   case Op_AddVI: return new AddVINode(n1, n2, vt);
 427   case Op_AddVL: return new AddVLNode(n1, n2, vt);
 428   case Op_AddVF: return new AddVFNode(n1, n2, vt);
 429   case Op_AddVD: return new AddVDNode(n1, n2, vt);
 430 
 431   case Op_SubVB: return new SubVBNode(n1, n2, vt);
 432   case Op_SubVS: return new SubVSNode(n1, n2, vt);
 433   case Op_SubVI: return new SubVINode(n1, n2, vt);
 434   case Op_SubVL: return new SubVLNode(n1, n2, vt);
 435   case Op_SubVF: return new SubVFNode(n1, n2, vt);
 436   case Op_SubVD: return new SubVDNode(n1, n2, vt);
 437 
 438   case Op_MulVB: return new MulVBNode(n1, n2, vt);
 439   case Op_MulVS: return new MulVSNode(n1, n2, vt);
 440   case Op_MulVI: return new MulVINode(n1, n2, vt);
 441   case Op_MulVL: return new MulVLNode(n1, n2, vt);
 442   case Op_MulVF: return new MulVFNode(n1, n2, vt);
 443   case Op_MulVD: return new MulVDNode(n1, n2, vt);
 444 
 445   case Op_DivVF: return new DivVFNode(n1, n2, vt);
 446   case Op_DivVD: return new DivVDNode(n1, n2, vt);
 447 
 448   case Op_MinV: return new MinVNode(n1, n2, vt);
 449   case Op_MaxV: return new MaxVNode(n1, n2, vt);
 450 
 451   case Op_AbsVF: return new AbsVFNode(n1, vt);
 452   case Op_AbsVD: return new AbsVDNode(n1, vt);
 453   case Op_AbsVB: return new AbsVBNode(n1, vt);
 454   case Op_AbsVS: return new AbsVSNode(n1, vt);
 455   case Op_AbsVI: return new AbsVINode(n1, vt);
 456   case Op_AbsVL: return new AbsVLNode(n1, vt);


 457 
 458   case Op_NegVI: return new NegVINode(n1, vt);
 459   case Op_NegVF: return new NegVFNode(n1, vt);
 460   case Op_NegVD: return new NegVDNode(n1, vt);
 461 
 462   case Op_SqrtVF: return new SqrtVFNode(n1, vt);
 463   case Op_SqrtVD: return new SqrtVDNode(n1, vt);
 464 
 465   case Op_PopCountVI: return new PopCountVINode(n1, vt);
 466 
 467   case Op_LShiftVB: return new LShiftVBNode(n1, n2, vt);
 468   case Op_LShiftVS: return new LShiftVSNode(n1, n2, vt);
 469   case Op_LShiftVI: return new LShiftVINode(n1, n2, vt);
 470   case Op_LShiftVL: return new LShiftVLNode(n1, n2, vt);
 471 
 472   case Op_RShiftVB: return new RShiftVBNode(n1, n2, vt);
 473   case Op_RShiftVS: return new RShiftVSNode(n1, n2, vt);
 474   case Op_RShiftVI: return new RShiftVINode(n1, n2, vt);
 475   case Op_RShiftVL: return new RShiftVLNode(n1, n2, vt);
 476 
 477   case Op_URShiftVB: return new URShiftVBNode(n1, n2, vt);
 478   case Op_URShiftVS: return new URShiftVSNode(n1, n2, vt);
 479   case Op_URShiftVI: return new URShiftVINode(n1, n2, vt);
 480   case Op_URShiftVL: return new URShiftVLNode(n1, n2, vt);
 481 
 482   case Op_AndV: return new AndVNode(n1, n2, vt);
 483   case Op_OrV:  return new OrVNode (n1, n2, vt);
 484   case Op_XorV: return new XorVNode(n1, n2, vt);
 485 



 486   case Op_RoundDoubleModeV: return new RoundDoubleModeVNode(n1, n2, vt);
 487 
 488   case Op_MulAddVS2VI: return new MulAddVS2VINode(n1, n2, vt);
 489   default:
 490     fatal("Missed vector creation for '%s'", NodeClassNames[vopc]);
 491     return NULL;
 492   }
 493 }
 494 
 495 // Return the vector version of a scalar binary operation node.
 496 VectorNode* VectorNode::make(int opc, Node* n1, Node* n2, uint vlen, BasicType bt) {
 497   const TypeVect* vt = TypeVect::make(bt, vlen);
 498   int vopc = VectorNode::opcode(opc, bt);
 499   // This method should not be called for unimplemented vectors.
 500   guarantee(vopc > 0, "Vector for '%s' is not implemented", NodeClassNames[opc]);
 501   return make(vopc, n1, n2, vt);
 502 }
 503 
 504 // Make a vector node for ternary operation
 505 VectorNode* VectorNode::make(int vopc, Node* n1, Node* n2, Node* n3, const TypeVect* vt) {
 506   // This method should not be called for unimplemented vectors.
 507   guarantee(vopc > 0, "vopc must be > 0");
 508   switch (vopc) {
 509   case Op_FmaVD: return new FmaVDNode(n1, n2, n3, vt);
 510   case Op_FmaVF: return new FmaVFNode(n1, n2, n3, vt);
 511   default:
 512     fatal("Missed vector creation for '%s'", NodeClassNames[vopc]);
 513     return NULL;
 514   }
 515 }
 516 
 517 // Return the vector version of a scalar ternary operation node.
 518 VectorNode* VectorNode::make(int opc, Node* n1, Node* n2, Node* n3, uint vlen, BasicType bt) {
 519   const TypeVect* vt = TypeVect::make(bt, vlen);
 520   int vopc = VectorNode::opcode(opc, bt);
 521   // This method should not be called for unimplemented vectors.
 522   guarantee(vopc > 0, "Vector for '%s' is not implemented", NodeClassNames[opc]);
 523   return make(vopc, n1, n2, n3, vt);
 524 }
 525 
 526 // Scalar promotion
 527 VectorNode* VectorNode::scalar2vector(Node* s, uint vlen, const Type* opd_t) {
 528   BasicType bt = opd_t->array_element_basic_type();
 529   const TypeVect* vt = opd_t->singleton() ? TypeVect::make(opd_t, vlen)
 530                                           : TypeVect::make(bt, vlen);
 531   switch (bt) {
 532   case T_BOOLEAN:
 533   case T_BYTE:
 534     return new ReplicateBNode(s, vt);
 535   case T_CHAR:
 536   case T_SHORT:
 537     return new ReplicateSNode(s, vt);
 538   case T_INT:
 539     return new ReplicateINode(s, vt);
 540   case T_LONG:
 541     return new ReplicateLNode(s, vt);
 542   case T_FLOAT:
 543     return new ReplicateFNode(s, vt);
 544   case T_DOUBLE:
 545     return new ReplicateDNode(s, vt);
 546   default:
 547     fatal("Type '%s' is not supported for vectors", type2name(bt));
 548     return NULL;
 549   }
 550 }
 551 
 552 VectorNode* VectorNode::shift_count(int opc, Node* cnt, uint vlen, BasicType bt) {

 553   // Match shift count type with shift vector type.
 554   const TypeVect* vt = TypeVect::make(bt, vlen);
 555   switch (opc) {
 556   case Op_LShiftI:
 557   case Op_LShiftL:
 558     return new LShiftCntVNode(cnt, vt);
 559   case Op_RShiftI:
 560   case Op_RShiftL:
 561   case Op_URShiftB:
 562   case Op_URShiftS:
 563   case Op_URShiftI:
 564   case Op_URShiftL:
 565     return new RShiftCntVNode(cnt, vt);
 566   default:
 567     fatal("Missed vector creation for '%s'", NodeClassNames[opc]);
 568     return NULL;
 569   }
 570 }
 571 
 572 bool VectorNode::is_vector_shift(int opc) {
 573   assert(opc > _last_machine_leaf && opc < _last_opcode, "invalid opcode");
 574   switch (opc) {
 575   case Op_LShiftVB:
 576   case Op_LShiftVS:
 577   case Op_LShiftVI:
 578   case Op_LShiftVL:
 579   case Op_RShiftVB:
 580   case Op_RShiftVS:
 581   case Op_RShiftVI:
 582   case Op_RShiftVL:
 583   case Op_URShiftVB:
 584   case Op_URShiftVS:
 585   case Op_URShiftVI:
 586   case Op_URShiftVL:
 587     return true;


 694     }
 695   }
 696 }
 697 
 698 // Return the vector version of a scalar load node.
 699 LoadVectorNode* LoadVectorNode::make(int opc, Node* ctl, Node* mem,
 700                                      Node* adr, const TypePtr* atyp,
 701                                      uint vlen, BasicType bt,
 702                                      ControlDependency control_dependency) {
 703   const TypeVect* vt = TypeVect::make(bt, vlen);
 704   return new LoadVectorNode(ctl, mem, adr, atyp, vt, control_dependency);
 705 }
 706 
 707 // Return the vector version of a scalar store node.
 708 StoreVectorNode* StoreVectorNode::make(int opc, Node* ctl, Node* mem,
 709                                        Node* adr, const TypePtr* atyp, Node* val,
 710                                        uint vlen) {
 711   return new StoreVectorNode(ctl, mem, adr, atyp, val);
 712 }
 713 
 714 int ExtractNode::opcode(BasicType bt) {
 715   switch (bt) {
 716     case T_BOOLEAN: return Op_ExtractUB;
 717     case T_BYTE:    return Op_ExtractB;
 718     case T_CHAR:    return Op_ExtractC;
 719     case T_SHORT:   return Op_ExtractS;
 720     case T_INT:     return Op_ExtractI;
 721     case T_LONG:    return Op_ExtractL;
 722     case T_FLOAT:   return Op_ExtractF;
 723     case T_DOUBLE:  return Op_ExtractD;
 724     default:
 725       assert(false, "wrong type: %s", type2name(bt));
 726       return 0;
 727   }
 728 }
 729 
 730 // Extract a scalar element of vector.
 731 Node* ExtractNode::make(Node* v, uint position, BasicType bt) {
 732   assert((int)position < Matcher::max_vector_size(bt), "pos in range");
 733   ConINode* pos = ConINode::make((int)position);
 734   switch (bt) {
 735   case T_BOOLEAN: return new ExtractUBNode(v, pos);
 736   case T_BYTE:    return new ExtractBNode(v, pos);
 737   case T_CHAR:    return new ExtractCNode(v, pos);
 738   case T_SHORT:   return new ExtractSNode(v, pos);
 739   case T_INT:     return new ExtractINode(v, pos);
 740   case T_LONG:    return new ExtractLNode(v, pos);
 741   case T_FLOAT:   return new ExtractFNode(v, pos);
 742   case T_DOUBLE:  return new ExtractDNode(v, pos);








 743   default:
 744     assert(false, "wrong type: %s", type2name(bt));
 745     return NULL;
 746   }
 747 }
 748 
 749 int ReductionNode::opcode(int opc, BasicType bt) {
 750   int vopc = opc;
 751   switch (opc) {
 752     case Op_AddI:
 753       switch (bt) {
 754         case T_BOOLEAN:
 755         case T_CHAR: return 0;
 756         case T_BYTE:
 757         case T_SHORT:
 758         case T_INT:
 759           vopc = Op_AddReductionVI;
 760           break;
 761         default: ShouldNotReachHere(); return 0;
 762       }
 763       break;
 764     case Op_AddL:
 765       assert(bt == T_LONG, "must be");
 766       vopc = Op_AddReductionVL;
 767       break;
 768     case Op_AddF:
 769       assert(bt == T_FLOAT, "must be");
 770       vopc = Op_AddReductionVF;
 771       break;
 772     case Op_AddD:
 773       assert(bt == T_DOUBLE, "must be");
 774       vopc = Op_AddReductionVD;
 775       break;
 776     case Op_MulI:
 777       switch (bt) {
 778         case T_BOOLEAN:
 779         case T_CHAR: return 0;
 780         case T_BYTE:
 781         case T_SHORT:
 782         case T_INT:
 783           vopc = Op_MulReductionVI;
 784           break;
 785         default: ShouldNotReachHere(); return 0;
 786       }
 787       break;
 788     case Op_MulL:
 789       assert(bt == T_LONG, "must be");
 790       vopc = Op_MulReductionVL;
 791       break;
 792     case Op_MulF:
 793       assert(bt == T_FLOAT, "must be");
 794       vopc = Op_MulReductionVF;
 795       break;
 796     case Op_MulD:
 797       assert(bt == T_DOUBLE, "must be");
 798       vopc = Op_MulReductionVD;
 799       break;
 800     case Op_MinI:
 801       switch (bt) {
 802         case T_BOOLEAN:
 803         case T_CHAR: return 0;
 804         case T_BYTE:
 805         case T_SHORT:
 806         case T_INT:
 807           vopc = Op_MinReductionV;
 808           break;
 809         default: ShouldNotReachHere(); return 0;
 810       }
 811       break;
 812     case Op_MinL:
 813       assert(bt == T_LONG, "must be");
 814       vopc = Op_MinReductionV;
 815       break;
 816     case Op_MinF:
 817       assert(bt == T_FLOAT, "must be");
 818       vopc = Op_MinReductionV;
 819       break;
 820     case Op_MinD:
 821       assert(bt == T_DOUBLE, "must be");
 822       vopc = Op_MinReductionV;
 823       break;
 824     case Op_MaxI:
 825       switch (bt) {
 826         case T_BOOLEAN:
 827         case T_CHAR: return 0;
 828         case T_BYTE:
 829         case T_SHORT:
 830         case T_INT:
 831           vopc = Op_MaxReductionV;
 832           break;
 833         default: ShouldNotReachHere(); return 0;
 834       }
 835       break;
 836     case Op_MaxL:
 837       assert(bt == T_LONG, "must be");
 838       vopc = Op_MaxReductionV;
 839       break;
 840     case Op_MaxF:
 841       assert(bt == T_FLOAT, "must be");
 842       vopc = Op_MaxReductionV;
 843       break;
 844     case Op_MaxD:
 845       assert(bt == T_DOUBLE, "must be");
 846       vopc = Op_MaxReductionV;
 847       break;
 848     case Op_AndI:
 849       switch (bt) {
 850       case T_BOOLEAN:
 851       case T_CHAR: return 0;
 852       case T_BYTE:
 853       case T_SHORT:
 854       case T_INT:
 855         vopc = Op_AndReductionV;
 856         break;
 857       default: ShouldNotReachHere(); return 0;
 858       }
 859       break;
 860     case Op_AndL:
 861       assert(bt == T_LONG, "must be");
 862       vopc = Op_AndReductionV;
 863       break;
 864     case Op_OrI:
 865       switch(bt) {
 866       case T_BOOLEAN:
 867       case T_CHAR: return 0;
 868       case T_BYTE:
 869       case T_SHORT:
 870       case T_INT:
 871         vopc = Op_OrReductionV;
 872         break;
 873       default: ShouldNotReachHere(); return 0;
 874       }
 875       break;
 876     case Op_OrL:
 877       assert(bt == T_LONG, "must be");
 878       vopc = Op_OrReductionV;
 879       break;
 880     case Op_XorI:
 881       switch(bt) {
 882       case T_BOOLEAN:
 883       case T_CHAR: return 0;
 884       case T_BYTE:
 885       case T_SHORT:
 886       case T_INT:
 887         vopc = Op_XorReductionV;
 888         break;
 889       default: ShouldNotReachHere(); return 0;
 890       }
 891       break;
 892     case Op_XorL:
 893       assert(bt == T_LONG, "must be");
 894       vopc = Op_XorReductionV;
 895       break;
 896     default:
 897       break;
 898   }
 899   return vopc;
 900 }
 901 
 902 // Return the appropriate reduction node.
 903 ReductionNode* ReductionNode::make(int opc, Node *ctrl, Node* n1, Node* n2, BasicType bt) {
 904 
 905   int vopc = opcode(opc, bt);
 906 
 907   // This method should not be called for unimplemented vectors.
 908   guarantee(vopc != opc, "Vector for '%s' is not implemented", NodeClassNames[opc]);
 909 
 910   switch (vopc) {
 911   case Op_AddReductionVI: return new AddReductionVINode(ctrl, n1, n2);
 912   case Op_AddReductionVL: return new AddReductionVLNode(ctrl, n1, n2);
 913   case Op_AddReductionVF: return new AddReductionVFNode(ctrl, n1, n2);
 914   case Op_AddReductionVD: return new AddReductionVDNode(ctrl, n1, n2);
 915   case Op_MulReductionVI: return new MulReductionVINode(ctrl, n1, n2);
 916   case Op_MulReductionVL: return new MulReductionVLNode(ctrl, n1, n2);
 917   case Op_MulReductionVF: return new MulReductionVFNode(ctrl, n1, n2);
 918   case Op_MulReductionVD: return new MulReductionVDNode(ctrl, n1, n2);
 919   case Op_MinReductionV:  return new MinReductionVNode(ctrl, n1, n2);
 920   case Op_MaxReductionV:  return new MaxReductionVNode(ctrl, n1, n2);
 921   case Op_AndReductionV:  return new AndReductionVNode(ctrl, n1, n2);
 922   case Op_OrReductionV:   return new OrReductionVNode(ctrl, n1, n2);
 923   case Op_XorReductionV:  return new XorReductionVNode(ctrl, n1, n2);
 924   default:
 925     assert(false, "unknown node: %s", NodeClassNames[vopc]);
 926     return NULL;
 927   }
 928 }
 929 
 930 VectorStoreMaskNode* VectorStoreMaskNode::make(PhaseGVN& gvn, Node* in, BasicType in_type, uint num_elem) {
 931   assert(in->bottom_type()->isa_vect(), "sanity");
 932   const TypeVect* vt = TypeVect::make(T_BOOLEAN, num_elem);
 933   int elem_size = type2aelembytes(in_type);
 934   return new VectorStoreMaskNode(in, gvn.intcon(elem_size), vt);
 935 }
 936 
 937 VectorCastNode* VectorCastNode::make(int vopc, Node* n1, BasicType bt, uint vlen) {
 938   const TypeVect* vt = TypeVect::make(bt, vlen);
 939   switch (vopc) {
 940     case Op_VectorCastB2X: return new VectorCastB2XNode(n1, vt);
 941     case Op_VectorCastS2X: return new VectorCastS2XNode(n1, vt);
 942     case Op_VectorCastI2X: return new VectorCastI2XNode(n1, vt);
 943     case Op_VectorCastL2X: return new VectorCastL2XNode(n1, vt);
 944     case Op_VectorCastF2X: return new VectorCastF2XNode(n1, vt);
 945     case Op_VectorCastD2X: return new VectorCastD2XNode(n1, vt);
 946     default:
 947       assert(false, "unknown node: %s", NodeClassNames[vopc]);
 948       return NULL;
 949   }
 950 }
 951 
 952 int VectorCastNode::opcode(BasicType bt) {
 953   switch (bt) {
 954     case T_BYTE:   return Op_VectorCastB2X;
 955     case T_SHORT:  return Op_VectorCastS2X;
 956     case T_INT:    return Op_VectorCastI2X;
 957     case T_LONG:   return Op_VectorCastL2X;
 958     case T_FLOAT:  return Op_VectorCastF2X;
 959     case T_DOUBLE: return Op_VectorCastD2X;
 960     default:
 961       assert(false, "unknown type: %s", type2name(bt));
 962       return 0;
 963   }
 964 }
 965 
 966 Node* ReductionNode::make_reduction_input(PhaseGVN& gvn, int opc, BasicType bt) {
 967   int vopc = opcode(opc, bt);
 968   guarantee(vopc != opc, "Vector reduction for '%s' is not implemented", NodeClassNames[opc]);
 969 
 970   switch (vopc) {
 971     case Op_AndReductionV:
 972       switch (bt) {
 973         case T_BYTE:
 974         case T_SHORT:
 975         case T_INT:
 976           return gvn.makecon(TypeInt::MINUS_1);
 977         case T_LONG:
 978           return gvn.makecon(TypeLong::MINUS_1);
 979         default:
 980           fatal("Missed vector creation for '%s' as the basic type is not correct.", NodeClassNames[vopc]);
 981           return NULL;
 982       }
 983       break;
 984     case Op_AddReductionVI: // fallthrough
 985     case Op_AddReductionVL: // fallthrough
 986     case Op_AddReductionVF: // fallthrough
 987     case Op_AddReductionVD:
 988     case Op_OrReductionV:
 989     case Op_XorReductionV:
 990       return gvn.zerocon(bt);
 991     case Op_MulReductionVI:
 992       return gvn.makecon(TypeInt::ONE);
 993     case Op_MulReductionVL:
 994       return gvn.makecon(TypeLong::ONE);
 995     case Op_MulReductionVF:
 996       return gvn.makecon(TypeF::ONE);
 997     case Op_MulReductionVD:
 998       return gvn.makecon(TypeD::ONE);
 999     case Op_MinReductionV:
1000       switch (bt) {
1001         case T_BYTE:
1002         case T_SHORT:
1003         case T_INT:
1004           return gvn.makecon(TypeInt::MAX);
1005         case T_LONG:
1006           return gvn.makecon(TypeLong::MAX);
1007         case T_FLOAT:
1008           return gvn.makecon(TypeF::POS_INF);
1009         case T_DOUBLE:
1010           return gvn.makecon(TypeD::POS_INF);
1011           default: Unimplemented(); return NULL;
1012       }
1013       break;
1014     case Op_MaxReductionV:
1015       switch (bt) {
1016         case T_BYTE:
1017         case T_SHORT:
1018         case T_INT:
1019           return gvn.makecon(TypeInt::MIN);
1020         case T_LONG:
1021           return gvn.makecon(TypeLong::MIN);
1022         case T_FLOAT:
1023           return gvn.makecon(TypeF::NEG_INF);
1024         case T_DOUBLE:
1025           return gvn.makecon(TypeD::NEG_INF);
1026           default: Unimplemented(); return NULL;
1027       }
1028       break;
1029     default:
1030       fatal("Missed vector creation for '%s'", NodeClassNames[vopc]);
1031       return NULL;
1032   }
1033 }
1034 
1035 bool ReductionNode::implemented(int opc, uint vlen, BasicType bt) {
1036   if (is_java_primitive(bt) &&
1037       (vlen > 1) && is_power_of_2(vlen) &&
1038       Matcher::vector_size_supported(bt, vlen)) {
1039     int vopc = ReductionNode::opcode(opc, bt);
1040     return vopc != opc && Matcher::match_rule_supported(vopc);
1041   }
1042   return false;
1043 }
1044 
1045 MacroLogicVNode* MacroLogicVNode::make(PhaseGVN& gvn, Node* in1, Node* in2, Node* in3,
1046                                        uint truth_table, const TypeVect* vt) {
1047   assert(truth_table <= 0xFF, "invalid");
1048   assert(in1->bottom_type()->is_vect()->length_in_bytes() == vt->length_in_bytes(), "mismatch");
1049   assert(in2->bottom_type()->is_vect()->length_in_bytes() == vt->length_in_bytes(), "mismatch");
1050   assert(in3->bottom_type()->is_vect()->length_in_bytes() == vt->length_in_bytes(), "mismatch");
1051   Node* fn = gvn.intcon(truth_table);
1052   return new MacroLogicVNode(in1, in2, in3, fn, vt);
1053 }
1054 
1055 #ifndef PRODUCT
1056 void VectorMaskCmpNode::dump_spec(outputStream *st) const {
1057   st->print(" %d #", _predicate); _type->dump_on(st);
1058 }
1059 #endif // PRODUCT
1060 
1061 Node* VectorReinterpretNode::Identity(PhaseGVN *phase) {
1062   Node* n = in(1);
1063   if (n->Opcode() == Op_VectorReinterpret) {
1064     if (Type::cmp(bottom_type(), n->in(1)->bottom_type()) == 0) {
1065       return n->in(1);
1066     }
1067   }
1068   return this;
1069 }
1070 
1071 Node* VectorInsertNode::make(Node* vec, Node* new_val, int position) {
1072   assert(position < (int)vec->bottom_type()->is_vect()->length(), "pos in range");
1073   ConINode* pos = ConINode::make(position);
1074   return new VectorInsertNode(vec, new_val, pos, vec->bottom_type()->is_vect());
1075 }
1076 
1077 Node* VectorUnboxNode::Identity(PhaseGVN *phase) {
1078   Node* n = obj()->uncast();
1079   if (EnableVectorReboxing && n->Opcode() == Op_VectorBox) {
1080     if (Type::cmp(bottom_type(), n->in(VectorBoxNode::Value)->bottom_type()) == 0) {
1081       return n->in(VectorBoxNode::Value);
1082     }
1083   }
1084   return this;
1085 }
1086 
1087 const TypeFunc* VectorBoxNode::vec_box_type(const TypeInstPtr* box_type) {
1088   const Type** fields = TypeTuple::fields(0);
1089   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms, fields);
1090 
1091   fields = TypeTuple::fields(1);
1092   fields[TypeFunc::Parms+0] = box_type;
1093   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
1094 
1095   return TypeFunc::make(domain, range);
1096 }
1097 
1098 #ifndef PRODUCT
1099 void VectorBoxAllocateNode::dump_spec(outputStream *st) const {
1100   CallStaticJavaNode::dump_spec(st);
1101 }
1102 #endif // !PRODUCT
< prev index next >