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