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

Tobias Hartmann thartmann at openjdk.java.net
Tue May 11 09:47: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
> [...]

Changes requested by thartmann (Reviewer).

src/hotspot/share/c1/c1_ValueMap.cpp line 592:

> 590:     assert(!subst->has_subst(), "can't have a substitution");
> 591: 
> 592:     TRACE_VALUE_NUMBERING(tty->print_cr("substitution for %c%d set to %c%d", instr->type()->tchar(), instr->id(), subst->id(), subst->type()->tchar()));

Shouldn't the third argument be a char and the fourth an int?

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

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


More information about the hotspot-compiler-dev mailing list