RFR: 8266798: C1: More types of instruction can also apply LoopInvariantCodeMotion [v2]
Nils Eliasson
neliasso at openjdk.java.net
Wed May 12 08:57:21 UTC 2021
On Tue, 11 May 2021 10:43:55 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
>> [...]
>
> Yi Yang has updated the pull request incrementally with one additional commit since the last revision:
>
> tchar() before id()
Looks good.
-------------
Marked as reviewed by neliasso (Reviewer).
PR: https://git.openjdk.java.net/jdk/pull/3965
More information about the hotspot-compiler-dev
mailing list