Skip to content

Commit

Permalink
8258946: Fix optimization-unstable code involving signed integer over…
Browse files Browse the repository at this point in the history
…flow

Backport-of: dd8996c
  • Loading branch information
GoeLin committed Jul 28, 2022
1 parent 5d20cb6 commit c61acb5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/hotspot/share/opto/ifnode.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -633,15 +633,15 @@ const TypeInt* IfNode::filtered_int_type(PhaseGVN* gvn, Node *val, Node* if_proj
return cmp2_t;
case BoolTest::lt:
lo = TypeInt::INT->_lo;
if (hi - 1 < hi) {
if (hi != min_jint) {
hi = hi - 1;
}
break;
case BoolTest::le:
lo = TypeInt::INT->_lo;
break;
case BoolTest::gt:
if (lo + 1 > lo) {
if (lo != max_jint) {
lo = lo + 1;
}
hi = TypeInt::INT->_hi;
Expand Down
10 changes: 5 additions & 5 deletions src/hotspot/share/opto/loopTransform.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -824,12 +824,12 @@ bool IdealLoopTree::policy_unroll(PhaseIdealLoop *phase) {
const TypeInt* iv_type = phase->_igvn.type(phi)->is_int();
int next_stride = stride_con * 2; // stride after this unroll
if (next_stride > 0) {
if (iv_type->_lo + next_stride <= iv_type->_lo || // overflow
if (iv_type->_lo > max_jint - next_stride || // overflow
iv_type->_lo + next_stride > iv_type->_hi) {
return false; // over-unrolling
}
} else if (next_stride < 0) {
if (iv_type->_hi + next_stride >= iv_type->_hi || // overflow
if (iv_type->_hi < min_jint - next_stride || // overflow
iv_type->_hi + next_stride < iv_type->_lo) {
return false; // over-unrolling
}
Expand All @@ -840,8 +840,8 @@ bool IdealLoopTree::policy_unroll(PhaseIdealLoop *phase) {
// After unroll limit will be adjusted: new_limit = limit-stride.
// Bailout if adjustment overflow.
const TypeInt* limit_type = phase->_igvn.type(limit_n)->is_int();
if ((stride_con > 0 && ((limit_type->_hi - stride_con) >= limit_type->_hi)) ||
(stride_con < 0 && ((limit_type->_lo - stride_con) <= limit_type->_lo)))
if ((stride_con > 0 && ((min_jint + stride_con) > limit_type->_hi)) ||
(stride_con < 0 && ((max_jint + stride_con) < limit_type->_lo)))
return false; // overflow

// Adjust body_size to determine if we unroll or not
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/opto/parse2.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -548,7 +548,7 @@ void Parse::do_lookupswitch() {
}
prev = match_int+1;
}
if (prev-1 != max_jint) {
if (prev != min_jint) {
defaults += (float)max_jint - prev + 1;
}
float default_cnt = 1;
Expand Down

1 comment on commit c61acb5

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.