< prev index next >

src/hotspot/share/c1/c1_Canonicalizer.cpp

Print this page
rev 56798 : [mq]: do_ShiftOp
   1 /*
   2  * Copyright (c) 1999, 2018, 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  *


 337       default       : ShouldNotReachHere();
 338     }
 339   }
 340 }
 341 
 342 
 343 void Canonicalizer::do_ArithmeticOp   (ArithmeticOp*    x) { do_Op2(x); }
 344 
 345 
 346 void Canonicalizer::do_ShiftOp        (ShiftOp*         x) {
 347   ValueType* t = x->x()->type();
 348   ValueType* t2 = x->y()->type();
 349   if (t->is_constant()) {
 350     switch (t->tag()) {
 351     case intTag   : if (t->as_IntConstant()->value() == 0)         { set_constant(0); return; } break;
 352     case longTag  : if (t->as_LongConstant()->value() == (jlong)0) { set_constant(jlong_cast(0)); return; } break;
 353     default       : ShouldNotReachHere();
 354     }
 355     if (t2->is_constant()) {
 356       if (t->tag() == intTag) {
 357         int value = t->as_IntConstant()->value();
 358         int shift = t2->as_IntConstant()->value() & 31;
 359         jint mask = ~(~0 << (32 - shift));
 360         if (shift == 0) mask = ~0;
 361         switch (x->op()) {
 362           case Bytecodes::_ishl:  set_constant(value << shift); return;
 363           case Bytecodes::_ishr:  set_constant(value >> shift); return;
 364           case Bytecodes::_iushr: set_constant((value >> shift) & mask); return;
 365           default:                break;
 366         }
 367       } else if (t->tag() == longTag) {
 368         jlong value = t->as_LongConstant()->value();
 369         int shift = t2->as_IntConstant()->value() & 63;
 370         jlong mask = ~(~jlong_cast(0) << (64 - shift));
 371         if (shift == 0) mask = ~jlong_cast(0);
 372         switch (x->op()) {
 373           case Bytecodes::_lshl:  set_constant(value << shift); return;
 374           case Bytecodes::_lshr:  set_constant(value >> shift); return;
 375           case Bytecodes::_lushr: set_constant((value >> shift) & mask); return;
 376           default:                break;
 377         }
 378       }
 379     }
 380   }
 381   if (t2->is_constant()) {
 382     switch (t2->tag()) {
 383       case intTag   : if (t2->as_IntConstant()->value() == 0)  set_canonical(x->x()); return;
 384       case longTag  : if (t2->as_LongConstant()->value() == (jlong)0)  set_canonical(x->x()); return;
 385       default       : ShouldNotReachHere(); return;
 386     }
 387   }
 388 }
 389 
 390 
 391 void Canonicalizer::do_LogicOp        (LogicOp*         x) { do_Op2(x); }
 392 void Canonicalizer::do_CompareOp      (CompareOp*       x) {
 393   if (x->x() == x->y()) {
 394     switch (x->x()->type()->tag()) {
 395       case longTag: set_constant(0); break;


   1 /*
   2  * Copyright (c) 1999, 2019, 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  *


 337       default       : ShouldNotReachHere();
 338     }
 339   }
 340 }
 341 
 342 
 343 void Canonicalizer::do_ArithmeticOp   (ArithmeticOp*    x) { do_Op2(x); }
 344 
 345 
 346 void Canonicalizer::do_ShiftOp        (ShiftOp*         x) {
 347   ValueType* t = x->x()->type();
 348   ValueType* t2 = x->y()->type();
 349   if (t->is_constant()) {
 350     switch (t->tag()) {
 351     case intTag   : if (t->as_IntConstant()->value() == 0)         { set_constant(0); return; } break;
 352     case longTag  : if (t->as_LongConstant()->value() == (jlong)0) { set_constant(jlong_cast(0)); return; } break;
 353     default       : ShouldNotReachHere();
 354     }
 355     if (t2->is_constant()) {
 356       if (t->tag() == intTag) {
 357         jint value = t->as_IntConstant()->value();
 358         jint shift = t2->as_IntConstant()->value();


 359         switch (x->op()) {
 360           case Bytecodes::_ishl:  set_constant(java_shift_left(value, shift)); return;
 361           case Bytecodes::_ishr:  set_constant(java_shift_right(value, shift)); return;
 362           case Bytecodes::_iushr: set_constant(java_shift_right_unsigned(value, shift)); return;
 363           default:                break;
 364         }
 365       } else if (t->tag() == longTag) {
 366         jlong value = t->as_LongConstant()->value();
 367         jint shift = t2->as_IntConstant()->value();


 368         switch (x->op()) {
 369           case Bytecodes::_lshl:  set_constant(java_shift_left(value, shift)); return;
 370           case Bytecodes::_lshr:  set_constant(java_shift_right(value, shift)); return;
 371           case Bytecodes::_lushr: set_constant(java_shift_right_unsigned(value, shift)); return;
 372           default:                break;
 373         }
 374       }
 375     }
 376   }
 377   if (t2->is_constant()) {
 378     switch (t2->tag()) {
 379       case intTag   : if (t2->as_IntConstant()->value() == 0)  set_canonical(x->x()); return;
 380       case longTag  : if (t2->as_LongConstant()->value() == (jlong)0)  set_canonical(x->x()); return;
 381       default       : ShouldNotReachHere(); return;
 382     }
 383   }
 384 }
 385 
 386 
 387 void Canonicalizer::do_LogicOp        (LogicOp*         x) { do_Op2(x); }
 388 void Canonicalizer::do_CompareOp      (CompareOp*       x) {
 389   if (x->x() == x->y()) {
 390     switch (x->x()->type()->tag()) {
 391       case longTag: set_constant(0); break;


< prev index next >