1.1 --- a/src/share/vm/c1/c1_Canonicalizer.cpp Wed Sep 24 09:49:47 2014 +0200 1.2 +++ b/src/share/vm/c1/c1_Canonicalizer.cpp Tue Sep 23 15:09:07 2014 -0700 1.3 @@ -327,7 +327,7 @@ 1.4 if (t2->is_constant()) { 1.5 switch (t2->tag()) { 1.6 case intTag : if (t2->as_IntConstant()->value() == 0) set_canonical(x->x()); return; 1.7 - case longTag : if (t2->as_IntConstant()->value() == 0) set_canonical(x->x()); return; 1.8 + case longTag : if (t2->as_LongConstant()->value() == (jlong)0) set_canonical(x->x()); return; 1.9 default : ShouldNotReachHere(); 1.10 } 1.11 } 1.12 @@ -808,28 +808,41 @@ 1.13 1.14 static bool match_index_and_scale(Instruction* instr, 1.15 Instruction** index, 1.16 - int* log2_scale, 1.17 - Instruction** instr_to_unpin) { 1.18 - *instr_to_unpin = NULL; 1.19 - 1.20 - // Skip conversion ops 1.21 + int* log2_scale) { 1.22 + // Skip conversion ops. This works only on 32bit because of the implicit l2i that the 1.23 + // unsafe performs. 1.24 +#ifndef _LP64 1.25 Convert* convert = instr->as_Convert(); 1.26 - if (convert != NULL) { 1.27 + if (convert != NULL && convert->op() == Bytecodes::_i2l) { 1.28 + assert(convert->value()->type() == intType, "invalid input type"); 1.29 instr = convert->value(); 1.30 } 1.31 +#endif 1.32 1.33 ShiftOp* shift = instr->as_ShiftOp(); 1.34 if (shift != NULL) { 1.35 - if (shift->is_pinned()) { 1.36 - *instr_to_unpin = shift; 1.37 + if (shift->op() == Bytecodes::_lshl) { 1.38 + assert(shift->x()->type() == longType, "invalid input type"); 1.39 + } else { 1.40 +#ifndef _LP64 1.41 + if (shift->op() == Bytecodes::_ishl) { 1.42 + assert(shift->x()->type() == intType, "invalid input type"); 1.43 + } else { 1.44 + return false; 1.45 + } 1.46 +#else 1.47 + return false; 1.48 +#endif 1.49 } 1.50 + 1.51 + 1.52 // Constant shift value? 1.53 Constant* con = shift->y()->as_Constant(); 1.54 if (con == NULL) return false; 1.55 // Well-known type and value? 1.56 IntConstant* val = con->type()->as_IntConstant(); 1.57 - if (val == NULL) return false; 1.58 - if (shift->x()->type() != intType) return false; 1.59 + assert(val != NULL, "Should be an int constant"); 1.60 + 1.61 *index = shift->x(); 1.62 int tmp_scale = val->value(); 1.63 if (tmp_scale >= 0 && tmp_scale < 4) { 1.64 @@ -842,31 +855,42 @@ 1.65 1.66 ArithmeticOp* arith = instr->as_ArithmeticOp(); 1.67 if (arith != NULL) { 1.68 - if (arith->is_pinned()) { 1.69 - *instr_to_unpin = arith; 1.70 + // See if either arg is a known constant 1.71 + Constant* con = arith->x()->as_Constant(); 1.72 + if (con != NULL) { 1.73 + *index = arith->y(); 1.74 + } else { 1.75 + con = arith->y()->as_Constant(); 1.76 + if (con == NULL) return false; 1.77 + *index = arith->x(); 1.78 } 1.79 + long const_value; 1.80 // Check for integer multiply 1.81 - if (arith->op() == Bytecodes::_imul) { 1.82 - // See if either arg is a known constant 1.83 - Constant* con = arith->x()->as_Constant(); 1.84 - if (con != NULL) { 1.85 - *index = arith->y(); 1.86 + if (arith->op() == Bytecodes::_lmul) { 1.87 + assert((*index)->type() == longType, "invalid input type"); 1.88 + LongConstant* val = con->type()->as_LongConstant(); 1.89 + assert(val != NULL, "expecting a long constant"); 1.90 + const_value = val->value(); 1.91 + } else { 1.92 +#ifndef _LP64 1.93 + if (arith->op() == Bytecodes::_imul) { 1.94 + assert((*index)->type() == intType, "invalid input type"); 1.95 + IntConstant* val = con->type()->as_IntConstant(); 1.96 + assert(val != NULL, "expecting an int constant"); 1.97 + const_value = val->value(); 1.98 } else { 1.99 - con = arith->y()->as_Constant(); 1.100 - if (con == NULL) return false; 1.101 - *index = arith->x(); 1.102 + return false; 1.103 } 1.104 - if ((*index)->type() != intType) return false; 1.105 - // Well-known type and value? 1.106 - IntConstant* val = con->type()->as_IntConstant(); 1.107 - if (val == NULL) return false; 1.108 - switch (val->value()) { 1.109 - case 1: *log2_scale = 0; return true; 1.110 - case 2: *log2_scale = 1; return true; 1.111 - case 4: *log2_scale = 2; return true; 1.112 - case 8: *log2_scale = 3; return true; 1.113 - default: return false; 1.114 - } 1.115 +#else 1.116 + return false; 1.117 +#endif 1.118 + } 1.119 + switch (const_value) { 1.120 + case 1: *log2_scale = 0; return true; 1.121 + case 2: *log2_scale = 1; return true; 1.122 + case 4: *log2_scale = 2; return true; 1.123 + case 8: *log2_scale = 3; return true; 1.124 + default: return false; 1.125 } 1.126 } 1.127 1.128 @@ -879,29 +903,37 @@ 1.129 Instruction** base, 1.130 Instruction** index, 1.131 int* log2_scale) { 1.132 - Instruction* instr_to_unpin = NULL; 1.133 ArithmeticOp* root = x->base()->as_ArithmeticOp(); 1.134 if (root == NULL) return false; 1.135 // Limit ourselves to addition for now 1.136 if (root->op() != Bytecodes::_ladd) return false; 1.137 + 1.138 + bool match_found = false; 1.139 // Try to find shift or scale op 1.140 - if (match_index_and_scale(root->y(), index, log2_scale, &instr_to_unpin)) { 1.141 + if (match_index_and_scale(root->y(), index, log2_scale)) { 1.142 *base = root->x(); 1.143 - } else if (match_index_and_scale(root->x(), index, log2_scale, &instr_to_unpin)) { 1.144 + match_found = true; 1.145 + } else if (match_index_and_scale(root->x(), index, log2_scale)) { 1.146 *base = root->y(); 1.147 - } else if (root->y()->as_Convert() != NULL) { 1.148 + match_found = true; 1.149 + } else if (NOT_LP64(root->y()->as_Convert() != NULL) LP64_ONLY(false)) { 1.150 + // Skipping i2l works only on 32bit because of the implicit l2i that the unsafe performs. 1.151 + // 64bit needs a real sign-extending conversion. 1.152 Convert* convert = root->y()->as_Convert(); 1.153 - if (convert->op() == Bytecodes::_i2l && convert->value()->type() == intType) { 1.154 + if (convert->op() == Bytecodes::_i2l) { 1.155 + assert(convert->value()->type() == intType, "should be an int"); 1.156 // pick base and index, setting scale at 1 1.157 *base = root->x(); 1.158 *index = convert->value(); 1.159 *log2_scale = 0; 1.160 - } else { 1.161 - return false; 1.162 + match_found = true; 1.163 } 1.164 - } else { 1.165 - // doesn't match any expected sequences 1.166 - return false; 1.167 + } 1.168 + // The default solution 1.169 + if (!match_found) { 1.170 + *base = root->x(); 1.171 + *index = root->y(); 1.172 + *log2_scale = 0; 1.173 } 1.174 1.175 // If the value is pinned then it will be always be computed so