1 /*
   2  * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   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 
  29 //------------------------------VectorNode--------------------------------------
  30 
  31 // Return the vector operator for the specified scalar operation
  32 // and vector length.
  33 int VectorNode::opcode(int sopc, BasicType bt) {
  34   switch (sopc) {
  35   case Op_AddI:
  36     switch (bt) {
  37     case T_BOOLEAN:
  38     case T_BYTE:      return Op_AddVB;
  39     case T_CHAR:
  40     case T_SHORT:     return Op_AddVS;
  41     case T_INT:       return Op_AddVI;
  42     default:          ShouldNotReachHere(); return 0;
  43     }
  44   case Op_AddL:
  45     assert(bt == T_LONG, "must be");
  46     return Op_AddVL;
  47   case Op_AddF:
  48     assert(bt == T_FLOAT, "must be");
  49     return Op_AddVF;
  50   case Op_AddD:
  51     assert(bt == T_DOUBLE, "must be");
  52     return Op_AddVD;
  53   case Op_SubI:
  54     switch (bt) {
  55     case T_BOOLEAN:
  56     case T_BYTE:   return Op_SubVB;
  57     case T_CHAR:
  58     case T_SHORT:  return Op_SubVS;
  59     case T_INT:    return Op_SubVI;
  60     default:       ShouldNotReachHere(); return 0;
  61     }
  62   case Op_SubL:
  63     assert(bt == T_LONG, "must be");
  64     return Op_SubVL;
  65   case Op_SubF:
  66     assert(bt == T_FLOAT, "must be");
  67     return Op_SubVF;
  68   case Op_SubD:
  69     assert(bt == T_DOUBLE, "must be");
  70     return Op_SubVD;
  71   case Op_MulI:
  72     switch (bt) {
  73     case T_BOOLEAN:return 0;
  74     case T_BYTE:   return Op_MulVB;
  75     case T_CHAR:
  76     case T_SHORT:  return Op_MulVS;
  77     case T_INT:    return Op_MulVI;
  78     default:       ShouldNotReachHere(); return 0;
  79     }
  80   case Op_MulL:
  81     assert(bt == T_LONG, "must be");
  82     return Op_MulVL;
  83   case Op_MulF:
  84     assert(bt == T_FLOAT, "must be");
  85     return Op_MulVF;
  86   case Op_MulD:
  87     assert(bt == T_DOUBLE, "must be");
  88     return Op_MulVD;
  89   case Op_FmaD:
  90     assert(bt == T_DOUBLE, "must be");
  91     return Op_FmaVD;
  92   case Op_FmaF:
  93     assert(bt == T_FLOAT, "must be");
  94     return Op_FmaVF;
  95   case Op_CMoveF:
  96     assert(bt == T_FLOAT, "must be");
  97     return Op_CMoveVF;
  98   case Op_CMoveD:
  99     assert(bt == T_DOUBLE, "must be");
 100     return Op_CMoveVD;
 101   case Op_DivF:
 102     assert(bt == T_FLOAT, "must be");
 103     return Op_DivVF;
 104   case Op_DivD:
 105     assert(bt == T_DOUBLE, "must be");
 106     return Op_DivVD;
 107   case Op_AbsI:
 108     switch (bt) {
 109     case T_BOOLEAN:
 110     case T_CHAR:  return 0; // abs does not make sense for unsigned
 111     case T_BYTE:  return Op_AbsVB;
 112     case T_SHORT: return Op_AbsVS;
 113     case T_INT:   return Op_AbsVI;
 114     default: ShouldNotReachHere(); return 0;
 115     }
 116   case Op_AbsL:
 117     assert(bt == T_LONG, "must be");
 118     return Op_AbsVL;
 119   case Op_AbsF:
 120     assert(bt == T_FLOAT, "must be");
 121     return Op_AbsVF;
 122   case Op_AbsD:
 123     assert(bt == T_DOUBLE, "must be");
 124     return Op_AbsVD;
 125   case Op_NegF:
 126     assert(bt == T_FLOAT, "must be");
 127     return Op_NegVF;
 128   case Op_NegD:
 129     assert(bt == T_DOUBLE, "must be");
 130     return Op_NegVD;
 131   case Op_SqrtF:
 132     assert(bt == T_FLOAT, "must be");
 133     return Op_SqrtVF;
 134   case Op_SqrtD:
 135     assert(bt == T_DOUBLE, "must be");
 136     return Op_SqrtVD;
 137   case Op_PopCountI:
 138     if (bt == T_INT) {
 139       return Op_PopCountVI;
 140     }
 141     // Unimplemented for subword types since bit count changes
 142     // depending on size of lane (and sign bit).
 143     return 0;
 144   case Op_LShiftI:
 145     switch (bt) {
 146     case T_BOOLEAN:
 147     case T_BYTE:   return Op_LShiftVB;
 148     case T_CHAR:
 149     case T_SHORT:  return Op_LShiftVS;
 150     case T_INT:    return Op_LShiftVI;
 151       default:       ShouldNotReachHere(); return 0;
 152     }
 153   case Op_LShiftL:
 154     assert(bt == T_LONG, "must be");
 155     return Op_LShiftVL;
 156   case Op_RShiftI:
 157     switch (bt) {
 158     case T_BOOLEAN:return Op_URShiftVB; // boolean is unsigned value
 159     case T_CHAR:   return Op_URShiftVS; // char is unsigned value
 160     case T_BYTE:   return Op_RShiftVB;
 161     case T_SHORT:  return Op_RShiftVS;
 162     case T_INT:    return Op_RShiftVI;
 163     default:       ShouldNotReachHere(); return 0;
 164     }
 165   case Op_RShiftL:
 166     assert(bt == T_LONG, "must be");
 167     return Op_RShiftVL;
 168   case Op_URShiftI:
 169     switch (bt) {
 170     case T_BOOLEAN:return Op_URShiftVB;
 171     case T_CHAR:   return Op_URShiftVS;
 172     case T_BYTE:
 173     case T_SHORT:  return 0; // Vector logical right shift for signed short
 174                              // values produces incorrect Java result for
 175                              // negative data because java code should convert
 176                              // a short value into int value with sign
 177                              // extension before a shift.
 178     case T_INT:    return Op_URShiftVI;
 179     default:       ShouldNotReachHere(); return 0;
 180     }
 181   case Op_URShiftL:
 182     assert(bt == T_LONG, "must be");
 183     return Op_URShiftVL;
 184   case Op_AndI:
 185   case Op_AndL:
 186     return Op_AndV;
 187   case Op_OrI:
 188   case Op_OrL:
 189     return Op_OrV;
 190   case Op_XorI:
 191   case Op_XorL:
 192     return Op_XorV;
 193   case Op_MinF:
 194     assert(bt == T_FLOAT, "must be");
 195     return Op_MinV;
 196   case Op_MinD:
 197     assert(bt == T_DOUBLE, "must be");
 198     return Op_MinV;
 199   case Op_MaxF:
 200     assert(bt == T_FLOAT, "must be");
 201     return Op_MaxV;
 202   case Op_MaxD:
 203     assert(bt == T_DOUBLE, "must be");
 204     return Op_MaxV;
 205 
 206   case Op_LoadB:
 207   case Op_LoadUB:
 208   case Op_LoadUS:
 209   case Op_LoadS:
 210   case Op_LoadI:
 211   case Op_LoadL:
 212   case Op_LoadF:
 213   case Op_LoadD:
 214     return Op_LoadVector;
 215 
 216   case Op_StoreB:
 217   case Op_StoreC:
 218   case Op_StoreI:
 219   case Op_StoreL:
 220   case Op_StoreF:
 221   case Op_StoreD:
 222     return Op_StoreVector;
 223   case Op_MulAddS2I:
 224     return Op_MulAddVS2VI;
 225 
 226   default:
 227     return 0; // Unimplemented
 228   }
 229 }
 230 
 231 // Also used to check if the code generator
 232 // supports the vector operation.
 233 bool VectorNode::implemented(int opc, uint vlen, BasicType bt) {
 234   if (is_java_primitive(bt) &&
 235       (vlen > 1) && is_power_of_2(vlen) &&
 236       Matcher::vector_size_supported(bt, vlen)) {
 237     int vopc = VectorNode::opcode(opc, bt);
 238     return vopc > 0 && Matcher::match_rule_supported_vector(vopc, vlen);
 239   }
 240   return false;
 241 }
 242 
 243 bool VectorNode::is_type_transition_short_to_int(Node* n) {
 244   switch (n->Opcode()) {
 245   case Op_MulAddS2I:
 246     return true;
 247   }
 248   return false;
 249 }
 250 
 251 bool VectorNode::is_type_transition_to_int(Node* n) {
 252   return is_type_transition_short_to_int(n);
 253 }
 254 
 255 bool VectorNode::is_muladds2i(Node* n) {
 256   if (n->Opcode() == Op_MulAddS2I) {
 257     return true;
 258   }
 259   return false;
 260 }
 261 
 262 bool VectorNode::is_shift(Node* n) {
 263   switch (n->Opcode()) {
 264   case Op_LShiftI:
 265   case Op_LShiftL:
 266   case Op_RShiftI:
 267   case Op_RShiftL:
 268   case Op_URShiftI:
 269   case Op_URShiftL:
 270     return true;
 271   default:
 272     return false;
 273   }
 274 }
 275 
 276 // Check if input is loop invariant vector.
 277 bool VectorNode::is_invariant_vector(Node* n) {
 278   // Only Replicate vector nodes are loop invariant for now.
 279   switch (n->Opcode()) {
 280   case Op_ReplicateB:
 281   case Op_ReplicateS:
 282   case Op_ReplicateI:
 283   case Op_ReplicateL:
 284   case Op_ReplicateF:
 285   case Op_ReplicateD:
 286     return true;
 287   default:
 288     return false;
 289   }
 290 }
 291 
 292 // [Start, end) half-open range defining which operands are vectors
 293 void VectorNode::vector_operands(Node* n, uint* start, uint* end) {
 294   switch (n->Opcode()) {
 295   case Op_LoadB:   case Op_LoadUB:
 296   case Op_LoadS:   case Op_LoadUS:
 297   case Op_LoadI:   case Op_LoadL:
 298   case Op_LoadF:   case Op_LoadD:
 299   case Op_LoadP:   case Op_LoadN:
 300   case Op_LoadBarrierSlowReg:
 301     *start = 0;
 302     *end   = 0; // no vector operands
 303     break;
 304   case Op_StoreB:  case Op_StoreC:
 305   case Op_StoreI:  case Op_StoreL:
 306   case Op_StoreF:  case Op_StoreD:
 307   case Op_StoreP:  case Op_StoreN:
 308     *start = MemNode::ValueIn;
 309     *end   = MemNode::ValueIn + 1; // 1 vector operand
 310     break;
 311   case Op_LShiftI:  case Op_LShiftL:
 312   case Op_RShiftI:  case Op_RShiftL:
 313   case Op_URShiftI: case Op_URShiftL:
 314     *start = 1;
 315     *end   = 2; // 1 vector operand
 316     break;
 317   case Op_AddI: case Op_AddL: case Op_AddF: case Op_AddD:
 318   case Op_SubI: case Op_SubL: case Op_SubF: case Op_SubD:
 319   case Op_MulI: case Op_MulL: case Op_MulF: case Op_MulD:
 320   case Op_DivF: case Op_DivD:
 321   case Op_AndI: case Op_AndL:
 322   case Op_OrI:  case Op_OrL:
 323   case Op_XorI: case Op_XorL:
 324   case Op_MulAddS2I:
 325     *start = 1;
 326     *end   = 3; // 2 vector operands
 327     break;
 328   case Op_CMoveI:  case Op_CMoveL:  case Op_CMoveF:  case Op_CMoveD:
 329     *start = 2;
 330     *end   = n->req();
 331     break;
 332   case Op_FmaD:
 333   case Op_FmaF:
 334     *start = 1;
 335     *end   = 4; // 3 vector operands
 336     break;
 337   default:
 338     *start = 1;
 339     *end   = n->req(); // default is all operands
 340   }
 341 }
 342 
 343 // Return the vector version of a scalar operation node.
 344 VectorNode* VectorNode::make(int opc, Node* n1, Node* n2, uint vlen, BasicType bt) {
 345   const TypeVect* vt = TypeVect::make(bt, vlen);
 346   int vopc = VectorNode::opcode(opc, bt);
 347   // This method should not be called for unimplemented vectors.
 348   guarantee(vopc > 0, "Vector for '%s' is not implemented", NodeClassNames[opc]);
 349   switch (vopc) {
 350   case Op_AddVB: return new AddVBNode(n1, n2, vt);
 351   case Op_AddVS: return new AddVSNode(n1, n2, vt);
 352   case Op_AddVI: return new AddVINode(n1, n2, vt);
 353   case Op_AddVL: return new AddVLNode(n1, n2, vt);
 354   case Op_AddVF: return new AddVFNode(n1, n2, vt);
 355   case Op_AddVD: return new AddVDNode(n1, n2, vt);
 356 
 357   case Op_SubVB: return new SubVBNode(n1, n2, vt);
 358   case Op_SubVS: return new SubVSNode(n1, n2, vt);
 359   case Op_SubVI: return new SubVINode(n1, n2, vt);
 360   case Op_SubVL: return new SubVLNode(n1, n2, vt);
 361   case Op_SubVF: return new SubVFNode(n1, n2, vt);
 362   case Op_SubVD: return new SubVDNode(n1, n2, vt);
 363 
 364   case Op_MulVB: return new MulVBNode(n1, n2, vt);
 365   case Op_MulVS: return new MulVSNode(n1, n2, vt);
 366   case Op_MulVI: return new MulVINode(n1, n2, vt);
 367   case Op_MulVL: return new MulVLNode(n1, n2, vt);
 368   case Op_MulVF: return new MulVFNode(n1, n2, vt);
 369   case Op_MulVD: return new MulVDNode(n1, n2, vt);
 370 
 371   case Op_DivVF: return new DivVFNode(n1, n2, vt);
 372   case Op_DivVD: return new DivVDNode(n1, n2, vt);
 373 
 374   case Op_AbsVB: return new AbsVBNode(n1, vt);
 375   case Op_AbsVS: return new AbsVSNode(n1, vt);
 376   case Op_AbsVI: return new AbsVINode(n1, vt);
 377   case Op_AbsVL: return new AbsVLNode(n1, vt);
 378   case Op_AbsVF: return new AbsVFNode(n1, vt);
 379   case Op_AbsVD: return new AbsVDNode(n1, vt);
 380 
 381   case Op_NegVF: return new NegVFNode(n1, vt);
 382   case Op_NegVD: return new NegVDNode(n1, vt);
 383 
 384   case Op_SqrtVF: return new SqrtVFNode(n1, vt);
 385   case Op_SqrtVD: return new SqrtVDNode(n1, vt);
 386 
 387   case Op_PopCountVI: return new PopCountVINode(n1, vt);
 388 
 389   case Op_LShiftVB: return new LShiftVBNode(n1, n2, vt);
 390   case Op_LShiftVS: return new LShiftVSNode(n1, n2, vt);
 391   case Op_LShiftVI: return new LShiftVINode(n1, n2, vt);
 392   case Op_LShiftVL: return new LShiftVLNode(n1, n2, vt);
 393 
 394   case Op_RShiftVB: return new RShiftVBNode(n1, n2, vt);
 395   case Op_RShiftVS: return new RShiftVSNode(n1, n2, vt);
 396   case Op_RShiftVI: return new RShiftVINode(n1, n2, vt);
 397   case Op_RShiftVL: return new RShiftVLNode(n1, n2, vt);
 398 
 399   case Op_URShiftVB: return new URShiftVBNode(n1, n2, vt);
 400   case Op_URShiftVS: return new URShiftVSNode(n1, n2, vt);
 401   case Op_URShiftVI: return new URShiftVINode(n1, n2, vt);
 402   case Op_URShiftVL: return new URShiftVLNode(n1, n2, vt);
 403 
 404   case Op_AndV: return new AndVNode(n1, n2, vt);
 405   case Op_OrV:  return new OrVNode (n1, n2, vt);
 406   case Op_XorV: return new XorVNode(n1, n2, vt);
 407 
 408   case Op_MinV: return new MinVNode(n1, n2, vt);
 409   case Op_MaxV: return new MaxVNode(n1, n2, vt);
 410 
 411   case Op_MulAddVS2VI: return new MulAddVS2VINode(n1, n2, vt);
 412   default:
 413     fatal("Missed vector creation for '%s'", NodeClassNames[vopc]);
 414     return NULL;
 415   }
 416 }
 417 
 418 VectorNode* VectorNode::make(int opc, Node* n1, Node* n2, Node* n3, uint vlen, BasicType bt) {
 419   const TypeVect* vt = TypeVect::make(bt, vlen);
 420   int vopc = VectorNode::opcode(opc, bt);
 421   // This method should not be called for unimplemented vectors.
 422   guarantee(vopc > 0, "Vector for '%s' is not implemented", NodeClassNames[opc]);
 423   switch (vopc) {
 424   case Op_FmaVD: return new FmaVDNode(n1, n2, n3, vt);
 425   case Op_FmaVF: return new FmaVFNode(n1, n2, n3, vt);
 426   default:
 427     fatal("Missed vector creation for '%s'", NodeClassNames[vopc]);
 428     return NULL;
 429   }
 430 }
 431 
 432 // Scalar promotion
 433 VectorNode* VectorNode::scalar2vector(Node* s, uint vlen, const Type* opd_t) {
 434   BasicType bt = opd_t->array_element_basic_type();
 435   const TypeVect* vt = opd_t->singleton() ? TypeVect::make(opd_t, vlen)
 436                                           : TypeVect::make(bt, vlen);
 437   switch (bt) {
 438   case T_BOOLEAN:
 439   case T_BYTE:
 440     return new ReplicateBNode(s, vt);
 441   case T_CHAR:
 442   case T_SHORT:
 443     return new ReplicateSNode(s, vt);
 444   case T_INT:
 445     return new ReplicateINode(s, vt);
 446   case T_LONG:
 447     return new ReplicateLNode(s, vt);
 448   case T_FLOAT:
 449     return new ReplicateFNode(s, vt);
 450   case T_DOUBLE:
 451     return new ReplicateDNode(s, vt);
 452   default:
 453     fatal("Type '%s' is not supported for vectors", type2name(bt));
 454     return NULL;
 455   }
 456 }
 457 
 458 VectorNode* VectorNode::shift_count(Node* shift, Node* cnt, uint vlen, BasicType bt) {
 459   assert(VectorNode::is_shift(shift) && !cnt->is_Con(), "only variable shift count");
 460   // Match shift count type with shift vector type.
 461   const TypeVect* vt = TypeVect::make(bt, vlen);
 462   switch (shift->Opcode()) {
 463   case Op_LShiftI:
 464   case Op_LShiftL:
 465     return new LShiftCntVNode(cnt, vt);
 466   case Op_RShiftI:
 467   case Op_RShiftL:
 468   case Op_URShiftI:
 469   case Op_URShiftL:
 470     return new RShiftCntVNode(cnt, vt);
 471   default:
 472     fatal("Missed vector creation for '%s'", NodeClassNames[shift->Opcode()]);
 473     return NULL;
 474   }
 475 }
 476 
 477 // Return initial Pack node. Additional operands added with add_opd() calls.
 478 PackNode* PackNode::make(Node* s, uint vlen, BasicType bt) {
 479   const TypeVect* vt = TypeVect::make(bt, vlen);
 480   switch (bt) {
 481   case T_BOOLEAN:
 482   case T_BYTE:
 483     return new PackBNode(s, vt);
 484   case T_CHAR:
 485   case T_SHORT:
 486     return new PackSNode(s, vt);
 487   case T_INT:
 488     return new PackINode(s, vt);
 489   case T_LONG:
 490     return new PackLNode(s, vt);
 491   case T_FLOAT:
 492     return new PackFNode(s, vt);
 493   case T_DOUBLE:
 494     return new PackDNode(s, vt);
 495   default:
 496     fatal("Type '%s' is not supported for vectors", type2name(bt));
 497     return NULL;
 498   }
 499 }
 500 
 501 // Create a binary tree form for Packs. [lo, hi) (half-open) range
 502 PackNode* PackNode::binary_tree_pack(int lo, int hi) {
 503   int ct = hi - lo;
 504   assert(is_power_of_2(ct), "power of 2");
 505   if (ct == 2) {
 506     PackNode* pk = PackNode::make(in(lo), 2, vect_type()->element_basic_type());
 507     pk->add_opd(in(lo+1));
 508     return pk;
 509   } else {
 510     int mid = lo + ct/2;
 511     PackNode* n1 = binary_tree_pack(lo,  mid);
 512     PackNode* n2 = binary_tree_pack(mid, hi );
 513 
 514     BasicType bt = n1->vect_type()->element_basic_type();
 515     assert(bt == n2->vect_type()->element_basic_type(), "should be the same");
 516     switch (bt) {
 517     case T_BOOLEAN:
 518     case T_BYTE:
 519       return new PackSNode(n1, n2, TypeVect::make(T_SHORT, 2));
 520     case T_CHAR:
 521     case T_SHORT:
 522       return new PackINode(n1, n2, TypeVect::make(T_INT, 2));
 523     case T_INT:
 524       return new PackLNode(n1, n2, TypeVect::make(T_LONG, 2));
 525     case T_LONG:
 526       return new Pack2LNode(n1, n2, TypeVect::make(T_LONG, 2));
 527     case T_FLOAT:
 528       return new PackDNode(n1, n2, TypeVect::make(T_DOUBLE, 2));
 529     case T_DOUBLE:
 530       return new Pack2DNode(n1, n2, TypeVect::make(T_DOUBLE, 2));
 531     default:
 532       fatal("Type '%s' is not supported for vectors", type2name(bt));
 533       return NULL;
 534     }
 535   }
 536 }
 537 
 538 // Return the vector version of a scalar load node.
 539 LoadVectorNode* LoadVectorNode::make(int opc, Node* ctl, Node* mem,
 540                                      Node* adr, const TypePtr* atyp,
 541                                      uint vlen, BasicType bt,
 542                                      ControlDependency control_dependency) {
 543   const TypeVect* vt = TypeVect::make(bt, vlen);
 544   return new LoadVectorNode(ctl, mem, adr, atyp, vt, control_dependency);
 545 }
 546 
 547 // Return the vector version of a scalar store node.
 548 StoreVectorNode* StoreVectorNode::make(int opc, Node* ctl, Node* mem,
 549                                        Node* adr, const TypePtr* atyp, Node* val,
 550                                        uint vlen) {
 551   return new StoreVectorNode(ctl, mem, adr, atyp, val);
 552 }
 553 
 554 // Extract a scalar element of vector.
 555 Node* ExtractNode::make(Node* v, uint position, BasicType bt) {
 556   assert((int)position < Matcher::max_vector_size(bt), "pos in range");
 557   ConINode* pos = ConINode::make((int)position);
 558   switch (bt) {
 559   case T_BOOLEAN:
 560     return new ExtractUBNode(v, pos);
 561   case T_BYTE:
 562     return new ExtractBNode(v, pos);
 563   case T_CHAR:
 564     return new ExtractCNode(v, pos);
 565   case T_SHORT:
 566     return new ExtractSNode(v, pos);
 567   case T_INT:
 568     return new ExtractINode(v, pos);
 569   case T_LONG:
 570     return new ExtractLNode(v, pos);
 571   case T_FLOAT:
 572     return new ExtractFNode(v, pos);
 573   case T_DOUBLE:
 574     return new ExtractDNode(v, pos);
 575   default:
 576     fatal("Type '%s' is not supported for vectors", type2name(bt));
 577     return NULL;
 578   }
 579 }
 580 
 581 int ReductionNode::opcode(int opc, BasicType bt) {
 582   int vopc = opc;
 583   switch (opc) {
 584     case Op_AddI:
 585       assert(bt == T_INT, "must be");
 586       vopc = Op_AddReductionVI;
 587       break;
 588     case Op_AddL:
 589       assert(bt == T_LONG, "must be");
 590       vopc = Op_AddReductionVL;
 591       break;
 592     case Op_AddF:
 593       assert(bt == T_FLOAT, "must be");
 594       vopc = Op_AddReductionVF;
 595       break;
 596     case Op_AddD:
 597       assert(bt == T_DOUBLE, "must be");
 598       vopc = Op_AddReductionVD;
 599       break;
 600     case Op_MulI:
 601       assert(bt == T_INT, "must be");
 602       vopc = Op_MulReductionVI;
 603       break;
 604     case Op_MulL:
 605       assert(bt == T_LONG, "must be");
 606       vopc = Op_MulReductionVL;
 607       break;
 608     case Op_MulF:
 609       assert(bt == T_FLOAT, "must be");
 610       vopc = Op_MulReductionVF;
 611       break;
 612     case Op_MulD:
 613       assert(bt == T_DOUBLE, "must be");
 614       vopc = Op_MulReductionVD;
 615       break;
 616     case Op_MinF:
 617       assert(bt == T_FLOAT, "must be");
 618       vopc = Op_MinReductionV;
 619       break;
 620     case Op_MinD:
 621       assert(bt == T_DOUBLE, "must be");
 622       vopc = Op_MinReductionV;
 623       break;
 624     case Op_MaxF:
 625       assert(bt == T_FLOAT, "must be");
 626       vopc = Op_MaxReductionV;
 627       break;
 628     case Op_MaxD:
 629       assert(bt == T_DOUBLE, "must be");
 630       vopc = Op_MaxReductionV;
 631       break;
 632     // TODO: add MulL for targets that support it
 633     default:
 634       break;
 635   }
 636   return vopc;
 637 }
 638 
 639 // Return the appropriate reduction node.
 640 ReductionNode* ReductionNode::make(int opc, Node *ctrl, Node* n1, Node* n2, BasicType bt) {
 641 
 642   int vopc = opcode(opc, bt);
 643 
 644   // This method should not be called for unimplemented vectors.
 645   guarantee(vopc != opc, "Vector for '%s' is not implemented", NodeClassNames[opc]);
 646 
 647   switch (vopc) {
 648   case Op_AddReductionVI: return new AddReductionVINode(ctrl, n1, n2);
 649   case Op_AddReductionVL: return new AddReductionVLNode(ctrl, n1, n2);
 650   case Op_AddReductionVF: return new AddReductionVFNode(ctrl, n1, n2);
 651   case Op_AddReductionVD: return new AddReductionVDNode(ctrl, n1, n2);
 652   case Op_MulReductionVI: return new MulReductionVINode(ctrl, n1, n2);
 653   case Op_MulReductionVL: return new MulReductionVLNode(ctrl, n1, n2);
 654   case Op_MulReductionVF: return new MulReductionVFNode(ctrl, n1, n2);
 655   case Op_MulReductionVD: return new MulReductionVDNode(ctrl, n1, n2);
 656   case Op_MinReductionV: return new MinReductionVNode(ctrl, n1, n2);
 657   case Op_MaxReductionV: return new MaxReductionVNode(ctrl, n1, n2);
 658   default:
 659     fatal("Missed vector creation for '%s'", NodeClassNames[vopc]);
 660     return NULL;
 661   }
 662 }
 663 
 664 bool ReductionNode::implemented(int opc, uint vlen, BasicType bt) {
 665   if (is_java_primitive(bt) &&
 666       (vlen > 1) && is_power_of_2(vlen) &&
 667       Matcher::vector_size_supported(bt, vlen)) {
 668     int vopc = ReductionNode::opcode(opc, bt);
 669     return vopc != opc && Matcher::match_rule_supported(vopc);
 670   }
 671   return false;
 672 }