Integrated: 8266798: C1: More types of instruction can also apply LoopInvariantCodeMotion

Yi Yang yyang at openjdk.java.net
Wed May 12 09:10:57 UTC 2021


On Tue, 11 May 2021 02:26:04 GMT, Yi Yang <yyang at openjdk.org> wrote:

> C1 only applies LoopInvariantCodeMotion for instructions whose types are Constant/ArithmeticOp/LoadField/ArrayLength/LoadIndexed. We are possible to apply this optimization for more types of instruction.
> 
> Candidates: NegateOp,Convert.
> 
> Due to the lack of verification at IR level, it is difficult to write jtreg to check if it transformed, so I can only demonstrate it with a simple program:
> 
> // run with -XX:+PrintValueNumbering
> static int foo10(int t){
>     int sum=12;
>     for(int i=0;i<100;i++){
>         sum += 12;
>         sum += -t;
>         sum += (long)t;
>     }
>     return sum;
> }
> 
> Before:
> 
> [...]
> * loop invariant code motion for short loop B1
> processing block B1
> Value Numbering: insert Constant i10  (size 11, entries 3, nesting 2)
> Instruction i10 is loop invariant
> processing block B2
> Value Numbering: Constant i12 equal to i5  (size 11, entries 3, nesting-diff 1)
> substitution for 12 set to 5
> Instruction i12 is loop invariant   // only 12 is recongized
> Value Numbering: insert Constant i20  (size 11, entries 4, nesting 2)
> Instruction i20 is loop invariant
> ** loop successfully optimized
> [...]
> 
> After:
> 
> [...]
> ** loop invariant code motion for short loop B1
> processing block B1
> Value Numbering: insert Constant i10  (size 11, entries 3, nesting 2)
> Instruction i10 is loop invariant
>   6    0    i10    100
> processing block B2
> Value Numbering: Constant i12 equal to i5  (size 11, entries 3, nesting-diff 1)
> substitution for i12 set to 105
> Instruction i12 is loop invariant
>   11   0    i12    12
> Instruction i14 is loop invariant
> . 16   0    i14    -i4
> Value Numbering: insert Convert l17  (size 11, entries 4, nesting 2)
> Instruction l17 is loop invariant
> . 22   0    l17    i2l(i4)
> Value Numbering: insert Constant i20  (size 11, entries 5, nesting 2)
> Instruction i20 is loop invariant
>   26   0    i20    1
> [...]

This pull request has now been integrated.

Changeset: 11759bfb
Author:    Yi Yang <yyang at openjdk.org>
Committer: Tobias Hartmann <thartmann at openjdk.org>
URL:       https://git.openjdk.java.net/jdk/commit/11759bfb2d8e0208ad56f9ad5a425067e66c2bc0
Stats:     11 lines in 1 file changed: 7 ins; 3 del; 1 mod

8266798: C1: More types of instruction can also apply LoopInvariantCodeMotion

Reviewed-by: thartmann, neliasso

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

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


More information about the hotspot-compiler-dev mailing list