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

Yi Yang yyang at openjdk.java.net
Tue May 11 02:33:37 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
[...]

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

Commit messages:
 - more instructions

Changes: https://git.openjdk.java.net/jdk/pull/3965/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=3965&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8266798
  Stats: 11 lines in 1 file changed: 7 ins; 3 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