RFR: 8256655: rework long counted loop handling

Tobias Hartmann thartmann at openjdk.java.net
Fri Nov 20 08:17:03 UTC 2020


On Thu, 19 Nov 2020 13:38:20 GMT, Roland Westrelin <roland at openjdk.org> wrote:

> Currently the transformation of a long counted loop into a loop nest
> with an inner int counted loop is performed in 2 steps:
> 
> 1- recognize the counted loop shape and build the loop nest
> 2- transform the inner loop into a counted loop
> 
> I propose changing this to a 3 steps process:
> 
> 1- recognize the counted loop shape (transform the loop into a LongCountedLoop)
> 2- build the loop nest
> 3- transform the inner loop into a counted loop
> 
> The benefits are:
> 
> - the logic is cleaner because step 1 and 2 are now separated
> - Simple optimizations (loop iv type, empty loop elimination, parallel
>   iv) can be implemented for LongCountedLoop by refactoring existing
>   code
> 
> 1- above is achieved by refactoring the
> PhaseIdealLoop::is_counted_loop() so it takes an extra parameter (the
> kind of counted loop, int or long).
> 
> 2- is the existing loop nest construction logic. But now that it takes
> a LongCountedLoop as input, the shape of the loop is known to be that
> of a canonicalized counted loop. As a result, the loop nest
> construction is simpler.
> 
> This change also refactors PhiNode::Value() so that it works for both
> CountedLoop and LongCountedLoop.
> 
> I also changed ConvL2INode to be a TypeNode (ConvI2LNode is a type
> node) and:
> 
>     jlong init_p = (jlong)init_t->_lo + stride_con;
>     if (init_p > (jlong)max_jint || init_p > (jlong)limit_t->_hi)
>       return false; // cyclic loop or this loop trips only once
> 
> to:
> 
>     if (init_t->lo_as_long() > max_signed_integer(iv_bt) - stride_con) {
> 
> because if the loop has a single iteration transforming it to a
> CountedLoop should allow the backedge to be optimized out.

This fails to build on Windows:
`
[2020-11-20T08:11:03,704Z] ./open/src/hotspot/share/opto/loopnode.cpp(821): error C2065: 'ulong': undeclared identifier
[2020-11-20T08:11:03,704Z] ./open/src/hotspot/share/opto/loopnode.cpp(821): error C2146: syntax error: missing ')' before identifier 'iters_limit'
[2020-11-20T08:11:03,704Z] ./open/src/hotspot/share/opto/loopnode.cpp(821): error C2146: syntax error: missing ';' before identifier 'iters_limit'
[2020-11-20T08:11:03,704Z] ./open/src/hotspot/share/opto/loopnode.cpp(821): error C2065: 'ulong': undeclared identifier
[2020-11-20T08:11:03,704Z] ./open/src/hotspot/share/opto/loopnode.cpp(821): error C2059: syntax error: ')'`

-------------

Changes requested by thartmann (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/1316


More information about the hotspot-compiler-dev mailing list