RFR: 8266798: C1: More types of instruction can also apply LoopInvariantCodeMotion [v2]
Yi Yang
yyang at openjdk.java.net
Tue May 11 10:43:55 UTC 2021
> 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
> [...]
Yi Yang has updated the pull request incrementally with one additional commit since the last revision:
tchar() before id()
-------------
Changes:
- all: https://git.openjdk.java.net/jdk/pull/3965/files
- new: https://git.openjdk.java.net/jdk/pull/3965/files/5690f5cc..447dc3b3
Webrevs:
- full: https://webrevs.openjdk.java.net/?repo=jdk&pr=3965&range=01
- incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=3965&range=00-01
Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
Patch: https://git.openjdk.java.net/jdk/pull/3965.diff
Fetch: git fetch https://git.openjdk.java.net/jdk pull/3965/head:pull/3965
PR: https://git.openjdk.java.net/jdk/pull/3965
More information about the hotspot-compiler-dev
mailing list