diff --git a/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp b/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp index ca3750733131a..0e7a82714b724 100644 --- a/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp +++ b/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp @@ -1049,9 +1049,9 @@ C2V_END C2V_VMENTRY_0(jlong, getMaxCallTargetOffset, (JNIEnv* env, jobject, jlong addr)) address target_addr = (address) addr; if (target_addr != 0x0) { - int64_t off_low = (int64_t)target_addr - ((int64_t)CodeCache::low_bound() + sizeof(int)); - int64_t off_high = (int64_t)target_addr - ((int64_t)CodeCache::high_bound() + sizeof(int)); - return MAX2(ABS(off_low), ABS(off_high)); + jlong off_low = (jlong)(target_addr - (CodeCache::low_bound() + sizeof(int))); + jlong off_high = (jlong)(target_addr - (CodeCache::high_bound() + sizeof(int))); + return checked_cast(MAX2(uabs(off_low), uabs(off_high))); } return -1; C2V_END diff --git a/src/hotspot/share/opto/divnode.cpp b/src/hotspot/share/opto/divnode.cpp index 9c6c6ed25dec2..f258a464edc57 100644 --- a/src/hotspot/share/opto/divnode.cpp +++ b/src/hotspot/share/opto/divnode.cpp @@ -54,7 +54,7 @@ static bool magic_int_divide_constants(jint d, jint &M, jint &s) { uint32_t ad, anc, delta, q1, r1, q2, r2, t; const uint32_t two31 = 0x80000000L; // 2**31. - ad = ABS(d); + ad = uabs(d); if (d == 0 || d == 1) return false; t = two31 + ((uint32_t)d >> 31); anc = t - 1 - t%ad; // Absolute value of nc. @@ -222,7 +222,7 @@ static bool magic_long_divide_constants(jlong d, jlong &M, jint &s) { uint64_t ad, anc, delta, q1, r1, q2, r2, t; const uint64_t two63 = UCONST64(0x8000000000000000); // 2**63. - ad = ABS(d); + ad = uabs(d); if (d == 0 || d == 1) return false; t = two63 + ((uint64_t)d >> 63); anc = t - 1 - t%ad; // Absolute value of nc. diff --git a/src/hotspot/share/opto/ifnode.cpp b/src/hotspot/share/opto/ifnode.cpp index 6ae62b24b3c8d..dd23258dd5998 100644 --- a/src/hotspot/share/opto/ifnode.cpp +++ b/src/hotspot/share/opto/ifnode.cpp @@ -1937,7 +1937,7 @@ Node* RangeCheckNode::Ideal(PhaseGVN *phase, bool can_reshape) { // the argument above still holds. // // Note that the same optimization with the same maximal accepted interval size can also be found in C1. - const jlong maximum_number_of_min_max_interval_indices = (jlong)max_jint; + const julong maximum_number_of_min_max_interval_indices = (julong)max_jint; // The top 3 range checks seen const int NRC = 3; @@ -1975,7 +1975,7 @@ Node* RangeCheckNode::Ideal(PhaseGVN *phase, bool can_reshape) { // "x - y" -> must add one to the difference for number of elements in [x,y] const jlong diff = (jlong)MIN2(offset2, off_lo) - (jlong)MAX2(offset2, off_hi); - if (ABS(diff) < maximum_number_of_min_max_interval_indices) { + if (uabs(diff) < maximum_number_of_min_max_interval_indices) { // Gather expanded bounds off_lo = MIN2(off_lo, offset2); off_hi = MAX2(off_hi, offset2); diff --git a/src/hotspot/share/opto/loopPredicate.cpp b/src/hotspot/share/opto/loopPredicate.cpp index fd0576832cf70..6d05dfe7f506e 100644 --- a/src/hotspot/share/opto/loopPredicate.cpp +++ b/src/hotspot/share/opto/loopPredicate.cpp @@ -957,7 +957,7 @@ bool PhaseIdealLoop::loop_predication_should_follow_branches(IdealLoopTree* loop CountedLoopNode* cl = head->as_CountedLoop(); if (cl->phi() != nullptr) { const TypeInt* t = _igvn.type(cl->phi())->is_int(); - float worst_case_trip_cnt = ((float)t->_hi - t->_lo) / ABS(cl->stride_con()); + float worst_case_trip_cnt = ((float)t->_hi - t->_lo) / uabs(cl->stride_con()); if (worst_case_trip_cnt < loop_trip_cnt) { loop_trip_cnt = worst_case_trip_cnt; } diff --git a/src/hotspot/share/opto/loopTransform.cpp b/src/hotspot/share/opto/loopTransform.cpp index b9e14f595c2fd..bc2e9325d28b9 100644 --- a/src/hotspot/share/opto/loopTransform.cpp +++ b/src/hotspot/share/opto/loopTransform.cpp @@ -2486,7 +2486,7 @@ void PhaseIdealLoop::add_constraint(jlong stride_con, jlong scale_con, Node* off // If the absolute scale value is greater one, division in 'adjust_limit' may require // rounding. Make sure the ABS method correctly handles min_jint. // Only do this for the pre-loop, one less iteration of the main loop doesn't hurt. - bool round = ABS(scale_con) > 1; + bool round = uabs(scale_con) > 1; Node* scale = _igvn.longcon(scale_con); set_ctrl(scale, C->root()); diff --git a/src/hotspot/share/opto/loopnode.cpp b/src/hotspot/share/opto/loopnode.cpp index fdfbab09b8fe8..3cb8a204fa85b 100644 --- a/src/hotspot/share/opto/loopnode.cpp +++ b/src/hotspot/share/opto/loopnode.cpp @@ -802,14 +802,14 @@ bool PhaseIdealLoop::create_loop_nest(IdealLoopTree* loop, Node_List &old_new) { // The number of iterations for the integer count loop: guarantee no // overflow: max_jint - stride_con max. -1 so there's no need for a // loop limit check if the exit test is <= or >=. - int iters_limit = max_jint - ABS(stride_con) - 1; + int iters_limit = max_jint - uabs(stride_con) - 1; #ifdef ASSERT if (bt == T_LONG && StressLongCountedLoop > 0) { iters_limit = iters_limit / StressLongCountedLoop; } #endif // At least 2 iterations so counted loop construction doesn't fail - if (iters_limit/ABS(stride_con) < 2) { + if (iters_limit/uabs(stride_con) < 2) { return false; } @@ -1106,8 +1106,8 @@ int PhaseIdealLoop::extract_long_range_checks(const IdealLoopTree* loop, jlong s jlong scale = 0; if (loop->is_range_check_if(if_proj, this, T_LONG, phi, range, offset, scale) && loop->is_invariant(range) && loop->is_invariant(offset) && - original_iters_limit / ABS(scale * stride_con) >= min_iters) { - reduced_iters_limit = MIN2(reduced_iters_limit, original_iters_limit/ABS(scale)); + original_iters_limit / uabs(scale * stride_con) >= min_iters) { + reduced_iters_limit = MIN2(reduced_iters_limit, checked_cast(original_iters_limit / uabs(scale))); range_checks.push(c); } } @@ -2341,7 +2341,7 @@ Node* PhaseIdealLoop::exact_limit( IdealLoopTree *loop ) { CountedLoopNode *cl = loop->_head->as_CountedLoop(); assert(cl->is_valid_counted_loop(T_INT), ""); - if (ABS(cl->stride_con()) == 1 || + if (uabs(cl->stride_con()) == 1 || cl->limit()->Opcode() == Op_LoopLimit) { // Old code has exact limit (it could be incorrect in case of int overflow). // Loop limit is exact with stride == 1. And loop may already have exact limit. @@ -2559,20 +2559,18 @@ Node *LoopLimitNode::Ideal(PhaseGVN *phase, bool can_reshape) { const TypeInt* init_t = phase->type(in(Init) )->is_int(); const TypeInt* limit_t = phase->type(in(Limit))->is_int(); - int stride_p; jlong lim, ini; julong max; if (stride_con > 0) { - stride_p = stride_con; lim = limit_t->_hi; ini = init_t->_lo; max = (julong)max_jint; } else { - stride_p = -stride_con; lim = init_t->_hi; ini = limit_t->_lo; max = (julong)min_jint; } + uint stride_p = uabs(stride_con); julong range = lim - ini + stride_p; if (range <= max) { // Convert to integer expression if it is not overflow. @@ -2951,9 +2949,9 @@ void OuterStripMinedLoopNode::adjust_strip_mined_loop(PhaseIterGVN* igvn) { CountedLoopEndNode* inner_cle = inner_cl->loopexit(); int stride = inner_cl->stride_con(); - jlong scaled_iters_long = ((jlong)LoopStripMiningIter) * ABS(stride); + jlong scaled_iters_long = ((jlong)LoopStripMiningIter) * uabs(stride); int scaled_iters = (int)scaled_iters_long; - int short_scaled_iters = LoopStripMiningIterShortLoop* ABS(stride); + int short_scaled_iters = LoopStripMiningIterShortLoop * uabs(stride); const TypeInt* inner_iv_t = igvn->type(inner_iv_phi)->is_int(); jlong iter_estimate = (jlong)inner_iv_t->_hi - (jlong)inner_iv_t->_lo; assert(iter_estimate > 0, "broken"); diff --git a/src/hotspot/share/opto/superword.hpp b/src/hotspot/share/opto/superword.hpp index 8813284e35140..11b9dbed0cd47 100644 --- a/src/hotspot/share/opto/superword.hpp +++ b/src/hotspot/share/opto/superword.hpp @@ -326,7 +326,7 @@ class SuperWord : public ResourceObj { int vector_width(const Node* n) const { BasicType bt = velt_basic_type(n); - return MIN2(ABS(iv_stride()), Matcher::max_vector_size(bt)); + return MIN2(checked_cast(uabs(iv_stride())), Matcher::max_vector_size(bt)); } int vector_width_in_bytes(const Node* n) const { BasicType bt = velt_basic_type(n); diff --git a/src/hotspot/share/utilities/globalDefinitions.hpp b/src/hotspot/share/utilities/globalDefinitions.hpp index c0f5b71966662..d84ec2dead6f3 100644 --- a/src/hotspot/share/utilities/globalDefinitions.hpp +++ b/src/hotspot/share/utilities/globalDefinitions.hpp @@ -1109,8 +1109,6 @@ template constexpr T MIN3(T a, T b, T c) { return MIN2(MIN2(a, b), template constexpr T MAX4(T a, T b, T c, T d) { return MAX2(MAX3(a, b, c), d); } template constexpr T MIN4(T a, T b, T c, T d) { return MIN2(MIN3(a, b, c), d); } -template inline T ABS(T x) { return (x > 0) ? x : -x; } - // Return the given value clamped to the range [min ... max] template inline T clamp(T value, T min, T max) {