JDK-8043284 : Optimize signed integer comparison
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2014-05-15
  • Updated: 2014-09-04
  • Resolved: 2014-08-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b29Fixed
Related Reports
Relates :  
Relates :  
Description
JDK-8042786 changes implemented optimization for unsigned integer comparison when one of input is AddI or SubI and its int type can be represented as set of type regions.

This optimization might also be beneficial on some signed comparisons, notably (r1+r2)==0 where r1 and r2 are both [1..maxint].

The problem rise when result of AddI(SubI) may overflow signed integer value.
Let say the input type is [256, maxint] then adding +128 will create 2 ranges due to
overflow: [minint, minint+127] and [384, maxint].
C2 type system keep only 1 type range and as result it use general [minint, maxint] type
for this case which we can't optimize.

Make 2 separate type ranges based on types of AddI(SubI) inputs and compare results of their compare. If results are the same CmpI node can be optimized. Note, only signed equality can be optimized this way.

Comments
You need to optimize BoolNode (EQ or NE) in this case. You can replace it with true of false.
14-07-2014

I don't understand how the optmization is feasible for signed integer comparison. For example if we have (r1 + r2) == c with r1 = [a, MAX] r2 = [b] We get the following two ranges for (r1 + r2): Overflow: range1 = [MIN, MIN + b - 1] No overflow: range2 = [a + b, MAX] Now it is not possible that cmp(range1, c) and cmp(range2, c) return the same value because MIN <= range1 < range2 <= MAX. For example, if c == MAX then range1 < c and range2 <= c. The only case where we could optimize is if range1 < c < range2. But this is not feasible either as we do not have a not-equal condition code type to state that range1 != c and range2 != c The optimization is only possible for an unsigned compare where a negative number is treated as a positive (see JDK-8042786).
20-06-2014