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/cfgnode.hpp"
  28 #include "opto/vectornode.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");
  47     return Op_AddVL;
  48   case Op_AddF:
  49     assert(bt == T_FLOAT, "must be");
  50     return Op_AddVF;
  51   case Op_AddD:
  52     assert(bt == T_DOUBLE, "must be");
  53     return Op_AddVD;
  54   case Op_SubI:
  55     switch (bt) {
  56     case T_BOOLEAN:
  57     case T_BYTE:   return Op_SubVB;
  58     case T_CHAR:
  59     case T_SHORT:  return Op_SubVS;
  60     case T_INT:    return Op_SubVI;
  61     default:       ShouldNotReachHere(); return 0;
  62     }
  63   case Op_SubL:
  64     assert(bt == T_LONG, "must be");
  65     return Op_SubVL;
  66   case Op_SubF:
  67     assert(bt == T_FLOAT, "must be");
  68     return Op_SubVF;
  69   case Op_SubD:
  70     assert(bt == T_DOUBLE, "must be");
  71     return Op_SubVD;
  72   case Op_MulI:
  73     switch (bt) {
  74     case T_BOOLEAN:
  75     case T_BYTE:   return Op_MulVB;
  76     case T_CHAR:
  77     case T_SHORT:  return Op_MulVS;
  78     case T_INT:    return Op_MulVI;
  79     default:       ShouldNotReachHere(); return 0;
  80     }
  81   case Op_MulL:
  82     assert(bt == T_LONG, "must be");
  83     return Op_MulVL;
  84   case Op_MulF:
  85     assert(bt == T_FLOAT, "must be");
  86     return Op_MulVF;
  87   case Op_MulD:
  88     assert(bt == T_DOUBLE, "must be");
  89     return Op_MulVD;
  90   case Op_FmaD:
  91     assert(bt == T_DOUBLE, "must be");
  92     return Op_FmaVD;
  93   case Op_FmaF:
  94     assert(bt == T_FLOAT, "must be");
  95     return Op_FmaVF;
  96   case Op_CMoveF:
  97     assert(bt == T_FLOAT, "must be");
  98     return Op_CMoveVF;
  99   case Op_CMoveD:
 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     assert(bt == T_INT, "must be");
 110     return Op_AbsVI;
 111   case Op_AbsF:
 112     assert(bt == T_FLOAT, "must be");
 113     return Op_AbsVF;
 114   case Op_AbsD:
 115     assert(bt == T_DOUBLE, "must be");
 116     return Op_AbsVD;
 117   case Op_NegI:
 118     assert(bt == T_INT, "must be");
 119     return Op_NegVI;
 120   case Op_NegF:
 121     assert(bt == T_FLOAT, "must be");
 122     return Op_NegVF;
 123   case Op_NegD:
 124     assert(bt == T_DOUBLE, "must be");
 125     return Op_NegVD;
 126   case Op_SqrtF:
 127     assert(bt == T_FLOAT, "must be");
 128     return Op_SqrtVF;
 129   case Op_SqrtD:
 130     assert(bt == T_DOUBLE, "must be");
 131     return Op_SqrtVD;
 132   case Op_Not:
 133     return Op_NotV;
 134   case Op_PopCountI:
 135     if (bt == T_INT) {
 136       return Op_PopCountVI;
 137     }
 138     // Unimplemented for subword types since bit count changes
 139     // depending on size of lane (and sign bit).
 140     return 0;
 141   case Op_LShiftI:
 142     switch (bt) {
 143     case T_BOOLEAN:
 144     case T_BYTE:   return Op_LShiftVB;
 145     case T_CHAR:
 146     case T_SHORT:  return Op_LShiftVS;
 147     case T_INT:    return Op_LShiftVI;
 148       default:       ShouldNotReachHere(); return 0;
 149     }
 150   case Op_LShiftL:
 151     assert(bt == T_LONG, "must be");
 152     return Op_LShiftVL;
 153   case Op_RShiftI:
 154     switch (bt) {
 155     case T_BOOLEAN:return Op_URShiftVB; // boolean is unsigned value
 156     case T_CHAR:   return Op_URShiftVS; // char is unsigned value
 157     case T_BYTE:   return Op_RShiftVB;
 158     case T_SHORT:  return Op_RShiftVS;
 159     case T_INT:    return Op_RShiftVI;
 160     default:       ShouldNotReachHere(); return 0;
 161     }
 162   case Op_RShiftL:
 163     assert(bt == T_LONG, "must be");
 164     return Op_RShiftVL;
 165   case Op_URShiftI:
 166     switch (bt) {
 167     case T_BOOLEAN:return Op_URShiftVB;
 168     case T_CHAR:   return Op_URShiftVS;
 169     case T_BYTE:
 170     case T_SHORT:  return 0; // Vector logical right shift for signed short
 171                              // values produces incorrect Java result for
 172                              // negative data because java code should convert
 173                              // a short value into int value with sign
 174                              // extension before a shift.
 175     case T_INT:    return Op_URShiftVI;
 176     default:       ShouldNotReachHere(); return 0;
 177     }
 178   case Op_URShiftL:
 179     assert(bt == T_LONG, "must be");
 180     return Op_URShiftVL;
 181   case Op_AndI:
 182   case Op_AndL:
 183     return Op_AndV;
 184   case Op_OrI:
 185   case Op_OrL:
 186     return Op_OrV;
 187   case Op_XorI:
 188   case Op_XorL:
 189     return Op_XorV;
 190 
 191   case Op_LoadB:
 192   case Op_LoadUB:
 193   case Op_LoadUS:
 194   case Op_LoadS:
 195   case Op_LoadI:
 196   case Op_LoadL:
 197   case Op_LoadF:
 198   case Op_LoadD:
 199     return Op_LoadVector;
 200 
 201   case Op_StoreB:
 202   case Op_StoreC:
 203   case Op_StoreI:
 204   case Op_StoreL:
 205   case Op_StoreF:
 206   case Op_StoreD:
 207     return Op_StoreVector;
 208 
 209   case Op_AddVB:
 210   case Op_AddVS:
 211   case Op_AddVI:
 212   case Op_AddVL:
 213   case Op_AddVF:
 214   case Op_AddVD:
 215   case Op_SubVB:
 216   case Op_SubVS:
 217   case Op_SubVI:
 218   case Op_SubVL:
 219   case Op_SubVF:
 220   case Op_SubVD:
 221   case Op_MulVB:
 222   case Op_MulVS:
 223   case Op_MulVI:
 224   case Op_MulVL:
 225   case Op_MulVF:
 226   case Op_MulVD:
 227   case Op_DivVF:
 228   case Op_DivVD:
 229   case Op_AbsVI:
 230   case Op_AbsVF:
 231   case Op_AbsVD:
 232   case Op_NegVI:
 233   case Op_NegVF:
 234   case Op_NegVD:
 235   case Op_SqrtVF:
 236   case Op_SqrtVD:
 237   case Op_NotV:
 238   case Op_LShiftVB:
 239   case Op_LShiftVS:
 240   case Op_LShiftVI:
 241   case Op_LShiftVL:
 242   case Op_RShiftVB:
 243   case Op_RShiftVS:
 244   case Op_RShiftVI:
 245   case Op_RShiftVL:
 246   case Op_URShiftVB:
 247   case Op_URShiftVS:
 248   case Op_URShiftVI:
 249   case Op_URShiftVL:
 250   case Op_AndV:
 251   case Op_OrV:
 252   case Op_XorV:
 253     // When op is already vectorized, return that directly.
 254     return sopc;
 255 
 256   default:
 257     return 0; // Unimplemented
 258   }
 259 }
 260 
 261 int VectorNode::replicate_opcode(BasicType bt) {
 262   switch(bt) {
 263     case T_BOOLEAN:
 264     case T_BYTE:
 265       return Op_ReplicateB;
 266     case T_SHORT:
 267     case T_CHAR:
 268       return Op_ReplicateS;
 269     case T_INT:
 270       return Op_ReplicateI;
 271     case T_LONG:
 272       return Op_ReplicateL;
 273     case T_FLOAT:
 274       return Op_ReplicateF;
 275     case T_DOUBLE:
 276       return Op_ReplicateD;
 277     default:
 278       break;
 279   }
 280 
 281   return 0;
 282 }
 283 
 284 // Also used to check if the code generator
 285 // supports the vector operation.
 286 bool VectorNode::implemented(int opc, uint vlen, BasicType bt) {
 287   if (is_java_primitive(bt) &&
 288       (vlen > 1) && is_power_of_2(vlen) &&
 289       Matcher::vector_size_supported(bt, vlen)) {
 290     int vopc = VectorNode::opcode(opc, bt);
 291     return vopc > 0 && Matcher::match_rule_supported_vector(vopc, vlen, bt);
 292   }
 293   return false;
 294 }
 295 
 296 bool VectorNode::is_shift(Node* n) {
 297   switch (n->Opcode()) {
 298   case Op_LShiftI:
 299   case Op_LShiftL:
 300   case Op_RShiftI:
 301   case Op_RShiftL:
 302   case Op_URShiftI:
 303   case Op_URShiftL:
 304     return true;
 305   default:
 306     return false;
 307   }
 308 }
 309 
 310 // Check if input is loop invariant vector.
 311 bool VectorNode::is_invariant_vector(Node* n) {
 312   // Only Replicate vector nodes are loop invariant for now.
 313   switch (n->Opcode()) {
 314   case Op_ReplicateB:
 315   case Op_ReplicateS:
 316   case Op_ReplicateI:
 317   case Op_ReplicateL:
 318   case Op_ReplicateF:
 319   case Op_ReplicateD:
 320     return true;
 321   default:
 322     return false;
 323   }
 324 }
 325 
 326 // [Start, end) half-open range defining which operands are vectors
 327 void VectorNode::vector_operands(Node* n, uint* start, uint* end) {
 328   switch (n->Opcode()) {
 329   case Op_LoadB:   case Op_LoadUB:
 330   case Op_LoadS:   case Op_LoadUS:
 331   case Op_LoadI:   case Op_LoadL:
 332   case Op_LoadF:   case Op_LoadD:
 333   case Op_LoadP:   case Op_LoadN:
 334     *start = 0;
 335     *end   = 0; // no vector operands
 336     break;
 337   case Op_StoreB:  case Op_StoreC:
 338   case Op_StoreI:  case Op_StoreL:
 339   case Op_StoreF:  case Op_StoreD:
 340   case Op_StoreP:  case Op_StoreN:
 341     *start = MemNode::ValueIn;
 342     *end   = MemNode::ValueIn + 1; // 1 vector operand
 343     break;
 344   case Op_LShiftI:  case Op_LShiftL:
 345   case Op_RShiftI:  case Op_RShiftL:
 346   case Op_URShiftI: case Op_URShiftL:
 347     *start = 1;
 348     *end   = 2; // 1 vector operand
 349     break;
 350   case Op_AddI: case Op_AddL: case Op_AddF: case Op_AddD:
 351   case Op_SubI: case Op_SubL: case Op_SubF: case Op_SubD:
 352   case Op_MulI: case Op_MulL: case Op_MulF: case Op_MulD:
 353   case Op_DivF: case Op_DivD:
 354   case Op_AndI: case Op_AndL:
 355   case Op_OrI:  case Op_OrL:
 356   case Op_XorI: case Op_XorL:
 357     *start = 1;
 358     *end   = 3; // 2 vector operands
 359     break;
 360   case Op_CMoveI:  case Op_CMoveL:  case Op_CMoveF:  case Op_CMoveD:
 361     *start = 2;
 362     *end   = n->req();
 363     break;
 364   case Op_FmaD:
 365   case Op_FmaF:
 366     *start = 1;
 367     *end   = 4; // 3 vector operands
 368     break;
 369   default:
 370     *start = 1;
 371     *end   = n->req(); // default is all operands
 372   }
 373 }
 374 
 375 // Return the vector version of a scalar operation node.
 376 VectorNode* VectorNode::make(int opc, Node* n1, Node* n2, uint vlen, BasicType bt) {
 377   const TypeVect* vt = TypeVect::make(bt, vlen);
 378   int vopc = VectorNode::opcode(opc, bt);
 379   // This method should not be called for unimplemented vectors.
 380   guarantee(vopc > 0, "Vector for '%s' is not implemented", NodeClassNames[opc]);
 381   switch (vopc) {
 382   case Op_AddVB: return new AddVBNode(n1, n2, vt);
 383   case Op_AddVS: return new AddVSNode(n1, n2, vt);
 384   case Op_AddVI: return new AddVINode(n1, n2, vt);
 385   case Op_AddVL: return new AddVLNode(n1, n2, vt);
 386   case Op_AddVF: return new AddVFNode(n1, n2, vt);
 387   case Op_AddVD: return new AddVDNode(n1, n2, vt);
 388 
 389   case Op_SubVB: return new SubVBNode(n1, n2, vt);
 390   case Op_SubVS: return new SubVSNode(n1, n2, vt);
 391   case Op_SubVI: return new SubVINode(n1, n2, vt);
 392   case Op_SubVL: return new SubVLNode(n1, n2, vt);
 393   case Op_SubVF: return new SubVFNode(n1, n2, vt);
 394   case Op_SubVD: return new SubVDNode(n1, n2, vt);
 395 
 396   case Op_MulVB: return new MulVBNode(n1, n2, vt);
 397   case Op_MulVS: return new MulVSNode(n1, n2, vt);
 398   case Op_MulVI: return new MulVINode(n1, n2, vt);
 399   case Op_MulVL: return new MulVLNode(n1, n2, vt);
 400   case Op_MulVF: return new MulVFNode(n1, n2, vt);
 401   case Op_MulVD: return new MulVDNode(n1, n2, vt);
 402 
 403   case Op_DivVF: return new DivVFNode(n1, n2, vt);
 404   case Op_DivVD: return new DivVDNode(n1, n2, vt);
 405 
 406   case Op_AbsVI: return new AbsVINode(n1, vt);
 407   case Op_AbsVF: return new AbsVFNode(n1, vt);
 408   case Op_AbsVD: return new AbsVDNode(n1, vt);
 409 
 410   case Op_NegVI: return new NegVINode(n1, vt);
 411   case Op_NegVF: return new NegVFNode(n1, vt);
 412   case Op_NegVD: return new NegVDNode(n1, vt);
 413 
 414   case Op_SqrtVF: return new SqrtVFNode(n1, vt);
 415   case Op_SqrtVD: return new SqrtVDNode(n1, vt);
 416 
 417   case Op_PopCountVI: return new PopCountVINode(n1, vt);
 418   case Op_NotV: return new NotVNode(n1, vt);
 419 
 420   case Op_LShiftVB: return new LShiftVBNode(n1, n2, vt);
 421   case Op_LShiftVS: return new LShiftVSNode(n1, n2, vt);
 422   case Op_LShiftVI: return new LShiftVINode(n1, n2, vt);
 423   case Op_LShiftVL: return new LShiftVLNode(n1, n2, vt);
 424 
 425   case Op_RShiftVB: return new RShiftVBNode(n1, n2, vt);
 426   case Op_RShiftVS: return new RShiftVSNode(n1, n2, vt);
 427   case Op_RShiftVI: return new RShiftVINode(n1, n2, vt);
 428   case Op_RShiftVL: return new RShiftVLNode(n1, n2, vt);
 429 
 430   case Op_URShiftVB: return new URShiftVBNode(n1, n2, vt);
 431   case Op_URShiftVS: return new URShiftVSNode(n1, n2, vt);
 432   case Op_URShiftVI: return new URShiftVINode(n1, n2, vt);
 433   case Op_URShiftVL: return new URShiftVLNode(n1, n2, vt);
 434 
 435   case Op_AndV: return new AndVNode(n1, n2, vt);
 436   case Op_OrV:  return new OrVNode (n1, n2, vt);
 437   case Op_XorV: return new XorVNode(n1, n2, vt);
 438   
 439   case Op_ConvertVF2VD:
 440     if (bt == T_DOUBLE) {
 441       return new ConvertVF2VDNode(n1, vt);
 442     }
 443   default:
 444     fatal("Missed vector creation for '%s'", NodeClassNames[vopc]);
 445     return NULL;
 446   }
 447 }
 448 
 449 VectorNode* VectorNode::make(int opc, Node* n1, Node* n2, Node* n3, uint vlen, BasicType bt) {
 450   const TypeVect* vt = TypeVect::make(bt, vlen);
 451   int vopc = VectorNode::opcode(opc, bt);
 452   // This method should not be called for unimplemented vectors.
 453   guarantee(vopc > 0, "Vector for '%s' is not implemented", NodeClassNames[opc]);
 454   switch (vopc) {
 455   case Op_FmaVD: return new FmaVDNode(n1, n2, n3, vt);
 456   case Op_FmaVF: return new FmaVFNode(n1, n2, n3, vt);
 457   default:
 458     fatal("Missed vector creation for '%s'", NodeClassNames[vopc]);
 459     return NULL;
 460   }
 461 }
 462 
 463 // Scalar promotion
 464 VectorNode* VectorNode::scalar2vector(Node* s, uint vlen, const Type* opd_t) {
 465   BasicType bt = opd_t->array_element_basic_type();
 466   const TypeVect* vt = opd_t->singleton() ? TypeVect::make(opd_t, vlen)
 467                                           : TypeVect::make(bt, vlen);
 468   switch (bt) {
 469   case T_BOOLEAN:
 470   case T_BYTE:
 471     return new ReplicateBNode(s, vt);
 472   case T_CHAR:
 473   case T_SHORT:
 474     return new ReplicateSNode(s, vt);
 475   case T_INT:
 476     return new ReplicateINode(s, vt);
 477   case T_LONG:
 478     return new ReplicateLNode(s, vt);
 479   case T_FLOAT:
 480     return new ReplicateFNode(s, vt);
 481   case T_DOUBLE:
 482     return new ReplicateDNode(s, vt);
 483   default:
 484     fatal("Type '%s' is not supported for vectors", type2name(bt));
 485     return NULL;
 486   }
 487 }
 488 
 489 VectorNode* VectorNode::shift_count(int opc, Node* cnt, uint vlen, BasicType bt) {
 490   assert(!cnt->is_Con(), "only variable shift count");
 491   // Match shift count type with shift vector type.
 492   const TypeVect* vt = TypeVect::make(bt, vlen);
 493   switch (opc) {
 494   case Op_LShiftI:
 495   case Op_LShiftL:
 496     return new LShiftCntVNode(cnt, vt);
 497   case Op_RShiftI:
 498   case Op_RShiftL:
 499   case Op_URShiftI:
 500   case Op_URShiftL:
 501     return new RShiftCntVNode(cnt, vt);
 502   default:
 503     fatal("Missed vector creation for '%s'", NodeClassNames[opc]);
 504     return NULL;
 505   }
 506 }
 507 
 508 // Return initial Pack node. Additional operands added with add_opd() calls.
 509 PackNode* PackNode::make(Node* s, uint vlen, BasicType bt) {
 510   const TypeVect* vt = TypeVect::make(bt, vlen);
 511   switch (bt) {
 512   case T_BOOLEAN:
 513   case T_BYTE:
 514     return new PackBNode(s, vt);
 515   case T_CHAR:
 516   case T_SHORT:
 517     return new PackSNode(s, vt);
 518   case T_INT:
 519     return new PackINode(s, vt);
 520   case T_LONG:
 521     return new PackLNode(s, vt);
 522   case T_FLOAT:
 523     return new PackFNode(s, vt);
 524   case T_DOUBLE:
 525     return new PackDNode(s, vt);
 526   default:
 527     fatal("Type '%s' is not supported for vectors", type2name(bt));
 528     return NULL;
 529   }
 530 }
 531 
 532 // Create a binary tree form for Packs. [lo, hi) (half-open) range
 533 PackNode* PackNode::binary_tree_pack(int lo, int hi) {
 534   int ct = hi - lo;
 535   assert(is_power_of_2(ct), "power of 2");
 536   if (ct == 2) {
 537     PackNode* pk = PackNode::make(in(lo), 2, vect_type()->element_basic_type());
 538     pk->add_opd(in(lo+1));
 539     return pk;
 540   } else {
 541     int mid = lo + ct/2;
 542     PackNode* n1 = binary_tree_pack(lo,  mid);
 543     PackNode* n2 = binary_tree_pack(mid, hi );
 544 
 545     BasicType bt = n1->vect_type()->element_basic_type();
 546     assert(bt == n2->vect_type()->element_basic_type(), "should be the same");
 547     switch (bt) {
 548     case T_BOOLEAN:
 549     case T_BYTE:
 550       return new PackSNode(n1, n2, TypeVect::make(T_SHORT, 2));
 551     case T_CHAR:
 552     case T_SHORT:
 553       return new PackINode(n1, n2, TypeVect::make(T_INT, 2));
 554     case T_INT:
 555       return new PackLNode(n1, n2, TypeVect::make(T_LONG, 2));
 556     case T_LONG:
 557       return new Pack2LNode(n1, n2, TypeVect::make(T_LONG, 2));
 558     case T_FLOAT:
 559       return new PackDNode(n1, n2, TypeVect::make(T_DOUBLE, 2));
 560     case T_DOUBLE:
 561       return new Pack2DNode(n1, n2, TypeVect::make(T_DOUBLE, 2));
 562     default:
 563       fatal("Type '%s' is not supported for vectors", type2name(bt));
 564       return NULL;
 565     }
 566   }
 567 }
 568 
 569 // Return the vector version of a scalar load node.
 570 LoadVectorNode* LoadVectorNode::make(int opc, Node* ctl, Node* mem,
 571                                      Node* adr, const TypePtr* atyp,
 572                                      uint vlen, BasicType bt,
 573                                      ControlDependency control_dependency) {
 574   const TypeVect* vt = TypeVect::make(bt, vlen);
 575   return new LoadVectorNode(ctl, mem, adr, atyp, vt, control_dependency);
 576 }
 577 
 578 // Return the vector version of a scalar store node.
 579 StoreVectorNode* StoreVectorNode::make(int opc, Node* ctl, Node* mem,
 580                                        Node* adr, const TypePtr* atyp, Node* val,
 581                                        uint vlen) {
 582   return new StoreVectorNode(ctl, mem, adr, atyp, val);
 583 }
 584 
 585 // Extract a scalar element of vector.
 586 Node* ExtractNode::make(Node* v, uint position, BasicType bt) {
 587   assert((int)position < Matcher::max_vector_size(bt), "pos in range");
 588   ConINode* pos = ConINode::make((int)position);
 589   switch (bt) {
 590   case T_BOOLEAN:
 591     return new ExtractUBNode(v, pos);
 592   case T_BYTE:
 593     return new ExtractBNode(v, pos);
 594   case T_CHAR:
 595     return new ExtractCNode(v, pos);
 596   case T_SHORT:
 597     return new ExtractSNode(v, pos);
 598   case T_INT:
 599     return new ExtractINode(v, pos);
 600   case T_LONG:
 601     return new ExtractLNode(v, pos);
 602   case T_FLOAT:
 603     return new ExtractFNode(v, pos);
 604   case T_DOUBLE:
 605     return new ExtractDNode(v, pos);
 606   default:
 607     fatal("Type '%s' is not supported for vectors", type2name(bt));
 608     return NULL;
 609   }
 610 }
 611 
 612 int ReductionNode::opcode(int opc, BasicType bt) {
 613   int vopc = opc;
 614   switch (opc) {
 615     case Op_AddI:
 616       switch (bt) {
 617         case T_BOOLEAN:
 618         case T_CHAR: return 0;
 619         case T_BYTE:
 620         case T_SHORT:
 621         case T_INT:       
 622           vopc = Op_AddReductionVI;
 623           break;
 624         default:          ShouldNotReachHere(); return 0;
 625       }
 626       break;
 627     case Op_AddL:
 628       assert(bt == T_LONG, "must be");
 629       vopc = Op_AddReductionVL;
 630       break;
 631     case Op_AddF:
 632       assert(bt == T_FLOAT, "must be");
 633       vopc = Op_AddReductionVF;
 634       break;
 635     case Op_AddD:
 636       assert(bt == T_DOUBLE, "must be");
 637       vopc = Op_AddReductionVD;
 638       break;
 639     case Op_MulI:
 640       assert(bt == T_INT, "must be");
 641       vopc = Op_MulReductionVI;
 642       break;
 643     case Op_MulL:
 644       assert(bt == T_LONG, "must be");
 645       vopc = Op_MulReductionVL;
 646       break;
 647     case Op_MulF:
 648       assert(bt == T_FLOAT, "must be");
 649       vopc = Op_MulReductionVF;
 650       break;
 651     case Op_MulD:
 652       assert(bt == T_DOUBLE, "must be");
 653       vopc = Op_MulReductionVD;
 654       break;
 655     case Op_AndI:
 656       switch (bt) {
 657       case T_BOOLEAN:
 658       case T_CHAR: return 0;
 659       case T_BYTE:
 660       case T_SHORT:
 661       case T_INT:
 662         vopc = Op_AndReductionV;
 663         break;
 664       default:          ShouldNotReachHere(); return 0;
 665       }
 666       break;
 667     case Op_AndL:
 668       assert(bt == T_LONG, "must be");
 669       vopc = Op_AndReductionV;
 670       break;
 671     case Op_OrI:
 672       assert(bt == T_INT, "must be");
 673       vopc = Op_OrReductionV;
 674       break;
 675     case Op_OrL:
 676       assert(bt == T_LONG, "must be");
 677       vopc = Op_OrReductionV;
 678       break;
 679     case Op_XorI:
 680       assert(bt == T_INT, "must be");
 681       vopc = Op_XorReductionV;
 682       break;
 683     case Op_XorL:
 684       assert(bt == T_LONG, "must be");
 685       vopc = Op_XorReductionV;
 686       break;
 687     case Op_SubI:
 688       assert(bt == T_INT, "must be");
 689       vopc = Op_SubReductionV;
 690       break;
 691     case Op_SubL:
 692       assert(bt == T_LONG, "must be");
 693       vopc = Op_SubReductionV;
 694       break;
 695     case Op_SubF:
 696       assert(bt == T_FLOAT, "must be");
 697       vopc = Op_SubReductionVF;
 698       break;
 699     case Op_SubD:
 700       assert(bt == T_DOUBLE, "must be");
 701       vopc = Op_SubReductionVF;
 702       break;
 703     // TODO: add MulL for targets that support it
 704     default:
 705       break;
 706   }
 707   return vopc;
 708 }
 709 
 710 // Return the appropriate reduction node.
 711 ReductionNode* ReductionNode::make(int opc, Node *ctrl, Node* n1, Node* n2, BasicType bt) {
 712 
 713   int vopc = opcode(opc, bt);
 714 
 715   // This method should not be called for unimplemented vectors.
 716   guarantee(vopc != opc, "Vector for '%s' is not implemented", NodeClassNames[opc]);
 717 
 718   switch (vopc) {
 719   case Op_AddReductionVI: return new AddReductionVINode(ctrl, n1, n2);
 720   case Op_AddReductionVL: return new AddReductionVLNode(ctrl, n1, n2);
 721   case Op_AddReductionVF: return new AddReductionVFNode(ctrl, n1, n2);
 722   case Op_AddReductionVD: return new AddReductionVDNode(ctrl, n1, n2);
 723   case Op_MulReductionVI: return new MulReductionVINode(ctrl, n1, n2);
 724   case Op_MulReductionVL: return new MulReductionVLNode(ctrl, n1, n2);
 725   case Op_MulReductionVF: return new MulReductionVFNode(ctrl, n1, n2);
 726   case Op_MulReductionVD: return new MulReductionVDNode(ctrl, n1, n2);
 727   case Op_AndReductionV: return new AndReductionVNode(ctrl, n1, n2);
 728   case Op_OrReductionV: return new OrReductionVNode(ctrl, n1, n2);
 729   case Op_XorReductionV: return new XorReductionVNode(ctrl, n1, n2);
 730   case Op_SubReductionV: return new SubReductionVNode(ctrl, n1, n2);
 731   case Op_SubReductionVF: return new SubReductionVFNode(ctrl, n1, n2);
 732   default:
 733     fatal("Missed vector creation for '%s'", NodeClassNames[vopc]);
 734     return NULL;
 735   }
 736 }
 737 
 738 Node* ReductionNode::make_reduction_input(PhaseGVN& gvn, int opc, BasicType bt) {
 739   int vopc = opcode(opc, bt);
 740   guarantee(vopc != opc, "Vector reduction for '%s' is not implemented", NodeClassNames[opc]);
 741 
 742   switch (vopc) {
 743     case Op_AndReductionV:
 744       switch (bt) {
 745         case T_BYTE:
 746         case T_SHORT:
 747         case T_INT:
 748           return gvn.makecon(TypeInt::MINUS_1);
 749         case T_LONG:
 750           return gvn.makecon(TypeLong::MINUS_1);
 751         default:
 752           fatal("Missed vector creation for '%s' as the basic type is not correct.", NodeClassNames[vopc]);
 753           return NULL;
 754       }
 755       break;
 756     case Op_AddReductionVI: // fallthrough
 757     case Op_AddReductionVL: // fallthrough
 758     case Op_AddReductionVF: // fallthrough
 759     case Op_AddReductionVD:
 760     case Op_OrReductionV:
 761     case Op_XorReductionV:
 762     case Op_SubReductionV:
 763     case Op_SubReductionVF:
 764       return gvn.zerocon(bt);
 765     case Op_MulReductionVI:
 766       return gvn.makecon(TypeInt::ONE);
 767     case Op_MulReductionVL:
 768       return gvn.makecon(TypeLong::ONE);
 769     case Op_MulReductionVF:
 770       return gvn.makecon(TypeF::ONE);
 771     case Op_MulReductionVD:
 772       return gvn.makecon(TypeD::ONE);
 773     default:
 774       fatal("Missed vector creation for '%s'", NodeClassNames[vopc]);
 775       return NULL;
 776   }
 777 }
 778 
 779 bool ReductionNode::implemented(int opc, uint vlen, BasicType bt) {
 780   if (is_java_primitive(bt) &&
 781       (vlen > 1) && is_power_of_2(vlen) &&
 782       Matcher::vector_size_supported(bt, vlen)) {
 783     int vopc = ReductionNode::opcode(opc, bt);
 784     return vopc != opc && Matcher::match_rule_supported(vopc);
 785   }
 786   return false;
 787 }
 788 
 789 #ifndef PRODUCT
 790 void VectorBoxAllocateNode::dump_spec(outputStream *st) const {
 791   CallStaticJavaNode::dump_spec(st);
 792 }
 793 
 794 void VectorMaskCmpNode::dump_spec(outputStream *st) const {
 795   st->print(" %d #", _predicate); _type->dump_on(st);
 796 }
 797 #endif // PRODUCT
 798 
 799 Node* VectorUnboxNode::Identity(PhaseGVN *phase) {
 800   Node* n = obj()->uncast();
 801   if (n->Opcode() == Op_VectorBox) {
 802     return n->in(VectorBoxNode::Value);
 803   }
 804   return this;
 805 }
 806 
 807 const TypeFunc* VectorBoxNode::vec_box_type(const TypeInstPtr* box_type) {
 808   const Type** fields = TypeTuple::fields(0);
 809   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms, fields);
 810 
 811   fields = TypeTuple::fields(1);
 812   fields[TypeFunc::Parms+0] = box_type;
 813   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
 814 
 815   return TypeFunc::make(domain, range);
 816 }
 817 
 818 Node* SubReductionVNode::Ideal(PhaseGVN* phase, bool can_reshape) {
 819   Node* ctrl = in(0);
 820   Node* in1 = in(1);
 821   Node* in2 = in(2);
 822 
 823   if (phase->type(in1)->isa_int()) {
 824                 assert(phase->type(in2)->is_vect()->element_type()->is_int(), "must be consistent");
 825     return new NegINode(phase->transform(new AddReductionVINode(ctrl,in1,in2)));
 826   } else if (phase->type(in1)->isa_long()) {
 827     return new NegLNode(phase->transform(new AddReductionVLNode(ctrl,in1,in2)));
 828   } else {
 829     Unimplemented();
 830     return NULL;
 831   } 
 832 }