Skip to content

Commit

Permalink
add safety net
Browse files Browse the repository at this point in the history
  • Loading branch information
offamitkumar committed Nov 15, 2024
1 parent 2b57f40 commit e858441
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/hotspot/cpu/riscv/c1_LIRGenerator_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ void LIRGenerator::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr bas
}

bool LIRGenerator::strength_reduce_multiply(LIR_Opr left, jint c, LIR_Opr result, LIR_Opr tmp) {
if (tmp->is_valid() && c > 0 && c < max_jint) {
if (tmp->is_valid()) {
if (is_power_of_2(c - 1)) {
__ shift_left(left, exact_log2(c - 1), tmp);
__ add(tmp, left, result);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/s390/c1_LIRGenerator_s390.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ void LIRGenerator::do_ArithmeticOp_Int(ArithmeticOp* x) {
bool use_tmp = false;
if (right_arg->is_constant()) {
int iconst = right_arg->get_jint_constant();
if (is_power_of_2(iconst - 1) || is_power_of_2(iconst + 1)) {
if (iconst > 0 && iconst < max_jint && (is_power_of_2(iconst - 1) || is_power_of_2(iconst + 1))) {
use_tmp = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ void LIRGenerator::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr bas


bool LIRGenerator::strength_reduce_multiply(LIR_Opr left, jint c, LIR_Opr result, LIR_Opr tmp) {
if (tmp->is_valid() && c > 0 && c < max_jint) {
if (tmp->is_valid()) {
if (is_power_of_2(c + 1)) {
__ move(left, tmp);
__ shift_left(left, log2i_exact(c + 1), left);
Expand Down
14 changes: 8 additions & 6 deletions src/hotspot/share/c1/c1_LIRGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,12 +530,14 @@ void LIRGenerator::arithmetic_op(Bytecodes::Code code, LIR_Opr result, LIR_Opr l

if (right->is_constant()) {
jint c = right->as_jint();
if (c > 0 && is_power_of_2(c)) {
// do not need tmp here
__ shift_left(left_op, exact_log2(c), result_op);
did_strength_reduce = true;
} else {
did_strength_reduce = strength_reduce_multiply(left_op, c, result_op, tmp_op);
if (c > 0 && c < max_jint) {
if (is_power_of_2(c)) {
// do not need tmp here
__ shift_left(left_op, exact_log2(c), result_op);
did_strength_reduce = true;
} else {
did_strength_reduce = strength_reduce_multiply(left_op, c, result_op, tmp_op);
}
}
}
// we couldn't strength reduce so just emit the multiply
Expand Down

0 comments on commit e858441

Please sign in to comment.