Code Review for 6894778

Prepared by:cfang on Thu Jan 7 16:02:00 PST 2010
Workspace:/home/cfang/hg/6894778
Compare against: http://hg.openjdk.java.net/jdk7/hotspot-comp/hotspot
Summary of changes: 844 lines changed: 812 ins; 4 del; 28 mod; 18431 unchg
Patch of changes: 6894778.patch
Author comments:
6894779: Loop Predication for Loop Optimizer in C2
This work implements the loop predication optimization for range check elimination,
and null check elimination, etc., for the loop optimizer in C2. It was initiated by Ross

The idea is to insert a predicate on the entry path to a loop, and raise a uncommon trap
if the check of the condition(s) fails. The condition checks are promoted from inside the
loop body, and thus the checks inside the loop could be eliminated.

While the loop predication is a framework, it could be applied to range check, null check, and
array check eliminations, etc. Loop predication has advantage over the existing iteration-splitting
based range check elimination, and loop peeling based null check and array check eliminations. First,
it does not increase the code size (but the iteration splitting, and loop peeling do increase the code
size significantly), so we can apply loop predication to outer loops without the conscern of code size
increment. Second, while the iteration spliting based range check elimination leaves range checks in the pre-
and post- loops not removed, loop predication does not split the loop, and thus the range checks could be
eliminated for the whole loop body.

Known Issues:
(1) Missing Loop Predicate
The loop predication relies on the loop predicate inserted at the parsing time. If for some reasons, the loop predicate
was not inserted, or the predicate-loop pattern was destroyed by other optimizations, we can not perform loop predication.
We know that the predicate is not inserted for loops from inline_intrinsics, and there is no predicate for new loops generated
in the optimizer. Some of the cases need further investigation
Currently predicate is inserted on each entry path to loop head. This will cause problem when a loop has more than one entry.
beautify_loop in the loop optimizer will merger the paths into one using "landing_pad" and there will be no predicate on the merged
path to the loop head
(2) Missing Loop Predication Opportunities
We walk through the idom tree in a loop from its tail to head to find range check and null check for eliminations. Checks within
a dismond shape were not considered. An example is " if (condition(i)) {a[i] = ...}". Without further analysis of condition(i), we
can not eliminate the range check for a[i]
(3) Single Uncommon Trap for Multiple Reasons
If one of the checks fails, we will disable loop predication optimization for the whole method. For example, array_check fails for some
specjvm2008 workloads (serial, compiler) (You may use -XX:+TraceLoopPredicate to take a look). The problem is that we can not distinguish whether it
is a array check failure and other check failure. So for the next compilation, loop predication will be disabled.

Legend: Modified file
Deleted file
New file

Cdiffs Udiffs Sdiffs Frames Old New Patch Raw src/share/vm/includeDB_compiler2

1 line changed: 1 ins; 0 del; 0 mod; 1143 unchg

Cdiffs Udiffs Sdiffs Frames Old New Patch Raw src/share/vm/opto/c2_globals.hpp

6 lines changed: 6 ins; 0 del; 0 mod; 422 unchg

Cdiffs Udiffs Sdiffs Frames Old New Patch Raw src/share/vm/opto/compile.cpp

27 lines changed: 22 ins; 0 del; 5 mod; 2793 unchg

Cdiffs Udiffs Sdiffs Frames Old New Patch Raw src/share/vm/opto/compile.hpp

16 lines changed: 16 ins; 0 del; 0 mod; 757 unchg

Cdiffs Udiffs Sdiffs Frames Old New Patch Raw src/share/vm/opto/loopTransform.cpp

585 lines changed: 577 ins; 0 del; 8 mod; 1740 unchg

Cdiffs Udiffs Sdiffs Frames Old New Patch Raw src/share/vm/opto/loopnode.cpp

75 lines changed: 73 ins; 0 del; 2 mod; 2928 unchg

Cdiffs Udiffs Sdiffs Frames Old New Patch Raw src/share/vm/opto/loopnode.hpp

54 lines changed: 44 ins; 4 del; 6 mod; 962 unchg

Cdiffs Udiffs Sdiffs Frames Old New Patch Raw src/share/vm/opto/parse.hpp

6 lines changed: 5 ins; 0 del; 1 mod; 561 unchg

Cdiffs Udiffs Sdiffs Frames Old New Patch Raw src/share/vm/opto/parse1.cpp

37 lines changed: 35 ins; 0 del; 2 mod; 2170 unchg

Cdiffs Udiffs Sdiffs Frames Old New Patch Raw src/share/vm/opto/parse2.cpp

33 lines changed: 30 ins; 0 del; 3 mod; 2225 unchg

Cdiffs Udiffs Sdiffs Frames Old New Patch Raw src/share/vm/opto/split_if.cpp

1 line changed: 1 ins; 0 del; 0 mod; 536 unchg

Cdiffs Udiffs Sdiffs Frames Old New Patch Raw src/share/vm/runtime/deoptimization.cpp

2 lines changed: 1 ins; 0 del; 1 mod; 1846 unchg

Cdiffs Udiffs Sdiffs Frames Old New Patch Raw src/share/vm/runtime/deoptimization.hpp

1 line changed: 1 ins; 0 del; 0 mod; 348 unchg

This code review page was prepared using /home/cfang/bin/tom_webrev (vers 23.18-hg-never).