From e8584412045158a69463c5d6022a25a9084a8be0 Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Fri, 15 Nov 2024 15:22:13 +0530 Subject: [PATCH] add safety net --- src/hotspot/cpu/riscv/c1_LIRGenerator_riscv.cpp | 2 +- src/hotspot/cpu/s390/c1_LIRGenerator_s390.cpp | 2 +- src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp | 2 +- src/hotspot/share/c1/c1_LIRGenerator.cpp | 14 ++++++++------ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/hotspot/cpu/riscv/c1_LIRGenerator_riscv.cpp b/src/hotspot/cpu/riscv/c1_LIRGenerator_riscv.cpp index b328d457192ba..07e0d467c876f 100644 --- a/src/hotspot/cpu/riscv/c1_LIRGenerator_riscv.cpp +++ b/src/hotspot/cpu/riscv/c1_LIRGenerator_riscv.cpp @@ -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); diff --git a/src/hotspot/cpu/s390/c1_LIRGenerator_s390.cpp b/src/hotspot/cpu/s390/c1_LIRGenerator_s390.cpp index f998e86256f56..8bc4f57fdeb48 100644 --- a/src/hotspot/cpu/s390/c1_LIRGenerator_s390.cpp +++ b/src/hotspot/cpu/s390/c1_LIRGenerator_s390.cpp @@ -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; } } diff --git a/src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp b/src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp index 36e2021138f2e..4d5b99280a5de 100644 --- a/src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp +++ b/src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp @@ -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); diff --git a/src/hotspot/share/c1/c1_LIRGenerator.cpp b/src/hotspot/share/c1/c1_LIRGenerator.cpp index 74fdf7a5b76a3..aee5489c66846 100644 --- a/src/hotspot/share/c1/c1_LIRGenerator.cpp +++ b/src/hotspot/share/c1/c1_LIRGenerator.cpp @@ -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