author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58589 | 45a085445a8c |
permissions | -rw-r--r-- |
1 | 1 |
/* |
54022
ff399127078a
8217561: X86: Add floating-point Math.min/max intrinsics
bsrbnd
parents:
53306
diff
changeset
|
2 |
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5054
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5054
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5054
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "compiler/compileLog.hpp" |
|
27 |
#include "memory/allocation.inline.hpp" |
|
28 |
#include "opto/addnode.hpp" |
|
29 |
#include "opto/callnode.hpp" |
|
27708
8a8710cb8fc4
8054478: C2: Incorrectly compiled char[] array access crashes JVM
roland
parents:
27707
diff
changeset
|
30 |
#include "opto/castnode.hpp" |
7397 | 31 |
#include "opto/connode.hpp" |
23528 | 32 |
#include "opto/convertnode.hpp" |
7397 | 33 |
#include "opto/divnode.hpp" |
34 |
#include "opto/loopnode.hpp" |
|
35 |
#include "opto/mulnode.hpp" |
|
23528 | 36 |
#include "opto/movenode.hpp" |
37 |
#include "opto/opaquenode.hpp" |
|
7397 | 38 |
#include "opto/rootnode.hpp" |
39 |
#include "opto/runtime.hpp" |
|
40 |
#include "opto/subnode.hpp" |
|
31403 | 41 |
#include "opto/superword.hpp" |
30211 | 42 |
#include "opto/vectornode.hpp" |
1 | 43 |
|
44 |
//------------------------------is_loop_exit----------------------------------- |
|
45 |
// Given an IfNode, return the loop-exiting projection or NULL if both |
|
46 |
// arms remain in the loop. |
|
47 |
Node *IdealLoopTree::is_loop_exit(Node *iff) const { |
|
54703 | 48 |
if (iff->outcnt() != 2) return NULL; // Ignore partially dead tests |
1 | 49 |
PhaseIdealLoop *phase = _phase; |
50 |
// Test is an IfNode, has 2 projections. If BOTH are in the loop |
|
51 |
// we need loop unswitching instead of peeling. |
|
54703 | 52 |
if (!is_member(phase->get_loop(iff->raw_out(0)))) |
1 | 53 |
return iff->raw_out(0); |
54703 | 54 |
if (!is_member(phase->get_loop(iff->raw_out(1)))) |
1 | 55 |
return iff->raw_out(1); |
56 |
return NULL; |
|
57 |
} |
|
58 |
||
59 |
||
60 |
//============================================================================= |
|
61 |
||
62 |
||
63 |
//------------------------------record_for_igvn---------------------------- |
|
64 |
// Put loop body on igvn work list |
|
65 |
void IdealLoopTree::record_for_igvn() { |
|
54703 | 66 |
for (uint i = 0; i < _body.size(); i++) { |
1 | 67 |
Node *n = _body.at(i); |
68 |
_phase->_igvn._worklist.push(n); |
|
69 |
} |
|
48145 | 70 |
// put body of outer strip mined loop on igvn work list as well |
71 |
if (_head->is_CountedLoop() && _head->as_Loop()->is_strip_mined()) { |
|
72 |
CountedLoopNode* l = _head->as_CountedLoop(); |
|
49600
d7c83c8e4e65
8197931: Null pointer dereference in Unique_Node_List::push of node.hpp:1510
roland
parents:
49487
diff
changeset
|
73 |
Node* outer_loop = l->outer_loop(); |
d7c83c8e4e65
8197931: Null pointer dereference in Unique_Node_List::push of node.hpp:1510
roland
parents:
49487
diff
changeset
|
74 |
assert(outer_loop != NULL, "missing piece of strip mined loop"); |
d7c83c8e4e65
8197931: Null pointer dereference in Unique_Node_List::push of node.hpp:1510
roland
parents:
49487
diff
changeset
|
75 |
_phase->_igvn._worklist.push(outer_loop); |
d7c83c8e4e65
8197931: Null pointer dereference in Unique_Node_List::push of node.hpp:1510
roland
parents:
49487
diff
changeset
|
76 |
Node* outer_loop_tail = l->outer_loop_tail(); |
d7c83c8e4e65
8197931: Null pointer dereference in Unique_Node_List::push of node.hpp:1510
roland
parents:
49487
diff
changeset
|
77 |
assert(outer_loop_tail != NULL, "missing piece of strip mined loop"); |
d7c83c8e4e65
8197931: Null pointer dereference in Unique_Node_List::push of node.hpp:1510
roland
parents:
49487
diff
changeset
|
78 |
_phase->_igvn._worklist.push(outer_loop_tail); |
d7c83c8e4e65
8197931: Null pointer dereference in Unique_Node_List::push of node.hpp:1510
roland
parents:
49487
diff
changeset
|
79 |
Node* outer_loop_end = l->outer_loop_end(); |
d7c83c8e4e65
8197931: Null pointer dereference in Unique_Node_List::push of node.hpp:1510
roland
parents:
49487
diff
changeset
|
80 |
assert(outer_loop_end != NULL, "missing piece of strip mined loop"); |
d7c83c8e4e65
8197931: Null pointer dereference in Unique_Node_List::push of node.hpp:1510
roland
parents:
49487
diff
changeset
|
81 |
_phase->_igvn._worklist.push(outer_loop_end); |
d7c83c8e4e65
8197931: Null pointer dereference in Unique_Node_List::push of node.hpp:1510
roland
parents:
49487
diff
changeset
|
82 |
Node* outer_safepoint = l->outer_safepoint(); |
d7c83c8e4e65
8197931: Null pointer dereference in Unique_Node_List::push of node.hpp:1510
roland
parents:
49487
diff
changeset
|
83 |
assert(outer_safepoint != NULL, "missing piece of strip mined loop"); |
d7c83c8e4e65
8197931: Null pointer dereference in Unique_Node_List::push of node.hpp:1510
roland
parents:
49487
diff
changeset
|
84 |
_phase->_igvn._worklist.push(outer_safepoint); |
48145 | 85 |
Node* cle_out = _head->as_CountedLoop()->loopexit()->proj_out(false); |
49600
d7c83c8e4e65
8197931: Null pointer dereference in Unique_Node_List::push of node.hpp:1510
roland
parents:
49487
diff
changeset
|
86 |
assert(cle_out != NULL, "missing piece of strip mined loop"); |
48145 | 87 |
_phase->_igvn._worklist.push(cle_out); |
88 |
} |
|
1 | 89 |
} |
90 |
||
9121 | 91 |
//------------------------------compute_exact_trip_count----------------------- |
40031
6cc034201dba
8159016: Over-unrolled loop is partially removed
thartmann
parents:
39429
diff
changeset
|
92 |
// Compute loop trip count if possible. Do not recalculate trip count for |
9121 | 93 |
// split loops (pre-main-post) which have their limits and inits behind Opaque node. |
40031
6cc034201dba
8159016: Over-unrolled loop is partially removed
thartmann
parents:
39429
diff
changeset
|
94 |
void IdealLoopTree::compute_trip_count(PhaseIdealLoop* phase) { |
9121 | 95 |
if (!_head->as_Loop()->is_valid_counted_loop()) { |
96 |
return; |
|
97 |
} |
|
98 |
CountedLoopNode* cl = _head->as_CountedLoop(); |
|
99 |
// Trip count may become nonexact for iteration split loops since |
|
100 |
// RCE modifies limits. Note, _trip_count value is not reset since |
|
101 |
// it is used to limit unrolling of main loop. |
|
102 |
cl->set_nonexact_trip_count(); |
|
103 |
||
104 |
// Loop's test should be part of loop. |
|
105 |
if (!phase->is_member(this, phase->get_ctrl(cl->loopexit()->in(CountedLoopEndNode::TestValue)))) |
|
106 |
return; // Infinite loop |
|
107 |
||
108 |
#ifdef ASSERT |
|
109 |
BoolTest::mask bt = cl->loopexit()->test_trip(); |
|
110 |
assert(bt == BoolTest::lt || bt == BoolTest::gt || |
|
10005 | 111 |
bt == BoolTest::ne, "canonical test is expected"); |
9121 | 112 |
#endif |
113 |
||
114 |
Node* init_n = cl->init_trip(); |
|
115 |
Node* limit_n = cl->limit(); |
|
40031
6cc034201dba
8159016: Over-unrolled loop is partially removed
thartmann
parents:
39429
diff
changeset
|
116 |
if (init_n != NULL && limit_n != NULL) { |
9121 | 117 |
// Use longs to avoid integer overflow. |
40031
6cc034201dba
8159016: Over-unrolled loop is partially removed
thartmann
parents:
39429
diff
changeset
|
118 |
int stride_con = cl->stride_con(); |
50262
131a631b271a
8202949: C2: assert(false) failed: Bad graph detected in build_loop_late
thartmann
parents:
49600
diff
changeset
|
119 |
const TypeInt* init_type = phase->_igvn.type(init_n)->is_int(); |
131a631b271a
8202949: C2: assert(false) failed: Bad graph detected in build_loop_late
thartmann
parents:
49600
diff
changeset
|
120 |
const TypeInt* limit_type = phase->_igvn.type(limit_n)->is_int(); |
131a631b271a
8202949: C2: assert(false) failed: Bad graph detected in build_loop_late
thartmann
parents:
49600
diff
changeset
|
121 |
jlong init_con = (stride_con > 0) ? init_type->_lo : init_type->_hi; |
131a631b271a
8202949: C2: assert(false) failed: Bad graph detected in build_loop_late
thartmann
parents:
49600
diff
changeset
|
122 |
jlong limit_con = (stride_con > 0) ? limit_type->_hi : limit_type->_lo; |
131a631b271a
8202949: C2: assert(false) failed: Bad graph detected in build_loop_late
thartmann
parents:
49600
diff
changeset
|
123 |
int stride_m = stride_con - (stride_con > 0 ? 1 : -1); |
13967 | 124 |
jlong trip_count = (limit_con - init_con + stride_m)/stride_con; |
9121 | 125 |
if (trip_count > 0 && (julong)trip_count < (julong)max_juint) { |
40031
6cc034201dba
8159016: Over-unrolled loop is partially removed
thartmann
parents:
39429
diff
changeset
|
126 |
if (init_n->is_Con() && limit_n->is_Con()) { |
6cc034201dba
8159016: Over-unrolled loop is partially removed
thartmann
parents:
39429
diff
changeset
|
127 |
// Set exact trip count. |
6cc034201dba
8159016: Over-unrolled loop is partially removed
thartmann
parents:
39429
diff
changeset
|
128 |
cl->set_exact_trip_count((uint)trip_count); |
6cc034201dba
8159016: Over-unrolled loop is partially removed
thartmann
parents:
39429
diff
changeset
|
129 |
} else if (cl->unrolled_count() == 1) { |
6cc034201dba
8159016: Over-unrolled loop is partially removed
thartmann
parents:
39429
diff
changeset
|
130 |
// Set maximum trip count before unrolling. |
6cc034201dba
8159016: Over-unrolled loop is partially removed
thartmann
parents:
39429
diff
changeset
|
131 |
cl->set_trip_count((uint)trip_count); |
6cc034201dba
8159016: Over-unrolled loop is partially removed
thartmann
parents:
39429
diff
changeset
|
132 |
} |
9121 | 133 |
} |
134 |
} |
|
135 |
} |
|
136 |
||
1 | 137 |
//------------------------------compute_profile_trip_cnt---------------------------- |
138 |
// Compute loop trip count from profile data as |
|
139 |
// (backedge_count + loop_exit_count) / loop_exit_count |
|
50623
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
140 |
|
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
141 |
float IdealLoopTree::compute_profile_trip_cnt_helper(Node* n) { |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
142 |
if (n->is_If()) { |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
143 |
IfNode *iff = n->as_If(); |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
144 |
if (iff->_fcnt != COUNT_UNKNOWN && iff->_prob != PROB_UNKNOWN) { |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
145 |
Node *exit = is_loop_exit(iff); |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
146 |
if (exit) { |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
147 |
float exit_prob = iff->_prob; |
54703 | 148 |
if (exit->Opcode() == Op_IfFalse) { |
149 |
exit_prob = 1.0 - exit_prob; |
|
150 |
} |
|
50623
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
151 |
if (exit_prob > PROB_MIN) { |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
152 |
float exit_cnt = iff->_fcnt * exit_prob; |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
153 |
return exit_cnt; |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
154 |
} |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
155 |
} |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
156 |
} |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
157 |
} |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
158 |
if (n->is_Jump()) { |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
159 |
JumpNode *jmp = n->as_Jump(); |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
160 |
if (jmp->_fcnt != COUNT_UNKNOWN) { |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
161 |
float* probs = jmp->_probs; |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
162 |
float exit_prob = 0; |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
163 |
PhaseIdealLoop *phase = _phase; |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
164 |
for (DUIterator_Fast imax, i = jmp->fast_outs(imax); i < imax; i++) { |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
165 |
JumpProjNode* u = jmp->fast_out(i)->as_JumpProj(); |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
166 |
if (!is_member(_phase->get_loop(u))) { |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
167 |
exit_prob += probs[u->_con]; |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
168 |
} |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
169 |
} |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
170 |
return exit_prob * jmp->_fcnt; |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
171 |
} |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
172 |
} |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
173 |
return 0; |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
174 |
} |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
175 |
|
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
176 |
void IdealLoopTree::compute_profile_trip_cnt(PhaseIdealLoop *phase) { |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
177 |
if (!_head->is_Loop()) { |
1 | 178 |
return; |
179 |
} |
|
50623
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
180 |
LoopNode* head = _head->as_Loop(); |
1 | 181 |
if (head->profile_trip_cnt() != COUNT_UNKNOWN) { |
182 |
return; // Already computed |
|
183 |
} |
|
184 |
float trip_cnt = (float)max_jint; // default is big |
|
185 |
||
186 |
Node* back = head->in(LoopNode::LoopBackControl); |
|
187 |
while (back != head) { |
|
188 |
if ((back->Opcode() == Op_IfTrue || back->Opcode() == Op_IfFalse) && |
|
189 |
back->in(0) && |
|
190 |
back->in(0)->is_If() && |
|
191 |
back->in(0)->as_If()->_fcnt != COUNT_UNKNOWN && |
|
50623
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
192 |
back->in(0)->as_If()->_prob != PROB_UNKNOWN && |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
193 |
(back->Opcode() == Op_IfTrue ? 1-back->in(0)->as_If()->_prob : back->in(0)->as_If()->_prob) > PROB_MIN) { |
1 | 194 |
break; |
195 |
} |
|
196 |
back = phase->idom(back); |
|
197 |
} |
|
198 |
if (back != head) { |
|
199 |
assert((back->Opcode() == Op_IfTrue || back->Opcode() == Op_IfFalse) && |
|
200 |
back->in(0), "if-projection exists"); |
|
201 |
IfNode* back_if = back->in(0)->as_If(); |
|
50623
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
202 |
float loop_back_cnt = back_if->_fcnt * (back->Opcode() == Op_IfTrue ? back_if->_prob : (1 - back_if->_prob)); |
1 | 203 |
|
204 |
// Now compute a loop exit count |
|
205 |
float loop_exit_cnt = 0.0f; |
|
50623
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
206 |
if (_child == NULL) { |
54703 | 207 |
for (uint i = 0; i < _body.size(); i++) { |
50623
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
208 |
Node *n = _body[i]; |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
209 |
loop_exit_cnt += compute_profile_trip_cnt_helper(n); |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
210 |
} |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
211 |
} else { |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
212 |
ResourceMark rm; |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
213 |
Unique_Node_List wq; |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
214 |
wq.push(back); |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
215 |
for (uint i = 0; i < wq.size(); i++) { |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
216 |
Node *n = wq.at(i); |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
217 |
assert(n->is_CFG(), "only control nodes"); |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
218 |
if (n != head) { |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
219 |
if (n->is_Region()) { |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
220 |
for (uint j = 1; j < n->req(); j++) { |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
221 |
wq.push(n->in(j)); |
1 | 222 |
} |
50623
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
223 |
} else { |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
224 |
loop_exit_cnt += compute_profile_trip_cnt_helper(n); |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
225 |
wq.push(n->in(0)); |
1 | 226 |
} |
227 |
} |
|
228 |
} |
|
50623
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
229 |
|
1 | 230 |
} |
231 |
if (loop_exit_cnt > 0.0f) { |
|
232 |
trip_cnt = (loop_back_cnt + loop_exit_cnt) / loop_exit_cnt; |
|
233 |
} else { |
|
234 |
// No exit count so use |
|
235 |
trip_cnt = loop_back_cnt; |
|
236 |
} |
|
50623
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
237 |
} else { |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
238 |
head->mark_profile_trip_failed(); |
1 | 239 |
} |
240 |
#ifndef PRODUCT |
|
241 |
if (TraceProfileTripCount) { |
|
242 |
tty->print_cr("compute_profile_trip_cnt lp: %d cnt: %f\n", head->_idx, trip_cnt); |
|
243 |
} |
|
244 |
#endif |
|
245 |
head->set_profile_trip_cnt(trip_cnt); |
|
246 |
} |
|
247 |
||
248 |
//---------------------is_invariant_addition----------------------------- |
|
249 |
// Return nonzero index of invariant operand for an Add or Sub |
|
2131 | 250 |
// of (nonconstant) invariant and variant values. Helper for reassociate_invariants. |
1 | 251 |
int IdealLoopTree::is_invariant_addition(Node* n, PhaseIdealLoop *phase) { |
252 |
int op = n->Opcode(); |
|
253 |
if (op == Op_AddI || op == Op_SubI) { |
|
254 |
bool in1_invar = this->is_invariant(n->in(1)); |
|
255 |
bool in2_invar = this->is_invariant(n->in(2)); |
|
256 |
if (in1_invar && !in2_invar) return 1; |
|
257 |
if (!in1_invar && in2_invar) return 2; |
|
258 |
} |
|
259 |
return 0; |
|
260 |
} |
|
261 |
||
262 |
//---------------------reassociate_add_sub----------------------------- |
|
263 |
// Reassociate invariant add and subtract expressions: |
|
264 |
// |
|
265 |
// inv1 + (x + inv2) => ( inv1 + inv2) + x |
|
266 |
// (x + inv2) + inv1 => ( inv1 + inv2) + x |
|
267 |
// inv1 + (x - inv2) => ( inv1 - inv2) + x |
|
268 |
// inv1 - (inv2 - x) => ( inv1 - inv2) + x |
|
269 |
// (x + inv2) - inv1 => (-inv1 + inv2) + x |
|
270 |
// (x - inv2) + inv1 => ( inv1 - inv2) + x |
|
271 |
// (x - inv2) - inv1 => (-inv1 - inv2) + x |
|
272 |
// inv1 + (inv2 - x) => ( inv1 + inv2) - x |
|
273 |
// inv1 - (x - inv2) => ( inv1 + inv2) - x |
|
274 |
// (inv2 - x) + inv1 => ( inv1 + inv2) - x |
|
275 |
// (inv2 - x) - inv1 => (-inv1 + inv2) - x |
|
276 |
// inv1 - (x + inv2) => ( inv1 - inv2) - x |
|
277 |
// |
|
278 |
Node* IdealLoopTree::reassociate_add_sub(Node* n1, PhaseIdealLoop *phase) { |
|
46630
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
44314
diff
changeset
|
279 |
if ((!n1->is_Add() && !n1->is_Sub()) || n1->outcnt() == 0) return NULL; |
1 | 280 |
if (is_invariant(n1)) return NULL; |
281 |
int inv1_idx = is_invariant_addition(n1, phase); |
|
282 |
if (!inv1_idx) return NULL; |
|
283 |
// Don't mess with add of constant (igvn moves them to expression tree root.) |
|
284 |
if (n1->is_Add() && n1->in(2)->is_Con()) return NULL; |
|
285 |
Node* inv1 = n1->in(inv1_idx); |
|
286 |
Node* n2 = n1->in(3 - inv1_idx); |
|
287 |
int inv2_idx = is_invariant_addition(n2, phase); |
|
288 |
if (!inv2_idx) return NULL; |
|
55150 | 289 |
|
290 |
if (!phase->may_require_nodes(10, 10)) return NULL; |
|
291 |
||
1 | 292 |
Node* x = n2->in(3 - inv2_idx); |
293 |
Node* inv2 = n2->in(inv2_idx); |
|
294 |
||
295 |
bool neg_x = n2->is_Sub() && inv2_idx == 1; |
|
296 |
bool neg_inv2 = n2->is_Sub() && inv2_idx == 2; |
|
297 |
bool neg_inv1 = n1->is_Sub() && inv1_idx == 2; |
|
298 |
if (n1->is_Sub() && inv1_idx == 1) { |
|
299 |
neg_x = !neg_x; |
|
300 |
neg_inv2 = !neg_inv2; |
|
301 |
} |
|
302 |
Node* inv1_c = phase->get_ctrl(inv1); |
|
303 |
Node* inv2_c = phase->get_ctrl(inv2); |
|
304 |
Node* n_inv1; |
|
305 |
if (neg_inv1) { |
|
306 |
Node *zero = phase->_igvn.intcon(0); |
|
307 |
phase->set_ctrl(zero, phase->C->root()); |
|
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
308 |
n_inv1 = new SubINode(zero, inv1); |
1 | 309 |
phase->register_new_node(n_inv1, inv1_c); |
310 |
} else { |
|
311 |
n_inv1 = inv1; |
|
312 |
} |
|
313 |
Node* inv; |
|
314 |
if (neg_inv2) { |
|
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
315 |
inv = new SubINode(n_inv1, inv2); |
1 | 316 |
} else { |
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
317 |
inv = new AddINode(n_inv1, inv2); |
1 | 318 |
} |
319 |
phase->register_new_node(inv, phase->get_early_ctrl(inv)); |
|
320 |
||
321 |
Node* addx; |
|
322 |
if (neg_x) { |
|
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
323 |
addx = new SubINode(inv, x); |
1 | 324 |
} else { |
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
325 |
addx = new AddINode(x, inv); |
1 | 326 |
} |
327 |
phase->register_new_node(addx, phase->get_ctrl(x)); |
|
5901
c046f8e9c52b
6677629: PhaseIterGVN::subsume_node() should call hash_delete() and add_users_to_worklist()
kvn
parents:
5547
diff
changeset
|
328 |
phase->_igvn.replace_node(n1, addx); |
8732
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
329 |
assert(phase->get_loop(phase->get_ctrl(n1)) == this, ""); |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
330 |
_body.yank(n1); |
1 | 331 |
return addx; |
332 |
} |
|
333 |
||
334 |
//---------------------reassociate_invariants----------------------------- |
|
335 |
// Reassociate invariant expressions: |
|
336 |
void IdealLoopTree::reassociate_invariants(PhaseIdealLoop *phase) { |
|
337 |
for (int i = _body.size() - 1; i >= 0; i--) { |
|
338 |
Node *n = _body.at(i); |
|
339 |
for (int j = 0; j < 5; j++) { |
|
340 |
Node* nn = reassociate_add_sub(n, phase); |
|
341 |
if (nn == NULL) break; |
|
342 |
n = nn; // again |
|
55150 | 343 |
} |
1 | 344 |
} |
345 |
} |
|
346 |
||
347 |
//------------------------------policy_peeling--------------------------------- |
|
55150 | 348 |
// Return TRUE if the loop should be peeled, otherwise return FALSE. Peeling |
349 |
// is applicable if we can make a loop-invariant test (usually a null-check) |
|
350 |
// execute before we enter the loop. When TRUE, the estimated node budget is |
|
351 |
// also requested. |
|
352 |
bool IdealLoopTree::policy_peeling(PhaseIdealLoop *phase) { |
|
353 |
uint estimate = estimate_peeling(phase); |
|
354 |
||
355 |
return estimate == 0 ? false : phase->may_require_nodes(estimate); |
|
356 |
} |
|
357 |
||
358 |
// Perform actual policy and size estimate for the loop peeling transform, and |
|
359 |
// return the estimated loop size if peeling is applicable, otherwise return |
|
360 |
// zero. No node budget is allocated. |
|
361 |
uint IdealLoopTree::estimate_peeling(PhaseIdealLoop *phase) { |
|
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
362 |
|
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
363 |
// If nodes are depleted, some transform has miscalculated its needs. |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
364 |
assert(!phase->exceeding_node_budget(), "sanity"); |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
365 |
|
55150 | 366 |
// Peeling does loop cloning which can result in O(N^2) node construction. |
367 |
if (_body.size() > 255) { |
|
368 |
return 0; // Suppress too large body size. |
|
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
369 |
} |
55150 | 370 |
// Optimistic estimate that approximates loop body complexity via data and |
371 |
// control flow fan-out (instead of using the more pessimistic: BodySize^2). |
|
372 |
uint estimate = est_loop_clone_sz(2); |
|
373 |
||
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
374 |
if (phase->exceeding_node_budget(estimate)) { |
55150 | 375 |
return 0; // Too large to safely clone. |
1 | 376 |
} |
31772 | 377 |
|
55150 | 378 |
// Check for vectorized loops, any peeling done was already applied. |
54698
3ebf58dbf5d8
8223137: Rename predicate 'do_unroll_only()' to 'is_unroll_only()'.
phedlin
parents:
54022
diff
changeset
|
379 |
if (_head->is_CountedLoop()) { |
3ebf58dbf5d8
8223137: Rename predicate 'do_unroll_only()' to 'is_unroll_only()'.
phedlin
parents:
54022
diff
changeset
|
380 |
CountedLoopNode* cl = _head->as_CountedLoop(); |
3ebf58dbf5d8
8223137: Rename predicate 'do_unroll_only()' to 'is_unroll_only()'.
phedlin
parents:
54022
diff
changeset
|
381 |
if (cl->is_unroll_only() || cl->trip_count() == 1) { |
55150 | 382 |
return 0; |
54698
3ebf58dbf5d8
8223137: Rename predicate 'do_unroll_only()' to 'is_unroll_only()'.
phedlin
parents:
54022
diff
changeset
|
383 |
} |
53167
030429d6baac
8215044: C2 crash in loopTransform.cpp with assert(cl->trip_count() > 0) failed: peeling a fully unrolled loop
roland
parents:
53063
diff
changeset
|
384 |
} |
030429d6baac
8215044: C2 crash in loopTransform.cpp with assert(cl->trip_count() > 0) failed: peeling a fully unrolled loop
roland
parents:
53063
diff
changeset
|
385 |
|
55150 | 386 |
Node* test = tail(); |
387 |
||
388 |
while (test != _head) { // Scan till run off top of loop |
|
389 |
if (test->is_If()) { // Test? |
|
1 | 390 |
Node *ctrl = phase->get_ctrl(test->in(1)); |
54703 | 391 |
if (ctrl->is_top()) { |
55150 | 392 |
return 0; // Found dead test on live IF? No peeling! |
54703 | 393 |
} |
55150 | 394 |
// Standard IF only has one input value to check for loop invariance. |
54703 | 395 |
assert(test->Opcode() == Op_If || |
396 |
test->Opcode() == Op_CountedLoopEnd || |
|
397 |
test->Opcode() == Op_RangeCheck, |
|
398 |
"Check this code when new subtype is added"); |
|
1 | 399 |
// Condition is not a member of this loop? |
54703 | 400 |
if (!is_member(phase->get_loop(ctrl)) && is_loop_exit(test)) { |
55150 | 401 |
return estimate; // Found reason to peel! |
54703 | 402 |
} |
1 | 403 |
} |
55150 | 404 |
// Walk up dominators to loop _head looking for test which is executed on |
405 |
// every path through the loop. |
|
1 | 406 |
test = phase->idom(test); |
407 |
} |
|
55150 | 408 |
return 0; |
1 | 409 |
} |
410 |
||
411 |
//------------------------------peeled_dom_test_elim--------------------------- |
|
412 |
// If we got the effect of peeling, either by actually peeling or by making |
|
413 |
// a pre-loop which must execute at least once, we can remove all |
|
414 |
// loop-invariant dominated tests in the main body. |
|
54703 | 415 |
void PhaseIdealLoop::peeled_dom_test_elim(IdealLoopTree *loop, Node_List &old_new) { |
1 | 416 |
bool progress = true; |
54703 | 417 |
while (progress) { |
1 | 418 |
progress = false; // Reset for next iteration |
419 |
Node *prev = loop->_head->in(LoopNode::LoopBackControl);//loop->tail(); |
|
420 |
Node *test = prev->in(0); |
|
54703 | 421 |
while (test != loop->_head) { // Scan till run off top of loop |
1 | 422 |
|
423 |
int p_op = prev->Opcode(); |
|
54703 | 424 |
if ((p_op == Op_IfFalse || p_op == Op_IfTrue) && |
1 | 425 |
test->is_If() && // Test? |
426 |
!test->in(1)->is_Con() && // And not already obvious? |
|
427 |
// Condition is not a member of this loop? |
|
428 |
!loop->is_member(get_loop(get_ctrl(test->in(1))))){ |
|
429 |
// Walk loop body looking for instances of this test |
|
54703 | 430 |
for (uint i = 0; i < loop->_body.size(); i++) { |
1 | 431 |
Node *n = loop->_body.at(i); |
54703 | 432 |
if (n->is_If() && n->in(1) == test->in(1) /*&& n != loop->tail()->in(0)*/) { |
1 | 433 |
// IfNode was dominated by version in peeled loop body |
434 |
progress = true; |
|
54703 | 435 |
dominated_by(old_new[prev->_idx], n); |
1 | 436 |
} |
437 |
} |
|
438 |
} |
|
439 |
prev = test; |
|
440 |
test = idom(test); |
|
441 |
} // End of scan tests in loop |
|
442 |
||
54703 | 443 |
} // End of while (progress) |
1 | 444 |
} |
445 |
||
446 |
//------------------------------do_peeling------------------------------------- |
|
447 |
// Peel the first iteration of the given loop. |
|
448 |
// Step 1: Clone the loop body. The clone becomes the peeled iteration. |
|
449 |
// The pre-loop illegally has 2 control users (old & new loops). |
|
450 |
// Step 2: Make the old-loop fall-in edges point to the peeled iteration. |
|
451 |
// Do this by making the old-loop fall-in edges act as if they came |
|
452 |
// around the loopback from the prior iteration (follow the old-loop |
|
453 |
// backedges) and then map to the new peeled iteration. This leaves |
|
454 |
// the pre-loop with only 1 user (the new peeled iteration), but the |
|
455 |
// peeled-loop backedge has 2 users. |
|
456 |
// Step 3: Cut the backedge on the clone (so its not a loop) and remove the |
|
457 |
// extra backedge user. |
|
9101 | 458 |
// |
459 |
// orig |
|
460 |
// |
|
461 |
// stmt1 |
|
462 |
// | |
|
463 |
// v |
|
464 |
// loop predicate |
|
465 |
// | |
|
466 |
// v |
|
467 |
// loop<----+ |
|
468 |
// | | |
|
469 |
// stmt2 | |
|
470 |
// | | |
|
471 |
// v | |
|
472 |
// if ^ |
|
473 |
// / \ | |
|
474 |
// / \ | |
|
475 |
// v v | |
|
476 |
// false true | |
|
477 |
// / \ | |
|
478 |
// / ----+ |
|
479 |
// | |
|
480 |
// v |
|
481 |
// exit |
|
482 |
// |
|
483 |
// |
|
484 |
// after clone loop |
|
485 |
// |
|
486 |
// stmt1 |
|
487 |
// | |
|
488 |
// v |
|
489 |
// loop predicate |
|
490 |
// / \ |
|
491 |
// clone / \ orig |
|
492 |
// / \ |
|
493 |
// / \ |
|
494 |
// v v |
|
495 |
// +---->loop clone loop<----+ |
|
496 |
// | | | | |
|
497 |
// | stmt2 clone stmt2 | |
|
498 |
// | | | | |
|
499 |
// | v v | |
|
500 |
// ^ if clone If ^ |
|
501 |
// | / \ / \ | |
|
502 |
// | / \ / \ | |
|
503 |
// | v v v v | |
|
504 |
// | true false false true | |
|
505 |
// | / \ / \ | |
|
506 |
// +---- \ / ----+ |
|
507 |
// \ / |
|
508 |
// 1v v2 |
|
509 |
// region |
|
510 |
// | |
|
511 |
// v |
|
512 |
// exit |
|
513 |
// |
|
514 |
// |
|
515 |
// after peel and predicate move |
|
516 |
// |
|
517 |
// stmt1 |
|
518 |
// / |
|
519 |
// / |
|
520 |
// clone / orig |
|
521 |
// / |
|
522 |
// / +----------+ |
|
523 |
// / | | |
|
524 |
// / loop predicate | |
|
525 |
// / | | |
|
526 |
// v v | |
|
527 |
// TOP-->loop clone loop<----+ | |
|
528 |
// | | | | |
|
529 |
// stmt2 clone stmt2 | | |
|
530 |
// | | | ^ |
|
531 |
// v v | | |
|
532 |
// if clone If ^ | |
|
533 |
// / \ / \ | | |
|
534 |
// / \ / \ | | |
|
535 |
// v v v v | | |
|
536 |
// true false false true | | |
|
537 |
// | \ / \ | | |
|
538 |
// | \ / ----+ ^ |
|
539 |
// | \ / | |
|
540 |
// | 1v v2 | |
|
541 |
// v region | |
|
542 |
// | | | |
|
543 |
// | v | |
|
544 |
// | exit | |
|
545 |
// | | |
|
546 |
// +--------------->-----------------+ |
|
547 |
// |
|
548 |
// |
|
549 |
// final graph |
|
550 |
// |
|
551 |
// stmt1 |
|
552 |
// | |
|
553 |
// v |
|
554 |
// stmt2 clone |
|
555 |
// | |
|
556 |
// v |
|
557 |
// if clone |
|
558 |
// / | |
|
559 |
// / | |
|
560 |
// v v |
|
561 |
// false true |
|
562 |
// | | |
|
563 |
// | v |
|
564 |
// | loop predicate |
|
565 |
// | | |
|
566 |
// | v |
|
567 |
// | loop<----+ |
|
568 |
// | | | |
|
569 |
// | stmt2 | |
|
570 |
// | | | |
|
571 |
// | v | |
|
572 |
// v if ^ |
|
573 |
// | / \ | |
|
574 |
// | / \ | |
|
575 |
// | v v | |
|
576 |
// | false true | |
|
577 |
// | | \ | |
|
578 |
// v v --+ |
|
579 |
// region |
|
580 |
// | |
|
581 |
// v |
|
582 |
// exit |
|
583 |
// |
|
54703 | 584 |
void PhaseIdealLoop::do_peeling(IdealLoopTree *loop, Node_List &old_new) { |
1 | 585 |
|
586 |
C->set_major_progress(); |
|
587 |
// Peeling a 'main' loop in a pre/main/post situation obfuscates the |
|
31133
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
588 |
// 'pre' loop from the main and the 'pre' can no longer have its |
1 | 589 |
// iterations adjusted. Therefore, we need to declare this loop as |
590 |
// no longer a 'main' loop; it will need new pre and post loops before |
|
591 |
// we can do further RCE. |
|
8732
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
592 |
#ifndef PRODUCT |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
593 |
if (TraceLoopOpts) { |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
594 |
tty->print("Peel "); |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
595 |
loop->dump_head(); |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
596 |
} |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
597 |
#endif |
48145 | 598 |
LoopNode* head = loop->_head->as_Loop(); |
9101 | 599 |
bool counted_loop = head->is_CountedLoop(); |
600 |
if (counted_loop) { |
|
601 |
CountedLoopNode *cl = head->as_CountedLoop(); |
|
1 | 602 |
assert(cl->trip_count() > 0, "peeling a fully unrolled loop"); |
603 |
cl->set_trip_count(cl->trip_count() - 1); |
|
8732
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
604 |
if (cl->is_main_loop()) { |
1 | 605 |
cl->set_normal_loop(); |
606 |
#ifndef PRODUCT |
|
8732
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
607 |
if (PrintOpto && VerifyLoopOptimizations) { |
1 | 608 |
tty->print("Peeling a 'main' loop; resetting to 'normal' "); |
609 |
loop->dump_head(); |
|
610 |
} |
|
611 |
#endif |
|
612 |
} |
|
613 |
} |
|
9101 | 614 |
Node* entry = head->in(LoopNode::EntryControl); |
1 | 615 |
|
616 |
// Step 1: Clone the loop body. The clone becomes the peeled iteration. |
|
617 |
// The pre-loop illegally has 2 control users (old & new loops). |
|
48145 | 618 |
clone_loop(loop, old_new, dom_depth(head->skip_strip_mined()), ControlAroundStripMined); |
1 | 619 |
|
620 |
// Step 2: Make the old-loop fall-in edges point to the peeled iteration. |
|
621 |
// Do this by making the old-loop fall-in edges act as if they came |
|
622 |
// around the loopback from the prior iteration (follow the old-loop |
|
623 |
// backedges) and then map to the new peeled iteration. This leaves |
|
624 |
// the pre-loop with only 1 user (the new peeled iteration), but the |
|
625 |
// peeled-loop backedge has 2 users. |
|
10258
10c77b8c8d3e
7068051: SIGSEGV in PhaseIdealLoop::build_loop_late_post
kvn
parents:
10011
diff
changeset
|
626 |
Node* new_entry = old_new[head->in(LoopNode::LoopBackControl)->_idx]; |
48145 | 627 |
_igvn.hash_delete(head->skip_strip_mined()); |
628 |
head->skip_strip_mined()->set_req(LoopNode::EntryControl, new_entry); |
|
9101 | 629 |
for (DUIterator_Fast jmax, j = head->fast_outs(jmax); j < jmax; j++) { |
630 |
Node* old = head->fast_out(j); |
|
631 |
if (old->in(0) == loop->_head && old->req() == 3 && old->is_Phi()) { |
|
10258
10c77b8c8d3e
7068051: SIGSEGV in PhaseIdealLoop::build_loop_late_post
kvn
parents:
10011
diff
changeset
|
632 |
Node* new_exit_value = old_new[old->in(LoopNode::LoopBackControl)->_idx]; |
54703 | 633 |
if (!new_exit_value) // Backedge value is ALSO loop invariant? |
1 | 634 |
// Then loop body backedge value remains the same. |
635 |
new_exit_value = old->in(LoopNode::LoopBackControl); |
|
636 |
_igvn.hash_delete(old); |
|
637 |
old->set_req(LoopNode::EntryControl, new_exit_value); |
|
638 |
} |
|
639 |
} |
|
640 |
||
641 |
||
642 |
// Step 3: Cut the backedge on the clone (so its not a loop) and remove the |
|
643 |
// extra backedge user. |
|
9101 | 644 |
Node* new_head = old_new[head->_idx]; |
645 |
_igvn.hash_delete(new_head); |
|
646 |
new_head->set_req(LoopNode::LoopBackControl, C->top()); |
|
647 |
for (DUIterator_Fast j2max, j2 = new_head->fast_outs(j2max); j2 < j2max; j2++) { |
|
648 |
Node* use = new_head->fast_out(j2); |
|
649 |
if (use->in(0) == new_head && use->req() == 3 && use->is_Phi()) { |
|
1 | 650 |
_igvn.hash_delete(use); |
651 |
use->set_req(LoopNode::LoopBackControl, C->top()); |
|
652 |
} |
|
653 |
} |
|
654 |
||
655 |
// Step 4: Correct dom-depth info. Set to loop-head depth. |
|
55150 | 656 |
|
9101 | 657 |
int dd = dom_depth(head); |
658 |
set_idom(head, head->in(1), dd); |
|
1 | 659 |
for (uint j3 = 0; j3 < loop->_body.size(); j3++) { |
660 |
Node *old = loop->_body.at(j3); |
|
661 |
Node *nnn = old_new[old->_idx]; |
|
54703 | 662 |
if (!has_ctrl(nnn)) { |
1 | 663 |
set_idom(nnn, idom(nnn), dd-1); |
54703 | 664 |
} |
1 | 665 |
} |
666 |
||
667 |
// Now force out all loop-invariant dominating tests. The optimizer |
|
668 |
// finds some, but we _know_ they are all useless. |
|
669 |
peeled_dom_test_elim(loop,old_new); |
|
670 |
||
671 |
loop->record_for_igvn(); |
|
672 |
} |
|
673 |
||
674 |
//------------------------------policy_maximally_unroll------------------------ |
|
55150 | 675 |
// Calculate the exact loop trip-count and return TRUE if loop can be fully, |
676 |
// i.e. maximally, unrolled, otherwise return FALSE. When TRUE, the estimated |
|
677 |
// node budget is also requested. |
|
58354 | 678 |
bool IdealLoopTree::policy_maximally_unroll(PhaseIdealLoop* phase) const { |
679 |
CountedLoopNode* cl = _head->as_CountedLoop(); |
|
8879
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
680 |
assert(cl->is_normal_loop(), ""); |
54703 | 681 |
if (!cl->is_valid_counted_loop()) { |
58354 | 682 |
return false; // Malformed counted loop. |
54703 | 683 |
} |
9121 | 684 |
if (!cl->has_exact_trip_count()) { |
58354 | 685 |
return false; // Trip count is not exact. |
1 | 686 |
} |
687 |
||
9121 | 688 |
uint trip_count = cl->trip_count(); |
689 |
// Note, max_juint is used to indicate unknown trip count. |
|
690 |
assert(trip_count > 1, "one iteration loop should be optimized out already"); |
|
58354 | 691 |
assert(trip_count < max_juint, "exact trip_count should be less than max_juint."); |
1 | 692 |
|
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
693 |
// If nodes are depleted, some transform has miscalculated its needs. |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
694 |
assert(!phase->exceeding_node_budget(), "sanity"); |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
695 |
|
58354 | 696 |
// Allow the unrolled body to get larger than the standard loop size limit. |
1 | 697 |
uint unroll_limit = (uint)LoopUnrollLimit * 4; |
54703 | 698 |
assert((intx)unroll_limit == LoopUnrollLimit * 4, "LoopUnrollLimit must fit in 32bits"); |
58354 | 699 |
if (trip_count > unroll_limit || _body.size() > unroll_limit) { |
8879
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
700 |
return false; |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
701 |
} |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
702 |
|
58354 | 703 |
uint new_body_size = est_loop_unroll_sz(trip_count); |
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
704 |
|
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
705 |
if (new_body_size == UINT_MAX) { // Check for bad estimate (overflow). |
9109
ec7b2f3b386c
7004547: regular loop unroll should not unroll more than max unrolling
kvn
parents:
9104
diff
changeset
|
706 |
return false; |
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
707 |
} |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
708 |
|
58354 | 709 |
// Fully unroll a loop with few iterations, regardless of other conditions, |
710 |
// since the following (general) loop optimizations will split such loop in |
|
711 |
// any case (into pre-main-post). |
|
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
712 |
if (trip_count <= 3) { |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
713 |
return phase->may_require_nodes(new_body_size); |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
714 |
} |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
715 |
|
58354 | 716 |
// Reject if unrolling will result in too much node construction. |
717 |
if (new_body_size > unroll_limit || phase->exceeding_node_budget(new_body_size)) { |
|
9109
ec7b2f3b386c
7004547: regular loop unroll should not unroll more than max unrolling
kvn
parents:
9104
diff
changeset
|
718 |
return false; |
ec7b2f3b386c
7004547: regular loop unroll should not unroll more than max unrolling
kvn
parents:
9104
diff
changeset
|
719 |
} |
ec7b2f3b386c
7004547: regular loop unroll should not unroll more than max unrolling
kvn
parents:
9104
diff
changeset
|
720 |
|
8879
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
721 |
// Do not unroll a loop with String intrinsics code. |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
722 |
// String intrinsics are large and have loops. |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
723 |
for (uint k = 0; k < _body.size(); k++) { |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
724 |
Node* n = _body.at(k); |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
725 |
switch (n->Opcode()) { |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
726 |
case Op_StrComp: |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
727 |
case Op_StrEquals: |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
728 |
case Op_StrIndexOf: |
33628 | 729 |
case Op_StrIndexOfChar: |
15242
695bb216be99
6896617: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() on x86
kvn
parents:
14623
diff
changeset
|
730 |
case Op_EncodeISOArray: |
33628 | 731 |
case Op_AryEq: |
732 |
case Op_HasNegatives: { |
|
8879
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
733 |
return false; |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
734 |
} |
23491 | 735 |
#if INCLUDE_RTM_OPT |
736 |
case Op_FastLock: |
|
737 |
case Op_FastUnlock: { |
|
738 |
// Don't unroll RTM locking code because it is large. |
|
739 |
if (UseRTMLocking) { |
|
740 |
return false; |
|
741 |
} |
|
742 |
} |
|
743 |
#endif |
|
8879
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
744 |
} // switch |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
745 |
} |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
746 |
|
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
747 |
return phase->may_require_nodes(new_body_size); |
1 | 748 |
} |
749 |
||
750 |
||
751 |
//------------------------------policy_unroll---------------------------------- |
|
55150 | 752 |
// Return TRUE or FALSE if the loop should be unrolled or not. Apply unroll if |
753 |
// the loop is a counted loop and the loop body is small enough. When TRUE, |
|
754 |
// the estimated node budget is also requested. |
|
31403 | 755 |
bool IdealLoopTree::policy_unroll(PhaseIdealLoop *phase) { |
1 | 756 |
|
757 |
CountedLoopNode *cl = _head->as_CountedLoop(); |
|
8879
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
758 |
assert(cl->is_normal_loop() || cl->is_main_loop(), ""); |
1 | 759 |
|
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
760 |
if (!cl->is_valid_counted_loop()) { |
9109
ec7b2f3b386c
7004547: regular loop unroll should not unroll more than max unrolling
kvn
parents:
9104
diff
changeset
|
761 |
return false; // Malformed counted loop |
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
762 |
} |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
763 |
|
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
764 |
// If nodes are depleted, some transform has miscalculated its needs. |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
765 |
assert(!phase->exceeding_node_budget(), "sanity"); |
1 | 766 |
|
9446 | 767 |
// Protect against over-unrolling. |
768 |
// After split at least one iteration will be executed in pre-loop. |
|
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
769 |
if (cl->trip_count() <= (cl->is_normal_loop() ? 2u : 1u)) { |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
770 |
return false; |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
771 |
} |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
772 |
_local_loop_unroll_limit = LoopUnrollLimit; |
31403 | 773 |
_local_loop_unroll_factor = 4; |
54702 | 774 |
int future_unroll_cnt = cl->unrolled_count() * 2; |
47591
d78db2ebce5e
8187601: Unrolling more when SLP auto-vectorization failed
zyao
parents:
47216
diff
changeset
|
775 |
if (!cl->is_vectorized_loop()) { |
54702 | 776 |
if (future_unroll_cnt > LoopMaxUnroll) return false; |
31772 | 777 |
} else { |
778 |
// obey user constraints on vector mapped loops with additional unrolling applied |
|
36066 | 779 |
int unroll_constraint = (cl->slp_max_unroll()) ? cl->slp_max_unroll() : 1; |
54702 | 780 |
if ((future_unroll_cnt / unroll_constraint) > LoopMaxUnroll) return false; |
31772 | 781 |
} |
9109
ec7b2f3b386c
7004547: regular loop unroll should not unroll more than max unrolling
kvn
parents:
9104
diff
changeset
|
782 |
|
9434 | 783 |
// Check for initial stride being a small enough constant |
54702 | 784 |
if (abs(cl->stride_con()) > (1<<2)*future_unroll_cnt) return false; |
1 | 785 |
|
786 |
// Don't unroll if the next round of unrolling would push us |
|
787 |
// over the expected trip count of the loop. One is subtracted |
|
788 |
// from the expected trip count because the pre-loop normally |
|
789 |
// executes 1 iteration. |
|
790 |
if (UnrollLimitForProfileCheck > 0 && |
|
791 |
cl->profile_trip_cnt() != COUNT_UNKNOWN && |
|
54702 | 792 |
future_unroll_cnt > UnrollLimitForProfileCheck && |
793 |
(float)future_unroll_cnt > cl->profile_trip_cnt() - 1.0) { |
|
1 | 794 |
return false; |
795 |
} |
|
796 |
||
797 |
// When unroll count is greater than LoopUnrollMin, don't unroll if: |
|
798 |
// the residual iterations are more than 10% of the trip count |
|
799 |
// and rounds of "unroll,optimize" are not making significant progress |
|
800 |
// Progress defined as current size less than 20% larger than previous size. |
|
801 |
if (UseSuperWord && cl->node_count_before_unroll() > 0 && |
|
54702 | 802 |
future_unroll_cnt > LoopUnrollMin && |
803 |
(future_unroll_cnt - 1) * (100 / LoopPercentProfileLimit) > cl->profile_trip_cnt() && |
|
1 | 804 |
1.2 * cl->node_count_before_unroll() < (double)_body.size()) { |
805 |
return false; |
|
806 |
} |
|
807 |
||
808 |
Node *init_n = cl->init_trip(); |
|
809 |
Node *limit_n = cl->limit(); |
|
9446 | 810 |
int stride_con = cl->stride_con(); |
51078 | 811 |
if (limit_n == NULL) return false; // We will dereference it below. |
812 |
||
1 | 813 |
// Non-constant bounds. |
814 |
// Protect against over-unrolling when init or/and limit are not constant |
|
815 |
// (so that trip_count's init value is maxint) but iv range is known. |
|
51078 | 816 |
if (init_n == NULL || !init_n->is_Con() || !limit_n->is_Con()) { |
1 | 817 |
Node* phi = cl->phi(); |
8879
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
818 |
if (phi != NULL) { |
1 | 819 |
assert(phi->is_Phi() && phi->in(0) == _head, "Counted loop should have iv phi."); |
820 |
const TypeInt* iv_type = phase->_igvn.type(phi)->is_int(); |
|
9446 | 821 |
int next_stride = stride_con * 2; // stride after this unroll |
8879
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
822 |
if (next_stride > 0) { |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
823 |
if (iv_type->_lo + next_stride <= iv_type->_lo || // overflow |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
824 |
iv_type->_lo + next_stride > iv_type->_hi) { |
1 | 825 |
return false; // over-unrolling |
826 |
} |
|
8879
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
827 |
} else if (next_stride < 0) { |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
828 |
if (iv_type->_hi + next_stride >= iv_type->_hi || // overflow |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
829 |
iv_type->_hi + next_stride < iv_type->_lo) { |
1 | 830 |
return false; // over-unrolling |
831 |
} |
|
832 |
} |
|
833 |
} |
|
834 |
} |
|
835 |
||
9446 | 836 |
// After unroll limit will be adjusted: new_limit = limit-stride. |
837 |
// Bailout if adjustment overflow. |
|
838 |
const TypeInt* limit_type = phase->_igvn.type(limit_n)->is_int(); |
|
46630
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
44314
diff
changeset
|
839 |
if ((stride_con > 0 && ((limit_type->_hi - stride_con) >= limit_type->_hi)) || |
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
44314
diff
changeset
|
840 |
(stride_con < 0 && ((limit_type->_lo - stride_con) <= limit_type->_lo))) |
9446 | 841 |
return false; // overflow |
842 |
||
1 | 843 |
// Adjust body_size to determine if we unroll or not |
844 |
uint body_size = _body.size(); |
|
10538
d6bf448fa3ad
7054211: No loop unrolling done in jdk7b144 for a test update() while loop
kvn
parents:
10263
diff
changeset
|
845 |
// Key test to unroll loop in CRC32 java code |
d6bf448fa3ad
7054211: No loop unrolling done in jdk7b144 for a test update() while loop
kvn
parents:
10263
diff
changeset
|
846 |
int xors_in_loop = 0; |
1 | 847 |
// Also count ModL, DivL and MulL which expand mightly |
8879
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
848 |
for (uint k = 0; k < _body.size(); k++) { |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
849 |
Node* n = _body.at(k); |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
850 |
switch (n->Opcode()) { |
10538
d6bf448fa3ad
7054211: No loop unrolling done in jdk7b144 for a test update() while loop
kvn
parents:
10263
diff
changeset
|
851 |
case Op_XorI: xors_in_loop++; break; // CRC32 java code |
8879
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
852 |
case Op_ModL: body_size += 30; break; |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
853 |
case Op_DivL: body_size += 30; break; |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
854 |
case Op_MulL: body_size += 10; break; |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
855 |
case Op_StrComp: |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
856 |
case Op_StrEquals: |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
857 |
case Op_StrIndexOf: |
33628 | 858 |
case Op_StrIndexOfChar: |
15242
695bb216be99
6896617: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() on x86
kvn
parents:
14623
diff
changeset
|
859 |
case Op_EncodeISOArray: |
33628 | 860 |
case Op_AryEq: |
861 |
case Op_HasNegatives: { |
|
8879
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
862 |
// Do not unroll a loop with String intrinsics code. |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
863 |
// String intrinsics are large and have loops. |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
864 |
return false; |
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
865 |
} |
23491 | 866 |
#if INCLUDE_RTM_OPT |
867 |
case Op_FastLock: |
|
868 |
case Op_FastUnlock: { |
|
869 |
// Don't unroll RTM locking code because it is large. |
|
870 |
if (UseRTMLocking) { |
|
871 |
return false; |
|
872 |
} |
|
873 |
} |
|
874 |
#endif |
|
8879
e6ae9a7aa72a
7029152: Ideal nodes for String intrinsics miss memory edge optimization
kvn
parents:
8870
diff
changeset
|
875 |
} // switch |
1 | 876 |
} |
877 |
||
31403 | 878 |
if (UseSuperWord) { |
879 |
if (!cl->is_reduction_loop()) { |
|
880 |
phase->mark_reductions(this); |
|
881 |
} |
|
882 |
||
883 |
// Only attempt slp analysis when user controls do not prohibit it |
|
884 |
if (LoopMaxUnroll > _local_loop_unroll_factor) { |
|
885 |
// Once policy_slp_analysis succeeds, mark the loop with the |
|
886 |
// maximal unroll factor so that we minimize analysis passes |
|
54702 | 887 |
if (future_unroll_cnt >= _local_loop_unroll_factor) { |
888 |
policy_unroll_slp_analysis(cl, phase, future_unroll_cnt); |
|
31403 | 889 |
} |
890 |
} |
|
891 |
} |
|
892 |
||
31772 | 893 |
int slp_max_unroll_factor = cl->slp_max_unroll(); |
46692
117b089cb1c3
8175096: Analyse subword in the loop to set maximum vector size
vdeshpande
parents:
46630
diff
changeset
|
894 |
if ((LoopMaxUnroll < slp_max_unroll_factor) && FLAG_IS_DEFAULT(LoopMaxUnroll) && UseSubwordForMaxVector) { |
117b089cb1c3
8175096: Analyse subword in the loop to set maximum vector size
vdeshpande
parents:
46630
diff
changeset
|
895 |
LoopMaxUnroll = slp_max_unroll_factor; |
117b089cb1c3
8175096: Analyse subword in the loop to set maximum vector size
vdeshpande
parents:
46630
diff
changeset
|
896 |
} |
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
897 |
|
55150 | 898 |
uint estimate = est_loop_clone_sz(2); |
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
899 |
|
31772 | 900 |
if (cl->has_passed_slp()) { |
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
901 |
if (slp_max_unroll_factor >= future_unroll_cnt) { |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
902 |
return phase->may_require_nodes(estimate); |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
903 |
} |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
904 |
return false; // Loop too big. |
31772 | 905 |
} |
906 |
||
1 | 907 |
// Check for being too big |
31403 | 908 |
if (body_size > (uint)_local_loop_unroll_limit) { |
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
909 |
if ((cl->is_subword_loop() || xors_in_loop >= 4) && body_size < 4u * LoopUnrollLimit) { |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
910 |
return phase->may_require_nodes(estimate); |
51017
dd7ce84016a5
8194740: UseSubwordForMaxVector causes performance regression
vdeshpande
parents:
50632
diff
changeset
|
911 |
} |
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
912 |
return false; // Loop too big. |
1 | 913 |
} |
914 |
||
54698
3ebf58dbf5d8
8223137: Rename predicate 'do_unroll_only()' to 'is_unroll_only()'.
phedlin
parents:
54022
diff
changeset
|
915 |
if (cl->is_unroll_only()) { |
34174
4db2fb26dc49
8140424: don't prefix developer and notproduct flag variables with CONST_ in product builds
twisti
parents:
34164
diff
changeset
|
916 |
if (TraceSuperWordLoopUnrollAnalysis) { |
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
917 |
tty->print_cr("policy_unroll passed vector loop(vlen=%d, factor=%d)\n", |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
918 |
slp_max_unroll_factor, future_unroll_cnt); |
34174
4db2fb26dc49
8140424: don't prefix developer and notproduct flag variables with CONST_ in product builds
twisti
parents:
34164
diff
changeset
|
919 |
} |
31772 | 920 |
} |
921 |
||
1 | 922 |
// Unroll once! (Each trip will soon do double iterations) |
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
923 |
return phase->may_require_nodes(estimate); |
1 | 924 |
} |
925 |
||
54702 | 926 |
void IdealLoopTree::policy_unroll_slp_analysis(CountedLoopNode *cl, PhaseIdealLoop *phase, int future_unroll_cnt) { |
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
927 |
|
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
928 |
// If nodes are depleted, some transform has miscalculated its needs. |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
929 |
assert(!phase->exceeding_node_budget(), "sanity"); |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
930 |
|
31403 | 931 |
// Enable this functionality target by target as needed |
932 |
if (SuperWordLoopUnrollAnalysis) { |
|
31772 | 933 |
if (!cl->was_slp_analyzed()) { |
31403 | 934 |
SuperWord sw(phase); |
935 |
sw.transform_loop(this, false); |
|
936 |
||
937 |
// If the loop is slp canonical analyze it |
|
938 |
if (sw.early_return() == false) { |
|
31772 | 939 |
sw.unrolling_analysis(_local_loop_unroll_factor); |
31403 | 940 |
} |
941 |
} |
|
942 |
||
31772 | 943 |
if (cl->has_passed_slp()) { |
944 |
int slp_max_unroll_factor = cl->slp_max_unroll(); |
|
54702 | 945 |
if (slp_max_unroll_factor >= future_unroll_cnt) { |
31772 | 946 |
int new_limit = cl->node_count_before_unroll() * slp_max_unroll_factor; |
947 |
if (new_limit > LoopUnrollLimit) { |
|
34174
4db2fb26dc49
8140424: don't prefix developer and notproduct flag variables with CONST_ in product builds
twisti
parents:
34164
diff
changeset
|
948 |
if (TraceSuperWordLoopUnrollAnalysis) { |
4db2fb26dc49
8140424: don't prefix developer and notproduct flag variables with CONST_ in product builds
twisti
parents:
34164
diff
changeset
|
949 |
tty->print_cr("slp analysis unroll=%d, default limit=%d\n", new_limit, _local_loop_unroll_limit); |
4db2fb26dc49
8140424: don't prefix developer and notproduct flag variables with CONST_ in product builds
twisti
parents:
34164
diff
changeset
|
950 |
} |
31772 | 951 |
_local_loop_unroll_limit = new_limit; |
31403 | 952 |
} |
953 |
} |
|
954 |
} |
|
955 |
} |
|
956 |
} |
|
957 |
||
1 | 958 |
//------------------------------policy_align----------------------------------- |
959 |
// Return TRUE or FALSE if the loop should be cache-line aligned. Gather the |
|
960 |
// expression that does the alignment. Note that only one array base can be |
|
2131 | 961 |
// aligned in a loop (unless the VM guarantees mutual alignment). Note that |
1 | 962 |
// if we vectorize short memory ops into longer memory ops, we may want to |
963 |
// increase alignment. |
|
54703 | 964 |
bool IdealLoopTree::policy_align(PhaseIdealLoop *phase) const { |
1 | 965 |
return false; |
966 |
} |
|
967 |
||
968 |
//------------------------------policy_range_check----------------------------- |
|
55150 | 969 |
// Return TRUE or FALSE if the loop should be range-check-eliminated or not. |
970 |
// When TRUE, the estimated node budget is also requested. |
|
971 |
// |
|
972 |
// We will actually perform iteration-splitting, a more powerful form of RCE. |
|
54703 | 973 |
bool IdealLoopTree::policy_range_check(PhaseIdealLoop *phase) const { |
9446 | 974 |
if (!RangeCheckElimination) return false; |
1 | 975 |
|
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
976 |
// If nodes are depleted, some transform has miscalculated its needs. |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
977 |
assert(!phase->exceeding_node_budget(), "sanity"); |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
978 |
|
1 | 979 |
CountedLoopNode *cl = _head->as_CountedLoop(); |
55150 | 980 |
// If we unrolled with no intention of doing RCE and we later changed our |
981 |
// minds, we got no pre-loop. Either we need to make a new pre-loop, or we |
|
982 |
// have to disallow RCE. |
|
9446 | 983 |
if (cl->is_main_no_pre_loop()) return false; // Disallowed for now. |
1 | 984 |
Node *trip_counter = cl->phi(); |
985 |
||
31772 | 986 |
// check for vectorized loops, some opts are no longer needed |
54698
3ebf58dbf5d8
8223137: Rename predicate 'do_unroll_only()' to 'is_unroll_only()'.
phedlin
parents:
54022
diff
changeset
|
987 |
if (cl->is_unroll_only()) return false; |
31772 | 988 |
|
1 | 989 |
// Check loop body for tests of trip-counter plus loop-invariant vs |
990 |
// loop-invariant. |
|
9446 | 991 |
for (uint i = 0; i < _body.size(); i++) { |
1 | 992 |
Node *iff = _body[i]; |
34164
a9e6034d7707
8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents:
33628
diff
changeset
|
993 |
if (iff->Opcode() == Op_If || |
a9e6034d7707
8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents:
33628
diff
changeset
|
994 |
iff->Opcode() == Op_RangeCheck) { // Test? |
1 | 995 |
|
996 |
// Comparing trip+off vs limit |
|
997 |
Node *bol = iff->in(1); |
|
54703 | 998 |
if (bol->req() != 2) { |
999 |
continue; // dead constant test |
|
1000 |
} |
|
4643 | 1001 |
if (!bol->is_Bool()) { |
39429 | 1002 |
assert(bol->Opcode() == Op_Conv2B, "predicate check only"); |
4643 | 1003 |
continue; |
1004 |
} |
|
54703 | 1005 |
if (bol->as_Bool()->_test._test == BoolTest::ne) { |
9446 | 1006 |
continue; // not RC |
54703 | 1007 |
} |
1 | 1008 |
Node *cmp = bol->in(1); |
1009 |
Node *rc_exp = cmp->in(1); |
|
1010 |
Node *limit = cmp->in(2); |
|
1011 |
||
1012 |
Node *limit_c = phase->get_ctrl(limit); |
|
54703 | 1013 |
if (limit_c == phase->C->top()) { |
1 | 1014 |
return false; // Found dead test on live IF? No RCE! |
54703 | 1015 |
} |
1016 |
if (is_member(phase->get_loop(limit_c))) { |
|
1 | 1017 |
// Compare might have operands swapped; commute them |
1018 |
rc_exp = cmp->in(2); |
|
1019 |
limit = cmp->in(1); |
|
1020 |
limit_c = phase->get_ctrl(limit); |
|
54703 | 1021 |
if (is_member(phase->get_loop(limit_c))) { |
1 | 1022 |
continue; // Both inputs are loop varying; cannot RCE |
54703 | 1023 |
} |
1 | 1024 |
} |
1025 |
||
1026 |
if (!phase->is_scaled_iv_plus_offset(rc_exp, trip_counter, NULL, NULL)) { |
|
1027 |
continue; |
|
1028 |
} |
|
55150 | 1029 |
// Found a test like 'trip+off vs limit'. Test is an IfNode, has two (2) |
1030 |
// projections. If BOTH are in the loop we need loop unswitching instead |
|
1031 |
// of iteration splitting. |
|
54703 | 1032 |
if (is_loop_exit(iff)) { |
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
1033 |
// Found valid reason to split iterations (if there is room). |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
1034 |
// NOTE: Usually a gross overestimate. |
55150 | 1035 |
return phase->may_require_nodes(est_loop_clone_sz(2)); |
54703 | 1036 |
} |
1 | 1037 |
} // End of is IF |
1038 |
} |
|
1039 |
||
1040 |
return false; |
|
1041 |
} |
|
1042 |
||
1043 |
//------------------------------policy_peel_only------------------------------- |
|
1044 |
// Return TRUE or FALSE if the loop should NEVER be RCE'd or aligned. Useful |
|
1045 |
// for unrolling loops with NO array accesses. |
|
54703 | 1046 |
bool IdealLoopTree::policy_peel_only(PhaseIdealLoop *phase) const { |
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
1047 |
|
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
1048 |
// If nodes are depleted, some transform has miscalculated its needs. |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
1049 |
assert(!phase->exceeding_node_budget(), "sanity"); |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
1050 |
|
31772 | 1051 |
// check for vectorized loops, any peeling done was already applied |
54698
3ebf58dbf5d8
8223137: Rename predicate 'do_unroll_only()' to 'is_unroll_only()'.
phedlin
parents:
54022
diff
changeset
|
1052 |
if (_head->is_CountedLoop() && _head->as_CountedLoop()->is_unroll_only()) { |
3ebf58dbf5d8
8223137: Rename predicate 'do_unroll_only()' to 'is_unroll_only()'.
phedlin
parents:
54022
diff
changeset
|
1053 |
return false; |
3ebf58dbf5d8
8223137: Rename predicate 'do_unroll_only()' to 'is_unroll_only()'.
phedlin
parents:
54022
diff
changeset
|
1054 |
} |
1 | 1055 |
|
54703 | 1056 |
for (uint i = 0; i < _body.size(); i++) { |
1057 |
if (_body[i]->is_Mem()) { |
|
1 | 1058 |
return false; |
54703 | 1059 |
} |
1060 |
} |
|
1 | 1061 |
// No memory accesses at all! |
1062 |
return true; |
|
1063 |
} |
|
1064 |
||
1065 |
//------------------------------clone_up_backedge_goo-------------------------- |
|
1066 |
// If Node n lives in the back_ctrl block and cannot float, we clone a private |
|
1067 |
// version of n in preheader_ctrl block and return that, otherwise return n. |
|
54703 | 1068 |
Node *PhaseIdealLoop::clone_up_backedge_goo(Node *back_ctrl, Node *preheader_ctrl, Node *n, VectorSet &visited, Node_Stack &clones) { |
1069 |
if (get_ctrl(n) != back_ctrl) return n; |
|
1 | 1070 |
|
10011
e8b38f7b9959
7044738: Loop unroll optimization causes incorrect result
kvn
parents:
10005
diff
changeset
|
1071 |
// Only visit once |
e8b38f7b9959
7044738: Loop unroll optimization causes incorrect result
kvn
parents:
10005
diff
changeset
|
1072 |
if (visited.test_set(n->_idx)) { |
e8b38f7b9959
7044738: Loop unroll optimization causes incorrect result
kvn
parents:
10005
diff
changeset
|
1073 |
Node *x = clones.find(n->_idx); |
54703 | 1074 |
return (x != NULL) ? x : n; |
10011
e8b38f7b9959
7044738: Loop unroll optimization causes incorrect result
kvn
parents:
10005
diff
changeset
|
1075 |
} |
e8b38f7b9959
7044738: Loop unroll optimization causes incorrect result
kvn
parents:
10005
diff
changeset
|
1076 |
|
1 | 1077 |
Node *x = NULL; // If required, a clone of 'n' |
1078 |
// Check for 'n' being pinned in the backedge. |
|
54703 | 1079 |
if (n->in(0) && n->in(0) == back_ctrl) { |
10011
e8b38f7b9959
7044738: Loop unroll optimization causes incorrect result
kvn
parents:
10005
diff
changeset
|
1080 |
assert(clones.find(n->_idx) == NULL, "dead loop"); |
1 | 1081 |
x = n->clone(); // Clone a copy of 'n' to preheader |
10011
e8b38f7b9959
7044738: Loop unroll optimization causes incorrect result
kvn
parents:
10005
diff
changeset
|
1082 |
clones.push(x, n->_idx); |
54703 | 1083 |
x->set_req(0, preheader_ctrl); // Fix x's control input to preheader |
1 | 1084 |
} |
1085 |
||
1086 |
// Recursive fixup any other input edges into x. |
|
1087 |
// If there are no changes we can just return 'n', otherwise |
|
1088 |
// we need to clone a private copy and change it. |
|
54703 | 1089 |
for (uint i = 1; i < n->req(); i++) { |
1090 |
Node *g = clone_up_backedge_goo(back_ctrl, preheader_ctrl, n->in(i), visited, clones); |
|
1091 |
if (g != n->in(i)) { |
|
1092 |
if (!x) { |
|
10011
e8b38f7b9959
7044738: Loop unroll optimization causes incorrect result
kvn
parents:
10005
diff
changeset
|
1093 |
assert(clones.find(n->_idx) == NULL, "dead loop"); |
1 | 1094 |
x = n->clone(); |
10011
e8b38f7b9959
7044738: Loop unroll optimization causes incorrect result
kvn
parents:
10005
diff
changeset
|
1095 |
clones.push(x, n->_idx); |
e8b38f7b9959
7044738: Loop unroll optimization causes incorrect result
kvn
parents:
10005
diff
changeset
|
1096 |
} |
1 | 1097 |
x->set_req(i, g); |
1098 |
} |
|
1099 |
} |
|
54703 | 1100 |
if (x) { // x can legally float to pre-header location |
1101 |
register_new_node(x, preheader_ctrl); |
|
1 | 1102 |
return x; |
1103 |
} else { // raise n to cover LCA of uses |
|
54703 | 1104 |
set_ctrl(n, find_non_split_ctrl(back_ctrl->in(0))); |
1 | 1105 |
} |
1106 |
return n; |
|
1107 |
} |
|
1108 |
||
49487
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
1109 |
Node* PhaseIdealLoop::cast_incr_before_loop(Node* incr, Node* ctrl, Node* loop) { |
27708
8a8710cb8fc4
8054478: C2: Incorrectly compiled char[] array access crashes JVM
roland
parents:
27707
diff
changeset
|
1110 |
Node* castii = new CastIINode(incr, TypeInt::INT, true); |
8a8710cb8fc4
8054478: C2: Incorrectly compiled char[] array access crashes JVM
roland
parents:
27707
diff
changeset
|
1111 |
castii->set_req(0, ctrl); |
8a8710cb8fc4
8054478: C2: Incorrectly compiled char[] array access crashes JVM
roland
parents:
27707
diff
changeset
|
1112 |
register_new_node(castii, ctrl); |
8a8710cb8fc4
8054478: C2: Incorrectly compiled char[] array access crashes JVM
roland
parents:
27707
diff
changeset
|
1113 |
for (DUIterator_Fast imax, i = incr->fast_outs(imax); i < imax; i++) { |
8a8710cb8fc4
8054478: C2: Incorrectly compiled char[] array access crashes JVM
roland
parents:
27707
diff
changeset
|
1114 |
Node* n = incr->fast_out(i); |
8a8710cb8fc4
8054478: C2: Incorrectly compiled char[] array access crashes JVM
roland
parents:
27707
diff
changeset
|
1115 |
if (n->is_Phi() && n->in(0) == loop) { |
8a8710cb8fc4
8054478: C2: Incorrectly compiled char[] array access crashes JVM
roland
parents:
27707
diff
changeset
|
1116 |
int nrep = n->replace_edge(incr, castii); |
49487
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
1117 |
return castii; |
27708
8a8710cb8fc4
8054478: C2: Incorrectly compiled char[] array access crashes JVM
roland
parents:
27707
diff
changeset
|
1118 |
} |
8a8710cb8fc4
8054478: C2: Incorrectly compiled char[] array access crashes JVM
roland
parents:
27707
diff
changeset
|
1119 |
} |
49487
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
1120 |
return NULL; |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
1121 |
} |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
1122 |
|
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
1123 |
// Make a copy of the skeleton range check predicates before the main |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
1124 |
// loop and set the initial value of loop as input. After unrolling, |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
1125 |
// the range of values for the induction variable in the main loop can |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
1126 |
// fall outside the allowed range of values by the array access (main |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
1127 |
// loop is never executed). When that happens, range check |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
1128 |
// CastII/ConvI2L nodes cause some data paths to die. For consistency, |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
1129 |
// the control paths must die too but the range checks were removed by |
50632
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1130 |
// predication. The range checks that we add here guarantee that they do. |
53306
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1131 |
void PhaseIdealLoop::duplicate_predicates_helper(Node* predicate, Node* start, Node* end, |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1132 |
IdealLoopTree* outer_loop, LoopNode* outer_main_head, |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1133 |
uint dd_main_head) { |
50623
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
1134 |
if (predicate != NULL) { |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
1135 |
IfNode* iff = predicate->in(0)->as_If(); |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
1136 |
ProjNode* uncommon_proj = iff->proj_out(1 - predicate->as_Proj()->_con); |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
1137 |
Node* rgn = uncommon_proj->unique_ctrl_out(); |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
1138 |
assert(rgn->is_Region() || rgn->is_Call(), "must be a region or call uct"); |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
1139 |
assert(iff->in(1)->in(1)->Opcode() == Op_Opaque1, "unexpected predicate shape"); |
50632
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1140 |
predicate = iff->in(0); |
50623
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
1141 |
Node* current_proj = outer_main_head->in(LoopNode::EntryControl); |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
1142 |
Node* prev_proj = current_proj; |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
1143 |
while (predicate != NULL && predicate->is_Proj() && predicate->in(0)->is_If()) { |
50632
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1144 |
iff = predicate->in(0)->as_If(); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1145 |
uncommon_proj = iff->proj_out(1 - predicate->as_Proj()->_con); |
50623
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
1146 |
if (uncommon_proj->unique_ctrl_out() != rgn) |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
1147 |
break; |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
1148 |
if (iff->in(1)->Opcode() == Op_Opaque4) { |
53306
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1149 |
assert(skeleton_predicate_has_opaque(iff), "unexpected"); |
50632
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1150 |
// Clone the predicate twice and initialize one with the initial |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1151 |
// value of the loop induction variable. Leave the other predicate |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1152 |
// to be initialized when increasing the stride during loop unrolling. |
53306
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1153 |
prev_proj = clone_skeleton_predicate(iff, start, predicate, uncommon_proj, current_proj, outer_loop, prev_proj); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1154 |
assert(skeleton_predicate_has_opaque(prev_proj->in(0)->as_If()) == (start->Opcode() == Op_Opaque1), ""); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1155 |
prev_proj = clone_skeleton_predicate(iff, end, predicate, uncommon_proj, current_proj, outer_loop, prev_proj); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1156 |
assert(skeleton_predicate_has_opaque(prev_proj->in(0)->as_If()) == (end->Opcode() == Op_Opaque1), ""); |
50632
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1157 |
// Remove the skeleton predicate from the pre-loop |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1158 |
_igvn.replace_input_of(iff, 1, _igvn.intcon(1)); |
50623
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
1159 |
} |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
1160 |
predicate = predicate->in(0)->in(0); |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
1161 |
} |
50632
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1162 |
_igvn.replace_input_of(outer_main_head, LoopNode::EntryControl, prev_proj); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1163 |
set_idom(outer_main_head, prev_proj, dd_main_head); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1164 |
} |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1165 |
} |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1166 |
|
53306
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1167 |
static bool skeleton_follow_inputs(Node* n, int op) { |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1168 |
return (n->is_Bool() || |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1169 |
n->is_Cmp() || |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1170 |
op == Op_AndL || |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1171 |
op == Op_OrL || |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1172 |
op == Op_RShiftL || |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1173 |
op == Op_LShiftL || |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1174 |
op == Op_AddL || |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1175 |
op == Op_AddI || |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1176 |
op == Op_MulL || |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1177 |
op == Op_MulI || |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1178 |
op == Op_SubL || |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1179 |
op == Op_SubI || |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1180 |
op == Op_ConvI2L); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1181 |
} |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1182 |
|
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1183 |
bool PhaseIdealLoop::skeleton_predicate_has_opaque(IfNode* iff) { |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1184 |
ResourceMark rm; |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1185 |
Unique_Node_List wq; |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1186 |
wq.push(iff->in(1)->in(1)); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1187 |
for (uint i = 0; i < wq.size(); i++) { |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1188 |
Node* n = wq.at(i); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1189 |
int op = n->Opcode(); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1190 |
if (skeleton_follow_inputs(n, op)) { |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1191 |
for (uint j = 1; j < n->req(); j++) { |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1192 |
Node* m = n->in(j); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1193 |
if (m != NULL) { |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1194 |
wq.push(m); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1195 |
} |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1196 |
} |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1197 |
continue; |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1198 |
} |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1199 |
if (op == Op_Opaque1) { |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1200 |
return true; |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1201 |
} |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1202 |
} |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1203 |
return false; |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1204 |
} |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1205 |
|
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1206 |
Node* PhaseIdealLoop::clone_skeleton_predicate(Node* iff, Node* value, Node* predicate, Node* uncommon_proj, |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1207 |
Node* current_proj, IdealLoopTree* outer_loop, Node* prev_proj) { |
50632
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1208 |
Node_Stack to_clone(2); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1209 |
to_clone.push(iff->in(1), 1); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1210 |
uint current = C->unique(); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1211 |
Node* result = NULL; |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1212 |
// Look for the opaque node to replace with the new value |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1213 |
// and clone everything in between. We keep the Opaque4 node |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1214 |
// so the duplicated predicates are eliminated once loop |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1215 |
// opts are over: they are here only to keep the IR graph |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1216 |
// consistent. |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1217 |
do { |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1218 |
Node* n = to_clone.node(); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1219 |
uint i = to_clone.index(); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1220 |
Node* m = n->in(i); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1221 |
int op = m->Opcode(); |
53306
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1222 |
if (skeleton_follow_inputs(m, op)) { |
50632
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1223 |
to_clone.push(m, 1); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1224 |
continue; |
50623
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
1225 |
} |
50632
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1226 |
if (op == Op_Opaque1) { |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1227 |
if (n->_idx < current) { |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1228 |
n = n->clone(); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1229 |
} |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1230 |
n->set_req(i, value); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1231 |
register_new_node(n, current_proj); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1232 |
to_clone.set_node(n); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1233 |
} |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1234 |
for (;;) { |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1235 |
Node* cur = to_clone.node(); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1236 |
uint j = to_clone.index(); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1237 |
if (j+1 < cur->req()) { |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1238 |
to_clone.set_index(j+1); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1239 |
break; |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1240 |
} |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1241 |
to_clone.pop(); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1242 |
if (to_clone.size() == 0) { |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1243 |
result = cur; |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1244 |
break; |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1245 |
} |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1246 |
Node* next = to_clone.node(); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1247 |
j = to_clone.index(); |
53306
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1248 |
if (next->in(j) != cur) { |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1249 |
assert(cur->_idx >= current || next->in(j)->Opcode() == Op_Opaque1, "new node or Opaque1 being replaced"); |
50632
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1250 |
if (next->_idx < current) { |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1251 |
next = next->clone(); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1252 |
register_new_node(next, current_proj); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1253 |
to_clone.set_node(next); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1254 |
} |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1255 |
next->set_req(j, cur); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1256 |
} |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1257 |
} |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1258 |
} while (result == NULL); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1259 |
assert(result->_idx >= current, "new node expected"); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1260 |
|
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1261 |
Node* proj = predicate->clone(); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1262 |
Node* other_proj = uncommon_proj->clone(); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1263 |
Node* new_iff = iff->clone(); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1264 |
new_iff->set_req(1, result); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1265 |
proj->set_req(0, new_iff); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1266 |
other_proj->set_req(0, new_iff); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1267 |
Node *frame = new ParmNode(C->start(), TypeFunc::FramePtr); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1268 |
register_new_node(frame, C->start()); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1269 |
// It's impossible for the predicate to fail at runtime. Use an Halt node. |
58061
fafba5cf3546
8225653: Provide more information when hitting SIGILL from HaltNode
chagedorn
parents:
55150
diff
changeset
|
1270 |
Node* halt = new HaltNode(other_proj, frame, "duplicated predicate failed which is impossible"); |
50632
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1271 |
C->root()->add_req(halt); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1272 |
new_iff->set_req(0, prev_proj); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1273 |
|
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1274 |
register_control(new_iff, outer_loop->_parent, prev_proj); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1275 |
register_control(proj, outer_loop->_parent, new_iff); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1276 |
register_control(other_proj, _ltree_root, new_iff); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1277 |
register_control(halt, _ltree_root, other_proj); |
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1278 |
return proj; |
50623
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
1279 |
} |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
1280 |
|
53306
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1281 |
void PhaseIdealLoop::duplicate_predicates(CountedLoopNode* pre_head, Node* start, Node* end, |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1282 |
IdealLoopTree* outer_loop, LoopNode* outer_main_head, |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1283 |
uint dd_main_head) { |
50561
5756e8eecb17
8205034: [BACKOUT] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50558
diff
changeset
|
1284 |
if (UseLoopPredicate) { |
5756e8eecb17
8205034: [BACKOUT] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50558
diff
changeset
|
1285 |
Node* entry = pre_head->in(LoopNode::EntryControl); |
5756e8eecb17
8205034: [BACKOUT] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50558
diff
changeset
|
1286 |
Node* predicate = NULL; |
5756e8eecb17
8205034: [BACKOUT] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50558
diff
changeset
|
1287 |
predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_loop_limit_check); |
5756e8eecb17
8205034: [BACKOUT] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50558
diff
changeset
|
1288 |
if (predicate != NULL) { |
52608
61241fc2217a
8211451: ~2.5% regression on compression benchmark starting with 12-b11
roland
parents:
51078
diff
changeset
|
1289 |
entry = skip_loop_predicates(entry); |
49487
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
1290 |
} |
50623
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
1291 |
Node* profile_predicate = NULL; |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
1292 |
if (UseProfiledLoopPredicate) { |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
1293 |
profile_predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_profile_predicate); |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
1294 |
if (profile_predicate != NULL) { |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
1295 |
entry = skip_loop_predicates(entry); |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
1296 |
} |
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
1297 |
} |
50561
5756e8eecb17
8205034: [BACKOUT] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50558
diff
changeset
|
1298 |
predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate); |
53306
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1299 |
duplicate_predicates_helper(predicate, start, end, outer_loop, outer_main_head, dd_main_head); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1300 |
duplicate_predicates_helper(profile_predicate, start, end, outer_loop, outer_main_head, dd_main_head); |
49487
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
1301 |
} |
27708
8a8710cb8fc4
8054478: C2: Incorrectly compiled char[] array access crashes JVM
roland
parents:
27707
diff
changeset
|
1302 |
} |
8a8710cb8fc4
8054478: C2: Incorrectly compiled char[] array access crashes JVM
roland
parents:
27707
diff
changeset
|
1303 |
|
1 | 1304 |
//------------------------------insert_pre_post_loops-------------------------- |
1305 |
// Insert pre and post loops. If peel_only is set, the pre-loop can not have |
|
1306 |
// more iterations added. It acts as a 'peel' only, no lower-bound RCE, no |
|
1307 |
// alignment. Useful to unroll loops that do no array accesses. |
|
54703 | 1308 |
void PhaseIdealLoop::insert_pre_post_loops(IdealLoopTree *loop, Node_List &old_new, bool peel_only) { |
1 | 1309 |
|
8732
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
1310 |
#ifndef PRODUCT |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
1311 |
if (TraceLoopOpts) { |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
1312 |
if (peel_only) |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
1313 |
tty->print("PeelMainPost "); |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
1314 |
else |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
1315 |
tty->print("PreMainPost "); |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
1316 |
loop->dump_head(); |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
1317 |
} |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
1318 |
#endif |
1 | 1319 |
C->set_major_progress(); |
1320 |
||
1321 |
// Find common pieces of the loop being guarded with pre & post loops |
|
1322 |
CountedLoopNode *main_head = loop->_head->as_CountedLoop(); |
|
54703 | 1323 |
assert(main_head->is_normal_loop(), ""); |
1 | 1324 |
CountedLoopEndNode *main_end = main_head->loopexit(); |
54703 | 1325 |
assert(main_end->outcnt() == 2, "1 true, 1 false path only"); |
1 | 1326 |
|
1327 |
Node *pre_header= main_head->in(LoopNode::EntryControl); |
|
1328 |
Node *init = main_head->init_trip(); |
|
1329 |
Node *incr = main_end ->incr(); |
|
1330 |
Node *limit = main_end ->limit(); |
|
1331 |
Node *stride = main_end ->stride(); |
|
1332 |
Node *cmp = main_end ->cmp_node(); |
|
1333 |
BoolTest::mask b_test = main_end->test_trip(); |
|
1334 |
||
1335 |
// Need only 1 user of 'bol' because I will be hacking the loop bounds. |
|
1336 |
Node *bol = main_end->in(CountedLoopEndNode::TestValue); |
|
54703 | 1337 |
if (bol->outcnt() != 1) { |
1 | 1338 |
bol = bol->clone(); |
1339 |
register_new_node(bol,main_end->in(CountedLoopEndNode::TestControl)); |
|
25913
81dbc151e91c
8040213: C2 does not put all modified nodes on IGVN worklist
thartmann
parents:
24923
diff
changeset
|
1340 |
_igvn.replace_input_of(main_end, CountedLoopEndNode::TestValue, bol); |
1 | 1341 |
} |
1342 |
// Need only 1 user of 'cmp' because I will be hacking the loop bounds. |
|
54703 | 1343 |
if (cmp->outcnt() != 1) { |
1 | 1344 |
cmp = cmp->clone(); |
1345 |
register_new_node(cmp,main_end->in(CountedLoopEndNode::TestControl)); |
|
25913
81dbc151e91c
8040213: C2 does not put all modified nodes on IGVN worklist
thartmann
parents:
24923
diff
changeset
|
1346 |
_igvn.replace_input_of(bol, 1, cmp); |
1 | 1347 |
} |
1348 |
||
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1349 |
// Add the post loop |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1350 |
CountedLoopNode *post_head = NULL; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1351 |
Node *main_exit = insert_post_loop(loop, old_new, main_head, main_end, incr, limit, post_head); |
1 | 1352 |
|
1353 |
//------------------------------ |
|
1354 |
// Step B: Create Pre-Loop. |
|
1355 |
||
1356 |
// Step B1: Clone the loop body. The clone becomes the pre-loop. The main |
|
1357 |
// loop pre-header illegally has 2 control users (old & new loops). |
|
48145 | 1358 |
LoopNode* outer_main_head = main_head; |
1359 |
IdealLoopTree* outer_loop = loop; |
|
1360 |
if (main_head->is_strip_mined()) { |
|
1361 |
main_head->verify_strip_mined(1); |
|
1362 |
outer_main_head = main_head->outer_loop(); |
|
1363 |
outer_loop = loop->_parent; |
|
1364 |
assert(outer_loop->_head == outer_main_head, "broken loop tree"); |
|
1365 |
} |
|
1366 |
uint dd_main_head = dom_depth(outer_main_head); |
|
1367 |
clone_loop(loop, old_new, dd_main_head, ControlAroundStripMined); |
|
1 | 1368 |
CountedLoopNode* pre_head = old_new[main_head->_idx]->as_CountedLoop(); |
1369 |
CountedLoopEndNode* pre_end = old_new[main_end ->_idx]->as_CountedLoopEnd(); |
|
1370 |
pre_head->set_pre_loop(main_head); |
|
1371 |
Node *pre_incr = old_new[incr->_idx]; |
|
1372 |
||
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1399
diff
changeset
|
1373 |
// Reduce the pre-loop trip count. |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1399
diff
changeset
|
1374 |
pre_end->_prob = PROB_FAIR; |
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1399
diff
changeset
|
1375 |
|
1 | 1376 |
// Find the pre-loop normal exit. |
1377 |
Node* pre_exit = pre_end->proj_out(false); |
|
54703 | 1378 |
assert(pre_exit->Opcode() == Op_IfFalse, ""); |
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
1379 |
IfFalseNode *new_pre_exit = new IfFalseNode(pre_end); |
54703 | 1380 |
_igvn.register_new_node_with_optimizer(new_pre_exit); |
1 | 1381 |
set_idom(new_pre_exit, pre_end, dd_main_head); |
48145 | 1382 |
set_loop(new_pre_exit, outer_loop->_parent); |
1 | 1383 |
|
1384 |
// Step B2: Build a zero-trip guard for the main-loop. After leaving the |
|
1385 |
// pre-loop, the main-loop may not execute at all. Later in life this |
|
1386 |
// zero-trip guard will become the minimum-trip guard when we unroll |
|
1387 |
// the main-loop. |
|
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
1388 |
Node *min_opaq = new Opaque1Node(C, limit); |
54703 | 1389 |
Node *min_cmp = new CmpINode(pre_incr, min_opaq); |
1390 |
Node *min_bol = new BoolNode(min_cmp, b_test); |
|
1391 |
register_new_node(min_opaq, new_pre_exit); |
|
1392 |
register_new_node(min_cmp , new_pre_exit); |
|
1393 |
register_new_node(min_bol , new_pre_exit); |
|
1 | 1394 |
|
1432
44f076e3d2a4
6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents:
1399
diff
changeset
|
1395 |
// Build the IfNode (assume the main-loop is executed always). |
54703 | 1396 |
IfNode *min_iff = new IfNode(new_pre_exit, min_bol, PROB_ALWAYS, COUNT_UNKNOWN); |
1397 |
_igvn.register_new_node_with_optimizer(min_iff); |
|
1 | 1398 |
set_idom(min_iff, new_pre_exit, dd_main_head); |
48145 | 1399 |
set_loop(min_iff, outer_loop->_parent); |
1 | 1400 |
|
1401 |
// Plug in the false-path, taken if we need to skip main-loop |
|
54703 | 1402 |
_igvn.hash_delete(pre_exit); |
1 | 1403 |
pre_exit->set_req(0, min_iff); |
1404 |
set_idom(pre_exit, min_iff, dd_main_head); |
|
48145 | 1405 |
set_idom(pre_exit->unique_ctrl_out(), min_iff, dd_main_head); |
1 | 1406 |
// Make the true-path, must enter the main loop |
54703 | 1407 |
Node *min_taken = new IfTrueNode(min_iff); |
1408 |
_igvn.register_new_node_with_optimizer(min_taken); |
|
1 | 1409 |
set_idom(min_taken, min_iff, dd_main_head); |
48145 | 1410 |
set_loop(min_taken, outer_loop->_parent); |
1 | 1411 |
// Plug in the true path |
48145 | 1412 |
_igvn.hash_delete(outer_main_head); |
1413 |
outer_main_head->set_req(LoopNode::EntryControl, min_taken); |
|
1414 |
set_idom(outer_main_head, min_taken, dd_main_head); |
|
1 | 1415 |
|
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1416 |
Arena *a = Thread::current()->resource_area(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1417 |
VectorSet visited(a); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1418 |
Node_Stack clones(a, main_head->back_control()->outcnt()); |
1 | 1419 |
// Step B3: Make the fall-in values to the main-loop come from the |
1420 |
// fall-out values of the pre-loop. |
|
1421 |
for (DUIterator_Fast i2max, i2 = main_head->fast_outs(i2max); i2 < i2max; i2++) { |
|
1422 |
Node* main_phi = main_head->fast_out(i2); |
|
54703 | 1423 |
if (main_phi->is_Phi() && main_phi->in(0) == main_head && main_phi->outcnt() > 0) { |
1 | 1424 |
Node *pre_phi = old_new[main_phi->_idx]; |
1425 |
Node *fallpre = clone_up_backedge_goo(pre_head->back_control(), |
|
48145 | 1426 |
main_head->skip_strip_mined()->in(LoopNode::EntryControl), |
10011
e8b38f7b9959
7044738: Loop unroll optimization causes incorrect result
kvn
parents:
10005
diff
changeset
|
1427 |
pre_phi->in(LoopNode::LoopBackControl), |
e8b38f7b9959
7044738: Loop unroll optimization causes incorrect result
kvn
parents:
10005
diff
changeset
|
1428 |
visited, clones); |
1 | 1429 |
_igvn.hash_delete(main_phi); |
54703 | 1430 |
main_phi->set_req(LoopNode::EntryControl, fallpre); |
1 | 1431 |
} |
1432 |
} |
|
1433 |
||
27708
8a8710cb8fc4
8054478: C2: Incorrectly compiled char[] array access crashes JVM
roland
parents:
27707
diff
changeset
|
1434 |
// Nodes inside the loop may be control dependent on a predicate |
8a8710cb8fc4
8054478: C2: Incorrectly compiled char[] array access crashes JVM
roland
parents:
27707
diff
changeset
|
1435 |
// that was moved before the preloop. If the back branch of the main |
8a8710cb8fc4
8054478: C2: Incorrectly compiled char[] array access crashes JVM
roland
parents:
27707
diff
changeset
|
1436 |
// or post loops becomes dead, those nodes won't be dependent on the |
8a8710cb8fc4
8054478: C2: Incorrectly compiled char[] array access crashes JVM
roland
parents:
27707
diff
changeset
|
1437 |
// test that guards that loop nest anymore which could lead to an |
8a8710cb8fc4
8054478: C2: Incorrectly compiled char[] array access crashes JVM
roland
parents:
27707
diff
changeset
|
1438 |
// incorrect array access because it executes independently of the |
8a8710cb8fc4
8054478: C2: Incorrectly compiled char[] array access crashes JVM
roland
parents:
27707
diff
changeset
|
1439 |
// test that was guarding the loop nest. We add a special CastII on |
8a8710cb8fc4
8054478: C2: Incorrectly compiled char[] array access crashes JVM
roland
parents:
27707
diff
changeset
|
1440 |
// the if branch that enters the loop, between the input induction |
8a8710cb8fc4
8054478: C2: Incorrectly compiled char[] array access crashes JVM
roland
parents:
27707
diff
changeset
|
1441 |
// variable value and the induction variable Phi to preserve correct |
8a8710cb8fc4
8054478: C2: Incorrectly compiled char[] array access crashes JVM
roland
parents:
27707
diff
changeset
|
1442 |
// dependencies. |
8a8710cb8fc4
8054478: C2: Incorrectly compiled char[] array access crashes JVM
roland
parents:
27707
diff
changeset
|
1443 |
|
8a8710cb8fc4
8054478: C2: Incorrectly compiled char[] array access crashes JVM
roland
parents:
27707
diff
changeset
|
1444 |
// CastII for the main loop: |
54703 | 1445 |
Node* castii = cast_incr_before_loop(pre_incr, min_taken, main_head); |
49487
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
1446 |
assert(castii != NULL, "no castII inserted"); |
53306
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1447 |
Node* opaque_castii = new Opaque1Node(C, castii); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1448 |
register_new_node(opaque_castii, outer_main_head->in(LoopNode::EntryControl)); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1449 |
duplicate_predicates(pre_head, castii, opaque_castii, outer_loop, outer_main_head, dd_main_head); |
27708
8a8710cb8fc4
8054478: C2: Incorrectly compiled char[] array access crashes JVM
roland
parents:
27707
diff
changeset
|
1450 |
|
1 | 1451 |
// Step B4: Shorten the pre-loop to run only 1 iteration (for now). |
1452 |
// RCE and alignment may change this later. |
|
1453 |
Node *cmp_end = pre_end->cmp_node(); |
|
54703 | 1454 |
assert(cmp_end->in(2) == limit, ""); |
1455 |
Node *pre_limit = new AddINode(init, stride); |
|
1 | 1456 |
|
1457 |
// Save the original loop limit in this Opaque1 node for |
|
1458 |
// use by range check elimination. |
|
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
1459 |
Node *pre_opaq = new Opaque1Node(C, pre_limit, limit); |
1 | 1460 |
|
54703 | 1461 |
register_new_node(pre_limit, pre_head->in(0)); |
1462 |
register_new_node(pre_opaq , pre_head->in(0)); |
|
1 | 1463 |
|
1464 |
// Since no other users of pre-loop compare, I can hack limit directly |
|
54703 | 1465 |
assert(cmp_end->outcnt() == 1, "no other users"); |
1 | 1466 |
_igvn.hash_delete(cmp_end); |
1467 |
cmp_end->set_req(2, peel_only ? pre_limit : pre_opaq); |
|
1468 |
||
1469 |
// Special case for not-equal loop bounds: |
|
1470 |
// Change pre loop test, main loop test, and the |
|
1471 |
// main loop guard test to use lt or gt depending on stride |
|
1472 |
// direction: |
|
1473 |
// positive stride use < |
|
1474 |
// negative stride use > |
|
10005 | 1475 |
// |
1476 |
// not-equal test is kept for post loop to handle case |
|
1477 |
// when init > limit when stride > 0 (and reverse). |
|
1 | 1478 |
|
1479 |
if (pre_end->in(CountedLoopEndNode::TestValue)->as_Bool()->_test._test == BoolTest::ne) { |
|
1480 |
||
1481 |
BoolTest::mask new_test = (main_end->stride_con() > 0) ? BoolTest::lt : BoolTest::gt; |
|
1482 |
// Modify pre loop end condition |
|
1483 |
Node* pre_bol = pre_end->in(CountedLoopEndNode::TestValue)->as_Bool(); |
|
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
1484 |
BoolNode* new_bol0 = new BoolNode(pre_bol->in(1), new_test); |
54703 | 1485 |
register_new_node(new_bol0, pre_head->in(0)); |
25913
81dbc151e91c
8040213: C2 does not put all modified nodes on IGVN worklist
thartmann
parents:
24923
diff
changeset
|
1486 |
_igvn.replace_input_of(pre_end, CountedLoopEndNode::TestValue, new_bol0); |
1 | 1487 |
// Modify main loop guard condition |
1488 |
assert(min_iff->in(CountedLoopEndNode::TestValue) == min_bol, "guard okay"); |
|
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
1489 |
BoolNode* new_bol1 = new BoolNode(min_bol->in(1), new_test); |
54703 | 1490 |
register_new_node(new_bol1, new_pre_exit); |
1 | 1491 |
_igvn.hash_delete(min_iff); |
1492 |
min_iff->set_req(CountedLoopEndNode::TestValue, new_bol1); |
|
1493 |
// Modify main loop end condition |
|
1494 |
BoolNode* main_bol = main_end->in(CountedLoopEndNode::TestValue)->as_Bool(); |
|
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
1495 |
BoolNode* new_bol2 = new BoolNode(main_bol->in(1), new_test); |
54703 | 1496 |
register_new_node(new_bol2, main_end->in(CountedLoopEndNode::TestControl)); |
25913
81dbc151e91c
8040213: C2 does not put all modified nodes on IGVN worklist
thartmann
parents:
24923
diff
changeset
|
1497 |
_igvn.replace_input_of(main_end, CountedLoopEndNode::TestValue, new_bol2); |
1 | 1498 |
} |
1499 |
||
1500 |
// Flag main loop |
|
1501 |
main_head->set_main_loop(); |
|
54703 | 1502 |
if (peel_only) { |
1503 |
main_head->set_main_no_pre_loop(); |
|
1504 |
} |
|
1 | 1505 |
|
9446 | 1506 |
// Subtract a trip count for the pre-loop. |
1507 |
main_head->set_trip_count(main_head->trip_count() - 1); |
|
1508 |
||
1 | 1509 |
// It's difficult to be precise about the trip-counts |
1510 |
// for the pre/post loops. They are usually very short, |
|
1511 |
// so guess that 4 trips is a reasonable value. |
|
1512 |
post_head->set_profile_trip_cnt(4.0); |
|
1513 |
pre_head->set_profile_trip_cnt(4.0); |
|
1514 |
||
1515 |
// Now force out all loop-invariant dominating tests. The optimizer |
|
1516 |
// finds some, but we _know_ they are all useless. |
|
1517 |
peeled_dom_test_elim(loop,old_new); |
|
24020 | 1518 |
loop->record_for_igvn(); |
1 | 1519 |
} |
1520 |
||
36066 | 1521 |
//------------------------------insert_vector_post_loop------------------------ |
1522 |
// Insert a copy of the atomic unrolled vectorized main loop as a post loop, |
|
54703 | 1523 |
// unroll_policy has already informed us that more unrolling is about to |
1524 |
// happen to the main loop. The resultant post loop will serve as a |
|
1525 |
// vectorized drain loop. |
|
36066 | 1526 |
void PhaseIdealLoop::insert_vector_post_loop(IdealLoopTree *loop, Node_List &old_new) { |
1527 |
if (!loop->_head->is_CountedLoop()) return; |
|
1528 |
||
1529 |
CountedLoopNode *cl = loop->_head->as_CountedLoop(); |
|
1530 |
||
1531 |
// only process vectorized main loops |
|
1532 |
if (!cl->is_vectorized_loop() || !cl->is_main_loop()) return; |
|
1533 |
||
1534 |
int slp_max_unroll_factor = cl->slp_max_unroll(); |
|
1535 |
int cur_unroll = cl->unrolled_count(); |
|
1536 |
||
1537 |
if (slp_max_unroll_factor == 0) return; |
|
1538 |
||
1539 |
// only process atomic unroll vector loops (not super unrolled after vectorization) |
|
1540 |
if (cur_unroll != slp_max_unroll_factor) return; |
|
1541 |
||
1542 |
// we only ever process this one time |
|
1543 |
if (cl->has_atomic_post_loop()) return; |
|
1544 |
||
55150 | 1545 |
if (!may_require_nodes(loop->est_loop_clone_sz(2))) { |
1546 |
return; |
|
1547 |
} |
|
1548 |
||
36066 | 1549 |
#ifndef PRODUCT |
1550 |
if (TraceLoopOpts) { |
|
1551 |
tty->print("PostVector "); |
|
1552 |
loop->dump_head(); |
|
1553 |
} |
|
1554 |
#endif |
|
1555 |
C->set_major_progress(); |
|
1556 |
||
1557 |
// Find common pieces of the loop being guarded with pre & post loops |
|
1558 |
CountedLoopNode *main_head = loop->_head->as_CountedLoop(); |
|
1559 |
CountedLoopEndNode *main_end = main_head->loopexit(); |
|
1560 |
// diagnostic to show loop end is not properly formed |
|
1561 |
assert(main_end->outcnt() == 2, "1 true, 1 false path only"); |
|
1562 |
||
1563 |
// mark this loop as processed |
|
1564 |
main_head->mark_has_atomic_post_loop(); |
|
1565 |
||
1566 |
Node *incr = main_end->incr(); |
|
1567 |
Node *limit = main_end->limit(); |
|
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1568 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1569 |
// In this case we throw away the result as we are not using it to connect anything else. |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1570 |
CountedLoopNode *post_head = NULL; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1571 |
insert_post_loop(loop, old_new, main_head, main_end, incr, limit, post_head); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1572 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1573 |
// It's difficult to be precise about the trip-counts |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1574 |
// for post loops. They are usually very short, |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1575 |
// so guess that unit vector trips is a reasonable value. |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1576 |
post_head->set_profile_trip_cnt(cur_unroll); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1577 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1578 |
// Now force out all loop-invariant dominating tests. The optimizer |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1579 |
// finds some, but we _know_ they are all useless. |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1580 |
peeled_dom_test_elim(loop, old_new); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1581 |
loop->record_for_igvn(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1582 |
} |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1583 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1584 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1585 |
//-------------------------insert_scalar_rced_post_loop------------------------ |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1586 |
// Insert a copy of the rce'd main loop as a post loop, |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1587 |
// We have not unrolled the main loop, so this is the right time to inject this. |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1588 |
// Later we will examine the partner of this post loop pair which still has range checks |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1589 |
// to see inject code which tests at runtime if the range checks are applicable. |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1590 |
void PhaseIdealLoop::insert_scalar_rced_post_loop(IdealLoopTree *loop, Node_List &old_new) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1591 |
if (!loop->_head->is_CountedLoop()) return; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1592 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1593 |
CountedLoopNode *cl = loop->_head->as_CountedLoop(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1594 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1595 |
// only process RCE'd main loops |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1596 |
if (!cl->is_main_loop() || cl->range_checks_present()) return; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1597 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1598 |
#ifndef PRODUCT |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1599 |
if (TraceLoopOpts) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1600 |
tty->print("PostScalarRce "); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1601 |
loop->dump_head(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1602 |
} |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1603 |
#endif |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1604 |
C->set_major_progress(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1605 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1606 |
// Find common pieces of the loop being guarded with pre & post loops |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1607 |
CountedLoopNode *main_head = loop->_head->as_CountedLoop(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1608 |
CountedLoopEndNode *main_end = main_head->loopexit(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1609 |
// diagnostic to show loop end is not properly formed |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1610 |
assert(main_end->outcnt() == 2, "1 true, 1 false path only"); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1611 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1612 |
Node *incr = main_end->incr(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1613 |
Node *limit = main_end->limit(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1614 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1615 |
// In this case we throw away the result as we are not using it to connect anything else. |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1616 |
CountedLoopNode *post_head = NULL; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1617 |
insert_post_loop(loop, old_new, main_head, main_end, incr, limit, post_head); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1618 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1619 |
// It's difficult to be precise about the trip-counts |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1620 |
// for post loops. They are usually very short, |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1621 |
// so guess that unit vector trips is a reasonable value. |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1622 |
post_head->set_profile_trip_cnt(4.0); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1623 |
post_head->set_is_rce_post_loop(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1624 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1625 |
// Now force out all loop-invariant dominating tests. The optimizer |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1626 |
// finds some, but we _know_ they are all useless. |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1627 |
peeled_dom_test_elim(loop, old_new); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1628 |
loop->record_for_igvn(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1629 |
} |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1630 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1631 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1632 |
//------------------------------insert_post_loop------------------------------- |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1633 |
// Insert post loops. Add a post loop to the given loop passed. |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1634 |
Node *PhaseIdealLoop::insert_post_loop(IdealLoopTree *loop, Node_List &old_new, |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1635 |
CountedLoopNode *main_head, CountedLoopEndNode *main_end, |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1636 |
Node *incr, Node *limit, CountedLoopNode *&post_head) { |
48145 | 1637 |
IfNode* outer_main_end = main_end; |
1638 |
IdealLoopTree* outer_loop = loop; |
|
1639 |
if (main_head->is_strip_mined()) { |
|
1640 |
main_head->verify_strip_mined(1); |
|
1641 |
outer_main_end = main_head->outer_loop_end(); |
|
1642 |
outer_loop = loop->_parent; |
|
1643 |
assert(outer_loop->_head == main_head->in(LoopNode::EntryControl), "broken loop tree"); |
|
1644 |
} |
|
36066 | 1645 |
|
1646 |
//------------------------------ |
|
1647 |
// Step A: Create a new post-Loop. |
|
48145 | 1648 |
Node* main_exit = outer_main_end->proj_out(false); |
36066 | 1649 |
assert(main_exit->Opcode() == Op_IfFalse, ""); |
1650 |
int dd_main_exit = dom_depth(main_exit); |
|
1651 |
||
40031
6cc034201dba
8159016: Over-unrolled loop is partially removed
thartmann
parents:
39429
diff
changeset
|
1652 |
// Step A1: Clone the loop body of main. The clone becomes the post-loop. |
36066 | 1653 |
// The main loop pre-header illegally has 2 control users (old & new loops). |
48145 | 1654 |
clone_loop(loop, old_new, dd_main_exit, ControlAroundStripMined); |
36066 | 1655 |
assert(old_new[main_end->_idx]->Opcode() == Op_CountedLoopEnd, ""); |
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1656 |
post_head = old_new[main_head->_idx]->as_CountedLoop(); |
36066 | 1657 |
post_head->set_normal_loop(); |
1658 |
post_head->set_post_loop(main_head); |
|
1659 |
||
1660 |
// Reduce the post-loop trip count. |
|
1661 |
CountedLoopEndNode* post_end = old_new[main_end->_idx]->as_CountedLoopEnd(); |
|
1662 |
post_end->_prob = PROB_FAIR; |
|
1663 |
||
1664 |
// Build the main-loop normal exit. |
|
48145 | 1665 |
IfFalseNode *new_main_exit = new IfFalseNode(outer_main_end); |
36066 | 1666 |
_igvn.register_new_node_with_optimizer(new_main_exit); |
48145 | 1667 |
set_idom(new_main_exit, outer_main_end, dd_main_exit); |
1668 |
set_loop(new_main_exit, outer_loop->_parent); |
|
36066 | 1669 |
|
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1670 |
// Step A2: Build a zero-trip guard for the post-loop. After leaving the |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1671 |
// main-loop, the post-loop may not execute at all. We 'opaque' the incr |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1672 |
// (the previous loop trip-counter exit value) because we will be changing |
36066 | 1673 |
// the exit value (via additional unrolling) so we cannot constant-fold away the zero |
1674 |
// trip guard until all unrolling is done. |
|
1675 |
Node *zer_opaq = new Opaque1Node(C, incr); |
|
1676 |
Node *zer_cmp = new CmpINode(zer_opaq, limit); |
|
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1677 |
Node *zer_bol = new BoolNode(zer_cmp, main_end->test_trip()); |
36066 | 1678 |
register_new_node(zer_opaq, new_main_exit); |
1679 |
register_new_node(zer_cmp, new_main_exit); |
|
1680 |
register_new_node(zer_bol, new_main_exit); |
|
1681 |
||
1682 |
// Build the IfNode |
|
1683 |
IfNode *zer_iff = new IfNode(new_main_exit, zer_bol, PROB_FAIR, COUNT_UNKNOWN); |
|
1684 |
_igvn.register_new_node_with_optimizer(zer_iff); |
|
1685 |
set_idom(zer_iff, new_main_exit, dd_main_exit); |
|
48145 | 1686 |
set_loop(zer_iff, outer_loop->_parent); |
36066 | 1687 |
|
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1688 |
// Plug in the false-path, taken if we need to skip this post-loop |
36066 | 1689 |
_igvn.replace_input_of(main_exit, 0, zer_iff); |
1690 |
set_idom(main_exit, zer_iff, dd_main_exit); |
|
1691 |
set_idom(main_exit->unique_out(), zer_iff, dd_main_exit); |
|
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1692 |
// Make the true-path, must enter this post loop |
36066 | 1693 |
Node *zer_taken = new IfTrueNode(zer_iff); |
1694 |
_igvn.register_new_node_with_optimizer(zer_taken); |
|
1695 |
set_idom(zer_taken, zer_iff, dd_main_exit); |
|
48145 | 1696 |
set_loop(zer_taken, outer_loop->_parent); |
36066 | 1697 |
// Plug in the true path |
1698 |
_igvn.hash_delete(post_head); |
|
1699 |
post_head->set_req(LoopNode::EntryControl, zer_taken); |
|
1700 |
set_idom(post_head, zer_taken, dd_main_exit); |
|
1701 |
||
1702 |
Arena *a = Thread::current()->resource_area(); |
|
1703 |
VectorSet visited(a); |
|
1704 |
Node_Stack clones(a, main_head->back_control()->outcnt()); |
|
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1705 |
// Step A3: Make the fall-in values to the post-loop come from the |
36066 | 1706 |
// fall-out values of the main-loop. |
1707 |
for (DUIterator_Fast imax, i = main_head->fast_outs(imax); i < imax; i++) { |
|
1708 |
Node* main_phi = main_head->fast_out(i); |
|
54703 | 1709 |
if (main_phi->is_Phi() && main_phi->in(0) == main_head && main_phi->outcnt() > 0) { |
36066 | 1710 |
Node *cur_phi = old_new[main_phi->_idx]; |
1711 |
Node *fallnew = clone_up_backedge_goo(main_head->back_control(), |
|
1712 |
post_head->init_control(), |
|
1713 |
main_phi->in(LoopNode::LoopBackControl), |
|
1714 |
visited, clones); |
|
1715 |
_igvn.hash_delete(cur_phi); |
|
1716 |
cur_phi->set_req(LoopNode::EntryControl, fallnew); |
|
1717 |
} |
|
1718 |
} |
|
1719 |
||
1720 |
// CastII for the new post loop: |
|
49487
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
1721 |
Node* castii = cast_incr_before_loop(zer_opaq->in(1), zer_taken, post_head); |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
1722 |
assert(castii != NULL, "no castII inserted"); |
36066 | 1723 |
|
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1724 |
return new_main_exit; |
36066 | 1725 |
} |
1726 |
||
1 | 1727 |
//------------------------------is_invariant----------------------------- |
1728 |
// Return true if n is invariant |
|
1729 |
bool IdealLoopTree::is_invariant(Node* n) const { |
|
4643 | 1730 |
Node *n_c = _phase->has_ctrl(n) ? _phase->get_ctrl(n) : n; |
1 | 1731 |
if (n_c->is_top()) return false; |
1732 |
return !is_member(_phase->get_loop(n_c)); |
|
1733 |
} |
|
1734 |
||
53306
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1735 |
void PhaseIdealLoop::update_skeleton_predicates(Node* ctrl, CountedLoopNode* loop_head, Node* init, int stride_con) { |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1736 |
// Search for skeleton predicates and update them according to the new stride |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1737 |
Node* entry = ctrl; |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1738 |
Node* prev_proj = ctrl; |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1739 |
LoopNode* outer_loop_head = loop_head->skip_strip_mined(); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1740 |
IdealLoopTree* outer_loop = get_loop(outer_loop_head); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1741 |
while (entry != NULL && entry->is_Proj() && entry->in(0)->is_If()) { |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1742 |
IfNode* iff = entry->in(0)->as_If(); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1743 |
ProjNode* proj = iff->proj_out(1 - entry->as_Proj()->_con); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1744 |
if (proj->unique_ctrl_out()->Opcode() != Op_Halt) { |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1745 |
break; |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1746 |
} |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1747 |
if (iff->in(1)->Opcode() == Op_Opaque4) { |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1748 |
// Look for predicate with an Opaque1 node that can be used as a template |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1749 |
if (!skeleton_predicate_has_opaque(iff)) { |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1750 |
// No Opaque1 node? It's either the check for the first value |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1751 |
// of the first iteration or the check for the last value of |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1752 |
// the first iteration of an unrolled loop. We can't |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1753 |
// tell. Kill it in any case. |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1754 |
_igvn.replace_input_of(iff, 1, iff->in(1)->in(2)); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1755 |
} else { |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1756 |
// Add back the predicate for the value at the beginning of the first entry |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1757 |
prev_proj = clone_skeleton_predicate(iff, init, entry, proj, ctrl, outer_loop, prev_proj); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1758 |
assert(!skeleton_predicate_has_opaque(prev_proj->in(0)->as_If()), "unexpected"); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1759 |
// Compute the value of the loop induction variable at the end of the |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1760 |
// first iteration of the unrolled loop: init + new_stride_con - init_inc |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1761 |
int init_inc = stride_con/loop_head->unrolled_count(); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1762 |
assert(init_inc != 0, "invalid loop increment"); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1763 |
int new_stride_con = stride_con * 2; |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1764 |
Node* max_value = _igvn.intcon(new_stride_con - init_inc); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1765 |
max_value = new AddINode(init, max_value); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1766 |
register_new_node(max_value, get_ctrl(iff->in(1))); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1767 |
prev_proj = clone_skeleton_predicate(iff, max_value, entry, proj, ctrl, outer_loop, prev_proj); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1768 |
assert(!skeleton_predicate_has_opaque(prev_proj->in(0)->as_If()), "unexpected"); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1769 |
} |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1770 |
} |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1771 |
entry = entry->in(0)->in(0); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1772 |
} |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1773 |
if (prev_proj != ctrl) { |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1774 |
_igvn.replace_input_of(outer_loop_head, LoopNode::EntryControl, prev_proj); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1775 |
set_idom(outer_loop_head, prev_proj, dom_depth(outer_loop_head)); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1776 |
} |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1777 |
} |
1 | 1778 |
|
1779 |
//------------------------------do_unroll-------------------------------------- |
|
1780 |
// Unroll the loop body one step - make each trip do 2 iterations. |
|
54703 | 1781 |
void PhaseIdealLoop::do_unroll(IdealLoopTree *loop, Node_List &old_new, bool adjust_min_trip) { |
8732
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
1782 |
assert(LoopUnrollLimit, ""); |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
1783 |
CountedLoopNode *loop_head = loop->_head->as_CountedLoop(); |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
1784 |
CountedLoopEndNode *loop_end = loop_head->loopexit(); |
1 | 1785 |
#ifndef PRODUCT |
8732
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
1786 |
if (PrintOpto && VerifyLoopOptimizations) { |
1 | 1787 |
tty->print("Unrolling "); |
1788 |
loop->dump_head(); |
|
8732
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
1789 |
} else if (TraceLoopOpts) { |
9121 | 1790 |
if (loop_head->trip_count() < (uint)LoopUnrollLimit) { |
9446 | 1791 |
tty->print("Unroll %d(%2d) ", loop_head->unrolled_count()*2, loop_head->trip_count()); |
9109
ec7b2f3b386c
7004547: regular loop unroll should not unroll more than max unrolling
kvn
parents:
9104
diff
changeset
|
1792 |
} else { |
9446 | 1793 |
tty->print("Unroll %d ", loop_head->unrolled_count()*2); |
9109
ec7b2f3b386c
7004547: regular loop unroll should not unroll more than max unrolling
kvn
parents:
9104
diff
changeset
|
1794 |
} |
8732
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
1795 |
loop->dump_head(); |
1 | 1796 |
} |
30593 | 1797 |
|
46630
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
44314
diff
changeset
|
1798 |
if (C->do_vector_loop() && (PrintOpto && (VerifyLoopOptimizations || TraceLoopOpts))) { |
30593 | 1799 |
Arena* arena = Thread::current()->resource_area(); |
32202
7e7ad8b06f5b
8011858: Use Compile::live_nodes() instead of Compile::unique() in appropriate places
kvn
parents:
31772
diff
changeset
|
1800 |
Node_Stack stack(arena, C->live_nodes() >> 2); |
30593 | 1801 |
Node_List rpo_list; |
1802 |
VectorSet visited(arena); |
|
1803 |
visited.set(loop_head->_idx); |
|
54703 | 1804 |
rpo(loop_head, stack, visited, rpo_list); |
1805 |
dump(loop, rpo_list.size(), rpo_list); |
|
30593 | 1806 |
} |
1 | 1807 |
#endif |
1808 |
||
1809 |
// Remember loop node count before unrolling to detect |
|
1810 |
// if rounds of unroll,optimize are making progress |
|
1811 |
loop_head->set_node_count_before_unroll(loop->_body.size()); |
|
1812 |
||
48145 | 1813 |
Node *ctrl = loop_head->skip_strip_mined()->in(LoopNode::EntryControl); |
1 | 1814 |
Node *limit = loop_head->limit(); |
1815 |
Node *init = loop_head->init_trip(); |
|
8732
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
1816 |
Node *stride = loop_head->stride(); |
1 | 1817 |
|
1818 |
Node *opaq = NULL; |
|
9446 | 1819 |
if (adjust_min_trip) { // If not maximally unrolling, need adjustment |
1820 |
// Search for zero-trip guard. |
|
36809
6f9362b27d4f
8148754: C2 loop unrolling fails due to unexpected graph shape
zmajo
parents:
36316
diff
changeset
|
1821 |
|
6f9362b27d4f
8148754: C2 loop unrolling fails due to unexpected graph shape
zmajo
parents:
36316
diff
changeset
|
1822 |
// Check the shape of the graph at the loop entry. If an inappropriate |
6f9362b27d4f
8148754: C2 loop unrolling fails due to unexpected graph shape
zmajo
parents:
36316
diff
changeset
|
1823 |
// graph shape is encountered, the compiler bails out loop unrolling; |
6f9362b27d4f
8148754: C2 loop unrolling fails due to unexpected graph shape
zmajo
parents:
36316
diff
changeset
|
1824 |
// compilation of the method will still succeed. |
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
1825 |
if (!is_canonical_loop_entry(loop_head)) { |
36809
6f9362b27d4f
8148754: C2 loop unrolling fails due to unexpected graph shape
zmajo
parents:
36316
diff
changeset
|
1826 |
return; |
6f9362b27d4f
8148754: C2 loop unrolling fails due to unexpected graph shape
zmajo
parents:
36316
diff
changeset
|
1827 |
} |
49487
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
1828 |
opaq = loop_head->skip_predicates()->in(0)->in(1)->in(1)->in(2); |
9446 | 1829 |
// Zero-trip test uses an 'opaque' node which is not shared. |
1830 |
assert(opaq->outcnt() == 1 && opaq->in(1) == limit, ""); |
|
1 | 1831 |
} |
1832 |
||
1833 |
C->set_major_progress(); |
|
1834 |
||
9446 | 1835 |
Node* new_limit = NULL; |
37287
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1836 |
int stride_con = stride->get_int(); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1837 |
int stride_p = (stride_con > 0) ? stride_con : -stride_con; |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1838 |
uint old_trip_count = loop_head->trip_count(); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1839 |
// Verify that unroll policy result is still valid. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1840 |
assert(old_trip_count > 1 && |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1841 |
(!adjust_min_trip || stride_p <= (1<<3)*loop_head->unrolled_count()), "sanity"); |
1 | 1842 |
|
53306
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
1843 |
update_skeleton_predicates(ctrl, loop_head, init, stride_con); |
50632
fd430e352427
8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents:
50623
diff
changeset
|
1844 |
|
37287
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1845 |
// Adjust loop limit to keep valid iterations number after unroll. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1846 |
// Use (limit - stride) instead of (((limit - init)/stride) & (-2))*stride |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1847 |
// which may overflow. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1848 |
if (!adjust_min_trip) { |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1849 |
assert(old_trip_count > 1 && (old_trip_count & 1) == 0, |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1850 |
"odd trip count for maximally unroll"); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1851 |
// Don't need to adjust limit for maximally unroll since trip count is even. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1852 |
} else if (loop_head->has_exact_trip_count() && init->is_Con()) { |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1853 |
// Loop's limit is constant. Loop's init could be constant when pre-loop |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1854 |
// become peeled iteration. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1855 |
jlong init_con = init->get_int(); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1856 |
// We can keep old loop limit if iterations count stays the same: |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1857 |
// old_trip_count == new_trip_count * 2 |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1858 |
// Note: since old_trip_count >= 2 then new_trip_count >= 1 |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1859 |
// so we also don't need to adjust zero trip test. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1860 |
jlong limit_con = limit->get_int(); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1861 |
// (stride_con*2) not overflow since stride_con <= 8. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1862 |
int new_stride_con = stride_con * 2; |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1863 |
int stride_m = new_stride_con - (stride_con > 0 ? 1 : -1); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1864 |
jlong trip_count = (limit_con - init_con + stride_m)/new_stride_con; |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1865 |
// New trip count should satisfy next conditions. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1866 |
assert(trip_count > 0 && (julong)trip_count < (julong)max_juint/2, "sanity"); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1867 |
uint new_trip_count = (uint)trip_count; |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1868 |
adjust_min_trip = (old_trip_count != new_trip_count*2); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1869 |
} |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1870 |
|
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1871 |
if (adjust_min_trip) { |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1872 |
// Step 2: Adjust the trip limit if it is called for. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1873 |
// The adjustment amount is -stride. Need to make sure if the |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1874 |
// adjustment underflows or overflows, then the main loop is skipped. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1875 |
Node* cmp = loop_end->cmp_node(); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1876 |
assert(cmp->in(2) == limit, "sanity"); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1877 |
assert(opaq != NULL && opaq->in(1) == limit, "sanity"); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1878 |
|
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1879 |
// Verify that policy_unroll result is still valid. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1880 |
const TypeInt* limit_type = _igvn.type(limit)->is_int(); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1881 |
assert(stride_con > 0 && ((limit_type->_hi - stride_con) < limit_type->_hi) || |
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
1882 |
stride_con < 0 && ((limit_type->_lo - stride_con) > limit_type->_lo), |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
1883 |
"sanity"); |
9446 | 1884 |
|
37287
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1885 |
if (limit->is_Con()) { |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1886 |
// The check in policy_unroll and the assert above guarantee |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1887 |
// no underflow if limit is constant. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1888 |
new_limit = _igvn.intcon(limit->get_int() - stride_con); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1889 |
set_ctrl(new_limit, C->root()); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1890 |
} else { |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1891 |
// Limit is not constant. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1892 |
if (loop_head->unrolled_count() == 1) { // only for first unroll |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1893 |
// Separate limit by Opaque node in case it is an incremented |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1894 |
// variable from previous loop to avoid using pre-incremented |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1895 |
// value which could increase register pressure. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1896 |
// Otherwise reorg_offsets() optimization will create a separate |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1897 |
// Opaque node for each use of trip-counter and as result |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1898 |
// zero trip guard limit will be different from loop limit. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1899 |
assert(has_ctrl(opaq), "should have it"); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1900 |
Node* opaq_ctrl = get_ctrl(opaq); |
54703 | 1901 |
limit = new Opaque2Node(C, limit); |
1902 |
register_new_node(limit, opaq_ctrl); |
|
37287
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1903 |
} |
46630
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
44314
diff
changeset
|
1904 |
if ((stride_con > 0 && (java_subtract(limit_type->_lo, stride_con) < limit_type->_lo)) || |
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
44314
diff
changeset
|
1905 |
(stride_con < 0 && (java_subtract(limit_type->_hi, stride_con) > limit_type->_hi))) { |
37287
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1906 |
// No underflow. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1907 |
new_limit = new SubINode(limit, stride); |
9446 | 1908 |
} else { |
37287
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1909 |
// (limit - stride) may underflow. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1910 |
// Clamp the adjustment value with MININT or MAXINT: |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1911 |
// |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1912 |
// new_limit = limit-stride |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1913 |
// if (stride > 0) |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1914 |
// new_limit = (limit < new_limit) ? MININT : new_limit; |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1915 |
// else |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1916 |
// new_limit = (limit > new_limit) ? MAXINT : new_limit; |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1917 |
// |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1918 |
BoolTest::mask bt = loop_end->test_trip(); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1919 |
assert(bt == BoolTest::lt || bt == BoolTest::gt, "canonical test is expected"); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1920 |
Node* adj_max = _igvn.intcon((stride_con > 0) ? min_jint : max_jint); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1921 |
set_ctrl(adj_max, C->root()); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1922 |
Node* old_limit = NULL; |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1923 |
Node* adj_limit = NULL; |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1924 |
Node* bol = limit->is_CMove() ? limit->in(CMoveNode::Condition) : NULL; |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1925 |
if (loop_head->unrolled_count() > 1 && |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1926 |
limit->is_CMove() && limit->Opcode() == Op_CMoveI && |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1927 |
limit->in(CMoveNode::IfTrue) == adj_max && |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1928 |
bol->as_Bool()->_test._test == bt && |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1929 |
bol->in(1)->Opcode() == Op_CmpI && |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1930 |
bol->in(1)->in(2) == limit->in(CMoveNode::IfFalse)) { |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1931 |
// Loop was unrolled before. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1932 |
// Optimize the limit to avoid nested CMove: |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1933 |
// use original limit as old limit. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1934 |
old_limit = bol->in(1)->in(1); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1935 |
// Adjust previous adjusted limit. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1936 |
adj_limit = limit->in(CMoveNode::IfFalse); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1937 |
adj_limit = new SubINode(adj_limit, stride); |
9446 | 1938 |
} else { |
37287
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1939 |
old_limit = limit; |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1940 |
adj_limit = new SubINode(limit, stride); |
9446 | 1941 |
} |
37287
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1942 |
assert(old_limit != NULL && adj_limit != NULL, ""); |
54703 | 1943 |
register_new_node(adj_limit, ctrl); // adjust amount |
37287
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1944 |
Node* adj_cmp = new CmpINode(old_limit, adj_limit); |
54703 | 1945 |
register_new_node(adj_cmp, ctrl); |
37287
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1946 |
Node* adj_bool = new BoolNode(adj_cmp, bt); |
54703 | 1947 |
register_new_node(adj_bool, ctrl); |
37287
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1948 |
new_limit = new CMoveINode(adj_bool, adj_limit, adj_max, TypeInt::INT); |
9446 | 1949 |
} |
37287
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1950 |
register_new_node(new_limit, ctrl); |
9446 | 1951 |
} |
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
1952 |
|
37287
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1953 |
assert(new_limit != NULL, ""); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1954 |
// Replace in loop test. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1955 |
assert(loop_end->in(1)->in(1) == cmp, "sanity"); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1956 |
if (cmp->outcnt() == 1 && loop_end->in(1)->outcnt() == 1) { |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1957 |
// Don't need to create new test since only one user. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1958 |
_igvn.hash_delete(cmp); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1959 |
cmp->set_req(2, new_limit); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1960 |
} else { |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1961 |
// Create new test since it is shared. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1962 |
Node* ctrl2 = loop_end->in(0); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1963 |
Node* cmp2 = cmp->clone(); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1964 |
cmp2->set_req(2, new_limit); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1965 |
register_new_node(cmp2, ctrl2); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1966 |
Node* bol2 = loop_end->in(1)->clone(); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1967 |
bol2->set_req(1, cmp2); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1968 |
register_new_node(bol2, ctrl2); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1969 |
_igvn.replace_input_of(loop_end, 1, bol2); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1970 |
} |
9446 | 1971 |
// Step 3: Find the min-trip test guaranteed before a 'main' loop. |
1972 |
// Make it a 1-trip test (means at least 2 trips). |
|
37287
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1973 |
|
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1974 |
// Guard test uses an 'opaque' node which is not shared. Hence I |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1975 |
// can edit it's inputs directly. Hammer in the new limit for the |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1976 |
// minimum-trip guard. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1977 |
assert(opaq->outcnt() == 1, ""); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1978 |
_igvn.replace_input_of(opaq, 1, new_limit); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1979 |
} |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1980 |
|
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1981 |
// Adjust max trip count. The trip count is intentionally rounded |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1982 |
// down here (e.g. 15-> 7-> 3-> 1) because if we unwittingly over-unroll, |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1983 |
// the main, unrolled, part of the loop will never execute as it is protected |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1984 |
// by the min-trip test. See bug 4834191 for a case where we over-unrolled |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1985 |
// and later determined that part of the unrolled loop was dead. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1986 |
loop_head->set_trip_count(old_trip_count / 2); |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1987 |
|
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1988 |
// Double the count of original iterations in the unrolled loop body. |
c2660335bf81
8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents:
36809
diff
changeset
|
1989 |
loop_head->double_unrolled_count(); |
1 | 1990 |
|
1991 |
// --------- |
|
1992 |
// Step 4: Clone the loop body. Move it inside the loop. This loop body |
|
1993 |
// represents the odd iterations; since the loop trips an even number of |
|
1994 |
// times its backedge is never taken. Kill the backedge. |
|
1995 |
uint dd = dom_depth(loop_head); |
|
48145 | 1996 |
clone_loop(loop, old_new, dd, IgnoreStripMined); |
1 | 1997 |
|
1998 |
// Make backedges of the clone equal to backedges of the original. |
|
1999 |
// Make the fall-in from the original come from the fall-out of the clone. |
|
2000 |
for (DUIterator_Fast jmax, j = loop_head->fast_outs(jmax); j < jmax; j++) { |
|
2001 |
Node* phi = loop_head->fast_out(j); |
|
54703 | 2002 |
if (phi->is_Phi() && phi->in(0) == loop_head && phi->outcnt() > 0) { |
1 | 2003 |
Node *newphi = old_new[phi->_idx]; |
54703 | 2004 |
_igvn.hash_delete(phi); |
2005 |
_igvn.hash_delete(newphi); |
|
1 | 2006 |
|
2007 |
phi ->set_req(LoopNode:: EntryControl, newphi->in(LoopNode::LoopBackControl)); |
|
2008 |
newphi->set_req(LoopNode::LoopBackControl, phi ->in(LoopNode::LoopBackControl)); |
|
2009 |
phi ->set_req(LoopNode::LoopBackControl, C->top()); |
|
2010 |
} |
|
2011 |
} |
|
2012 |
Node *clone_head = old_new[loop_head->_idx]; |
|
54703 | 2013 |
_igvn.hash_delete(clone_head); |
1 | 2014 |
loop_head ->set_req(LoopNode:: EntryControl, clone_head->in(LoopNode::LoopBackControl)); |
2015 |
clone_head->set_req(LoopNode::LoopBackControl, loop_head ->in(LoopNode::LoopBackControl)); |
|
2016 |
loop_head ->set_req(LoopNode::LoopBackControl, C->top()); |
|
2017 |
loop->_head = clone_head; // New loop header |
|
2018 |
||
2019 |
set_idom(loop_head, loop_head ->in(LoopNode::EntryControl), dd); |
|
2020 |
set_idom(clone_head, clone_head->in(LoopNode::EntryControl), dd); |
|
2021 |
||
2022 |
// Kill the clone's backedge |
|
2023 |
Node *newcle = old_new[loop_end->_idx]; |
|
54703 | 2024 |
_igvn.hash_delete(newcle); |
1 | 2025 |
Node *one = _igvn.intcon(1); |
2026 |
set_ctrl(one, C->root()); |
|
2027 |
newcle->set_req(1, one); |
|
2028 |
// Force clone into same loop body |
|
2029 |
uint max = loop->_body.size(); |
|
54703 | 2030 |
for (uint k = 0; k < max; k++) { |
1 | 2031 |
Node *old = loop->_body.at(k); |
2032 |
Node *nnn = old_new[old->_idx]; |
|
2033 |
loop->_body.push(nnn); |
|
54703 | 2034 |
if (!has_ctrl(old)) { |
1 | 2035 |
set_loop(nnn, loop); |
54703 | 2036 |
} |
1 | 2037 |
} |
1399
9648dfd4ce09
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
781
diff
changeset
|
2038 |
|
9648dfd4ce09
6384206: Phis which are later unneeded are impairing our ability to inline based on static types
never
parents:
781
diff
changeset
|
2039 |
loop->record_for_igvn(); |
48145 | 2040 |
loop_head->clear_strip_mined(); |
30593 | 2041 |
|
2042 |
#ifndef PRODUCT |
|
46630
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
44314
diff
changeset
|
2043 |
if (C->do_vector_loop() && (PrintOpto && (VerifyLoopOptimizations || TraceLoopOpts))) { |
30593 | 2044 |
tty->print("\nnew loop after unroll\n"); loop->dump_head(); |
2045 |
for (uint i = 0; i < loop->_body.size(); i++) { |
|
2046 |
loop->_body.at(i)->dump(); |
|
2047 |
} |
|
54703 | 2048 |
if (C->clone_map().is_debug()) { |
30593 | 2049 |
tty->print("\nCloneMap\n"); |
2050 |
Dict* dict = C->clone_map().dict(); |
|
2051 |
DictI i(dict); |
|
2052 |
tty->print_cr("Dict@%p[%d] = ", dict, dict->Size()); |
|
2053 |
for (int ii = 0; i.test(); ++i, ++ii) { |
|
2054 |
NodeCloneInfo cl((uint64_t)dict->operator[]((void*)i._key)); |
|
2055 |
tty->print("%d->%d:%d,", (int)(intptr_t)i._key, cl.idx(), cl.gen()); |
|
2056 |
if (ii % 10 == 9) { |
|
2057 |
tty->print_cr(" "); |
|
2058 |
} |
|
2059 |
} |
|
2060 |
tty->print_cr(" "); |
|
2061 |
} |
|
2062 |
} |
|
2063 |
#endif |
|
1 | 2064 |
} |
2065 |
||
2066 |
//------------------------------do_maximally_unroll---------------------------- |
|
2067 |
||
54703 | 2068 |
void PhaseIdealLoop::do_maximally_unroll(IdealLoopTree *loop, Node_List &old_new) { |
1 | 2069 |
CountedLoopNode *cl = loop->_head->as_CountedLoop(); |
9446 | 2070 |
assert(cl->has_exact_trip_count(), "trip count is not exact"); |
8732
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
2071 |
assert(cl->trip_count() > 0, ""); |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
2072 |
#ifndef PRODUCT |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
2073 |
if (TraceLoopOpts) { |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
2074 |
tty->print("MaxUnroll %d ", cl->trip_count()); |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
2075 |
loop->dump_head(); |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
2076 |
} |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
2077 |
#endif |
1 | 2078 |
|
2079 |
// If loop is tripping an odd number of times, peel odd iteration |
|
8732
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
2080 |
if ((cl->trip_count() & 1) == 1) { |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
2081 |
do_peeling(loop, old_new); |
1 | 2082 |
} |
2083 |
||
2084 |
// Now its tripping an even number of times remaining. Double loop body. |
|
2085 |
// Do not adjust pre-guards; they are not needed and do not exist. |
|
8732
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
2086 |
if (cl->trip_count() > 0) { |
9446 | 2087 |
assert((cl->trip_count() & 1) == 0, "missed peeling"); |
8732
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
2088 |
do_unroll(loop, old_new, false); |
1 | 2089 |
} |
2090 |
} |
|
2091 |
||
30211 | 2092 |
void PhaseIdealLoop::mark_reductions(IdealLoopTree *loop) { |
2093 |
if (SuperWordReductions == false) return; |
|
2094 |
||
2095 |
CountedLoopNode* loop_head = loop->_head->as_CountedLoop(); |
|
2096 |
if (loop_head->unrolled_count() > 1) { |
|
2097 |
return; |
|
2098 |
} |
|
2099 |
||
2100 |
Node* trip_phi = loop_head->phi(); |
|
2101 |
for (DUIterator_Fast imax, i = loop_head->fast_outs(imax); i < imax; i++) { |
|
2102 |
Node* phi = loop_head->fast_out(i); |
|
2103 |
if (phi->is_Phi() && phi->outcnt() > 0 && phi != trip_phi) { |
|
2104 |
// For definitions which are loop inclusive and not tripcounts. |
|
2105 |
Node* def_node = phi->in(LoopNode::LoopBackControl); |
|
2106 |
||
2107 |
if (def_node != NULL) { |
|
2108 |
Node* n_ctrl = get_ctrl(def_node); |
|
2109 |
if (n_ctrl != NULL && loop->is_member(get_loop(n_ctrl))) { |
|
2110 |
// Now test it to see if it fits the standard pattern for a reduction operator. |
|
2111 |
int opc = def_node->Opcode(); |
|
54022
ff399127078a
8217561: X86: Add floating-point Math.min/max intrinsics
bsrbnd
parents:
53306
diff
changeset
|
2112 |
if (opc != ReductionNode::opcode(opc, def_node->bottom_type()->basic_type()) |
ff399127078a
8217561: X86: Add floating-point Math.min/max intrinsics
bsrbnd
parents:
53306
diff
changeset
|
2113 |
|| opc == Op_MinD || opc == Op_MinF || opc == Op_MaxD || opc == Op_MaxF) { |
30211 | 2114 |
if (!def_node->is_reduction()) { // Not marked yet |
2115 |
// To be a reduction, the arithmetic node must have the phi as input and provide a def to it |
|
31048
ad1dfe0256a7
8080976: Unexpected AIOOB thrown from 1.9.0-ea-b64 on (regression)
roland
parents:
30593
diff
changeset
|
2116 |
bool ok = false; |
30211 | 2117 |
for (unsigned j = 1; j < def_node->req(); j++) { |
2118 |
Node* in = def_node->in(j); |
|
2119 |
if (in == phi) { |
|
31048
ad1dfe0256a7
8080976: Unexpected AIOOB thrown from 1.9.0-ea-b64 on (regression)
roland
parents:
30593
diff
changeset
|
2120 |
ok = true; |
30211 | 2121 |
break; |
2122 |
} |
|
2123 |
} |
|
31048
ad1dfe0256a7
8080976: Unexpected AIOOB thrown from 1.9.0-ea-b64 on (regression)
roland
parents:
30593
diff
changeset
|
2124 |
|
ad1dfe0256a7
8080976: Unexpected AIOOB thrown from 1.9.0-ea-b64 on (regression)
roland
parents:
30593
diff
changeset
|
2125 |
// do nothing if we did not match the initial criteria |
ad1dfe0256a7
8080976: Unexpected AIOOB thrown from 1.9.0-ea-b64 on (regression)
roland
parents:
30593
diff
changeset
|
2126 |
if (ok == false) { |
ad1dfe0256a7
8080976: Unexpected AIOOB thrown from 1.9.0-ea-b64 on (regression)
roland
parents:
30593
diff
changeset
|
2127 |
continue; |
ad1dfe0256a7
8080976: Unexpected AIOOB thrown from 1.9.0-ea-b64 on (regression)
roland
parents:
30593
diff
changeset
|
2128 |
} |
ad1dfe0256a7
8080976: Unexpected AIOOB thrown from 1.9.0-ea-b64 on (regression)
roland
parents:
30593
diff
changeset
|
2129 |
|
ad1dfe0256a7
8080976: Unexpected AIOOB thrown from 1.9.0-ea-b64 on (regression)
roland
parents:
30593
diff
changeset
|
2130 |
// The result of the reduction must not be used in the loop |
ad1dfe0256a7
8080976: Unexpected AIOOB thrown from 1.9.0-ea-b64 on (regression)
roland
parents:
30593
diff
changeset
|
2131 |
for (DUIterator_Fast imax, i = def_node->fast_outs(imax); i < imax && ok; i++) { |
ad1dfe0256a7
8080976: Unexpected AIOOB thrown from 1.9.0-ea-b64 on (regression)
roland
parents:
30593
diff
changeset
|
2132 |
Node* u = def_node->fast_out(i); |
42622 | 2133 |
if (!loop->is_member(get_loop(ctrl_or_self(u)))) { |
31048
ad1dfe0256a7
8080976: Unexpected AIOOB thrown from 1.9.0-ea-b64 on (regression)
roland
parents:
30593
diff
changeset
|
2134 |
continue; |
ad1dfe0256a7
8080976: Unexpected AIOOB thrown from 1.9.0-ea-b64 on (regression)
roland
parents:
30593
diff
changeset
|
2135 |
} |
ad1dfe0256a7
8080976: Unexpected AIOOB thrown from 1.9.0-ea-b64 on (regression)
roland
parents:
30593
diff
changeset
|
2136 |
if (u == phi) { |
ad1dfe0256a7
8080976: Unexpected AIOOB thrown from 1.9.0-ea-b64 on (regression)
roland
parents:
30593
diff
changeset
|
2137 |
continue; |
ad1dfe0256a7
8080976: Unexpected AIOOB thrown from 1.9.0-ea-b64 on (regression)
roland
parents:
30593
diff
changeset
|
2138 |
} |
ad1dfe0256a7
8080976: Unexpected AIOOB thrown from 1.9.0-ea-b64 on (regression)
roland
parents:
30593
diff
changeset
|
2139 |
ok = false; |
ad1dfe0256a7
8080976: Unexpected AIOOB thrown from 1.9.0-ea-b64 on (regression)
roland
parents:
30593
diff
changeset
|
2140 |
} |
ad1dfe0256a7
8080976: Unexpected AIOOB thrown from 1.9.0-ea-b64 on (regression)
roland
parents:
30593
diff
changeset
|
2141 |
|
ad1dfe0256a7
8080976: Unexpected AIOOB thrown from 1.9.0-ea-b64 on (regression)
roland
parents:
30593
diff
changeset
|
2142 |
// iff the uses conform |
ad1dfe0256a7
8080976: Unexpected AIOOB thrown from 1.9.0-ea-b64 on (regression)
roland
parents:
30593
diff
changeset
|
2143 |
if (ok) { |
ad1dfe0256a7
8080976: Unexpected AIOOB thrown from 1.9.0-ea-b64 on (regression)
roland
parents:
30593
diff
changeset
|
2144 |
def_node->add_flag(Node::Flag_is_reduction); |
31403 | 2145 |
loop_head->mark_has_reductions(); |
31048
ad1dfe0256a7
8080976: Unexpected AIOOB thrown from 1.9.0-ea-b64 on (regression)
roland
parents:
30593
diff
changeset
|
2146 |
} |
30211 | 2147 |
} |
2148 |
} |
|
2149 |
} |
|
2150 |
} |
|
2151 |
} |
|
2152 |
} |
|
2153 |
} |
|
2154 |
||
9941
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2155 |
//------------------------------adjust_limit----------------------------------- |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2156 |
// Helper function for add_constraint(). |
53169
98580226126d
8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
53167
diff
changeset
|
2157 |
Node* PhaseIdealLoop::adjust_limit(int stride_con, Node * scale, Node *offset, Node *rc_limit, Node *loop_limit, Node *pre_ctrl, bool round_up) { |
9941
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2158 |
// Compute "I :: (limit-offset)/scale" |
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
2159 |
Node *con = new SubINode(rc_limit, offset); |
9941
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2160 |
register_new_node(con, pre_ctrl); |
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
2161 |
Node *X = new DivINode(0, con, scale); |
9941
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2162 |
register_new_node(X, pre_ctrl); |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2163 |
|
53169
98580226126d
8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
53167
diff
changeset
|
2164 |
// When the absolute value of scale is greater than one, the integer |
98580226126d
8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
53167
diff
changeset
|
2165 |
// division may round limit down so add one to the limit. |
98580226126d
8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
53167
diff
changeset
|
2166 |
if (round_up) { |
98580226126d
8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
53167
diff
changeset
|
2167 |
X = new AddINode(X, _igvn.intcon(1)); |
98580226126d
8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
53167
diff
changeset
|
2168 |
register_new_node(X, pre_ctrl); |
98580226126d
8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
53167
diff
changeset
|
2169 |
} |
98580226126d
8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
53167
diff
changeset
|
2170 |
|
9941
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2171 |
// Adjust loop limit |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2172 |
loop_limit = (stride_con > 0) |
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
2173 |
? (Node*)(new MinINode(loop_limit, X)) |
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
2174 |
: (Node*)(new MaxINode(loop_limit, X)); |
9941
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2175 |
register_new_node(loop_limit, pre_ctrl); |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2176 |
return loop_limit; |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2177 |
} |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2178 |
|
1 | 2179 |
//------------------------------add_constraint--------------------------------- |
9446 | 2180 |
// Constrain the main loop iterations so the conditions: |
2181 |
// low_limit <= scale_con * I + offset < upper_limit |
|
1 | 2182 |
// always holds true. That is, either increase the number of iterations in |
2183 |
// the pre-loop or the post-loop until the condition holds true in the main |
|
2184 |
// loop. Stride, scale, offset and limit are all loop invariant. Further, |
|
2185 |
// stride and scale are constants (offset and limit often are). |
|
54703 | 2186 |
void PhaseIdealLoop::add_constraint(int stride_con, int scale_con, Node *offset, Node *low_limit, Node *upper_limit, Node *pre_ctrl, Node **pre_limit, Node **main_limit) { |
1 | 2187 |
// For positive stride, the pre-loop limit always uses a MAX function |
2188 |
// and the main loop a MIN function. For negative stride these are |
|
2189 |
// reversed. |
|
2190 |
||
2191 |
// Also for positive stride*scale the affine function is increasing, so the |
|
2192 |
// pre-loop must check for underflow and the post-loop for overflow. |
|
2193 |
// Negative stride*scale reverses this; pre-loop checks for overflow and |
|
2194 |
// post-loop for underflow. |
|
9941
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2195 |
|
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2196 |
Node *scale = _igvn.intcon(scale_con); |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2197 |
set_ctrl(scale, C->root()); |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2198 |
|
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2199 |
if ((stride_con^scale_con) >= 0) { // Use XOR to avoid overflow |
9446 | 2200 |
// The overflow limit: scale*I+offset < upper_limit |
2201 |
// For main-loop compute |
|
2202 |
// ( if (scale > 0) /* and stride > 0 */ |
|
2203 |
// I < (upper_limit-offset)/scale |
|
2204 |
// else /* scale < 0 and stride < 0 */ |
|
2205 |
// I > (upper_limit-offset)/scale |
|
2206 |
// ) |
|
2207 |
// |
|
9941
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2208 |
// (upper_limit-offset) may overflow or underflow. |
9446 | 2209 |
// But it is fine since main loop will either have |
2210 |
// less iterations or will be skipped in such case. |
|
53169
98580226126d
8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
53167
diff
changeset
|
2211 |
*main_limit = adjust_limit(stride_con, scale, offset, upper_limit, *main_limit, pre_ctrl, false); |
1 | 2212 |
|
9446 | 2213 |
// The underflow limit: low_limit <= scale*I+offset. |
2214 |
// For pre-loop compute |
|
2215 |
// NOT(scale*I+offset >= low_limit) |
|
2216 |
// scale*I+offset < low_limit |
|
2217 |
// ( if (scale > 0) /* and stride > 0 */ |
|
2218 |
// I < (low_limit-offset)/scale |
|
2219 |
// else /* scale < 0 and stride < 0 */ |
|
2220 |
// I > (low_limit-offset)/scale |
|
2221 |
// ) |
|
2222 |
||
2223 |
if (low_limit->get_int() == -max_jint) { |
|
2224 |
// We need this guard when scale*pre_limit+offset >= limit |
|
9941
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2225 |
// due to underflow. So we need execute pre-loop until |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2226 |
// scale*I+offset >= min_int. But (min_int-offset) will |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2227 |
// underflow when offset > 0 and X will be > original_limit |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2228 |
// when stride > 0. To avoid it we replace positive offset with 0. |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2229 |
// |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2230 |
// Also (min_int+1 == -max_int) is used instead of min_int here |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2231 |
// to avoid problem with scale == -1 (min_int/(-1) == min_int). |
9446 | 2232 |
Node* shift = _igvn.intcon(31); |
2233 |
set_ctrl(shift, C->root()); |
|
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
2234 |
Node* sign = new RShiftINode(offset, shift); |
9941
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2235 |
register_new_node(sign, pre_ctrl); |
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
2236 |
offset = new AndINode(offset, sign); |
9446 | 2237 |
register_new_node(offset, pre_ctrl); |
2238 |
} else { |
|
2239 |
assert(low_limit->get_int() == 0, "wrong low limit for range check"); |
|
2240 |
// The only problem we have here when offset == min_int |
|
9941
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2241 |
// since (0-min_int) == min_int. It may be fine for stride > 0 |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2242 |
// but for stride < 0 X will be < original_limit. To avoid it |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2243 |
// max(pre_limit, original_limit) is used in do_range_check(). |
9446 | 2244 |
} |
9941
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2245 |
// Pass (-stride) to indicate pre_loop_cond = NOT(main_loop_cond); |
53169
98580226126d
8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
53167
diff
changeset
|
2246 |
*pre_limit = adjust_limit((-stride_con), scale, offset, low_limit, *pre_limit, pre_ctrl, |
98580226126d
8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
53167
diff
changeset
|
2247 |
scale_con > 1 && stride_con > 0); |
9446 | 2248 |
|
2249 |
} else { // stride_con*scale_con < 0 |
|
2250 |
// For negative stride*scale pre-loop checks for overflow and |
|
2251 |
// post-loop for underflow. |
|
2252 |
// |
|
2253 |
// The overflow limit: scale*I+offset < upper_limit |
|
2254 |
// For pre-loop compute |
|
2255 |
// NOT(scale*I+offset < upper_limit) |
|
2256 |
// scale*I+offset >= upper_limit |
|
2257 |
// scale*I+offset+1 > upper_limit |
|
2258 |
// ( if (scale < 0) /* and stride > 0 */ |
|
2259 |
// I < (upper_limit-(offset+1))/scale |
|
9941
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2260 |
// else /* scale > 0 and stride < 0 */ |
9446 | 2261 |
// I > (upper_limit-(offset+1))/scale |
2262 |
// ) |
|
9941
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2263 |
// |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2264 |
// (upper_limit-offset-1) may underflow or overflow. |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2265 |
// To avoid it min(pre_limit, original_limit) is used |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2266 |
// in do_range_check() for stride > 0 and max() for < 0. |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2267 |
Node *one = _igvn.intcon(1); |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2268 |
set_ctrl(one, C->root()); |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2269 |
|
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
2270 |
Node *plus_one = new AddINode(offset, one); |
54703 | 2271 |
register_new_node(plus_one, pre_ctrl); |
9941
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2272 |
// Pass (-stride) to indicate pre_loop_cond = NOT(main_loop_cond); |
53169
98580226126d
8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
53167
diff
changeset
|
2273 |
*pre_limit = adjust_limit((-stride_con), scale, plus_one, upper_limit, *pre_limit, pre_ctrl, |
98580226126d
8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
53167
diff
changeset
|
2274 |
scale_con < -1 && stride_con > 0); |
9446 | 2275 |
|
9941
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2276 |
if (low_limit->get_int() == -max_jint) { |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2277 |
// We need this guard when scale*main_limit+offset >= limit |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2278 |
// due to underflow. So we need execute main-loop while |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2279 |
// scale*I+offset+1 > min_int. But (min_int-offset-1) will |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2280 |
// underflow when (offset+1) > 0 and X will be < main_limit |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2281 |
// when scale < 0 (and stride > 0). To avoid it we replace |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2282 |
// positive (offset+1) with 0. |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2283 |
// |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2284 |
// Also (min_int+1 == -max_int) is used instead of min_int here |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2285 |
// to avoid problem with scale == -1 (min_int/(-1) == min_int). |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2286 |
Node* shift = _igvn.intcon(31); |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2287 |
set_ctrl(shift, C->root()); |
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
2288 |
Node* sign = new RShiftINode(plus_one, shift); |
9941
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2289 |
register_new_node(sign, pre_ctrl); |
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
2290 |
plus_one = new AndINode(plus_one, sign); |
9941
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2291 |
register_new_node(plus_one, pre_ctrl); |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2292 |
} else { |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2293 |
assert(low_limit->get_int() == 0, "wrong low limit for range check"); |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2294 |
// The only problem we have here when offset == max_int |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2295 |
// since (max_int+1) == min_int and (0-min_int) == min_int. |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2296 |
// But it is fine since main loop will either have |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2297 |
// less iterations or will be skipped in such case. |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2298 |
} |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2299 |
// The underflow limit: low_limit <= scale*I+offset. |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2300 |
// For main-loop compute |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2301 |
// scale*I+offset+1 > low_limit |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2302 |
// ( if (scale < 0) /* and stride > 0 */ |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2303 |
// I < (low_limit-(offset+1))/scale |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2304 |
// else /* scale > 0 and stride < 0 */ |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2305 |
// I > (low_limit-(offset+1))/scale |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2306 |
// ) |
9446 | 2307 |
|
53169
98580226126d
8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
53167
diff
changeset
|
2308 |
*main_limit = adjust_limit(stride_con, scale, plus_one, low_limit, *main_limit, pre_ctrl, |
98580226126d
8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
53167
diff
changeset
|
2309 |
false); |
1 | 2310 |
} |
2311 |
} |
|
2312 |
||
2313 |
||
2314 |
//------------------------------is_scaled_iv--------------------------------- |
|
2315 |
// Return true if exp is a constant times an induction var |
|
2316 |
bool PhaseIdealLoop::is_scaled_iv(Node* exp, Node* iv, int* p_scale) { |
|
2317 |
if (exp == iv) { |
|
2318 |
if (p_scale != NULL) { |
|
2319 |
*p_scale = 1; |
|
2320 |
} |
|
2321 |
return true; |
|
2322 |
} |
|
2323 |
int opc = exp->Opcode(); |
|
2324 |
if (opc == Op_MulI) { |
|
2325 |
if (exp->in(1) == iv && exp->in(2)->is_Con()) { |
|
2326 |
if (p_scale != NULL) { |
|
2327 |
*p_scale = exp->in(2)->get_int(); |
|
2328 |
} |
|
2329 |
return true; |
|
2330 |
} |
|
2331 |
if (exp->in(2) == iv && exp->in(1)->is_Con()) { |
|
2332 |
if (p_scale != NULL) { |
|
2333 |
*p_scale = exp->in(1)->get_int(); |
|
2334 |
} |
|
2335 |
return true; |
|
2336 |
} |
|
2337 |
} else if (opc == Op_LShiftI) { |
|
2338 |
if (exp->in(1) == iv && exp->in(2)->is_Con()) { |
|
2339 |
if (p_scale != NULL) { |
|
2340 |
*p_scale = 1 << exp->in(2)->get_int(); |
|
2341 |
} |
|
2342 |
return true; |
|
2343 |
} |
|
2344 |
} |
|
2345 |
return false; |
|
2346 |
} |
|
2347 |
||
2348 |
//-----------------------------is_scaled_iv_plus_offset------------------------------ |
|
2349 |
// Return true if exp is a simple induction variable expression: k1*iv + (invar + k2) |
|
2350 |
bool PhaseIdealLoop::is_scaled_iv_plus_offset(Node* exp, Node* iv, int* p_scale, Node** p_offset, int depth) { |
|
2351 |
if (is_scaled_iv(exp, iv, p_scale)) { |
|
2352 |
if (p_offset != NULL) { |
|
2353 |
Node *zero = _igvn.intcon(0); |
|
2354 |
set_ctrl(zero, C->root()); |
|
2355 |
*p_offset = zero; |
|
2356 |
} |
|
2357 |
return true; |
|
2358 |
} |
|
2359 |
int opc = exp->Opcode(); |
|
2360 |
if (opc == Op_AddI) { |
|
2361 |
if (is_scaled_iv(exp->in(1), iv, p_scale)) { |
|
2362 |
if (p_offset != NULL) { |
|
2363 |
*p_offset = exp->in(2); |
|
2364 |
} |
|
2365 |
return true; |
|
2366 |
} |
|
35139
071b000357fc
8145754: PhaseIdealLoop::is_scaled_iv_plus_offset() does not match AddI
thartmann
parents:
34174
diff
changeset
|
2367 |
if (is_scaled_iv(exp->in(2), iv, p_scale)) { |
071b000357fc
8145754: PhaseIdealLoop::is_scaled_iv_plus_offset() does not match AddI
thartmann
parents:
34174
diff
changeset
|
2368 |
if (p_offset != NULL) { |
071b000357fc
8145754: PhaseIdealLoop::is_scaled_iv_plus_offset() does not match AddI
thartmann
parents:
34174
diff
changeset
|
2369 |
*p_offset = exp->in(1); |
071b000357fc
8145754: PhaseIdealLoop::is_scaled_iv_plus_offset() does not match AddI
thartmann
parents:
34174
diff
changeset
|
2370 |
} |
071b000357fc
8145754: PhaseIdealLoop::is_scaled_iv_plus_offset() does not match AddI
thartmann
parents:
34174
diff
changeset
|
2371 |
return true; |
071b000357fc
8145754: PhaseIdealLoop::is_scaled_iv_plus_offset() does not match AddI
thartmann
parents:
34174
diff
changeset
|
2372 |
} |
1 | 2373 |
if (exp->in(2)->is_Con()) { |
2374 |
Node* offset2 = NULL; |
|
2375 |
if (depth < 2 && |
|
2376 |
is_scaled_iv_plus_offset(exp->in(1), iv, p_scale, |
|
2377 |
p_offset != NULL ? &offset2 : NULL, depth+1)) { |
|
2378 |
if (p_offset != NULL) { |
|
2379 |
Node *ctrl_off2 = get_ctrl(offset2); |
|
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
2380 |
Node* offset = new AddINode(offset2, exp->in(2)); |
1 | 2381 |
register_new_node(offset, ctrl_off2); |
2382 |
*p_offset = offset; |
|
2383 |
} |
|
2384 |
return true; |
|
2385 |
} |
|
2386 |
} |
|
2387 |
} else if (opc == Op_SubI) { |
|
2388 |
if (is_scaled_iv(exp->in(1), iv, p_scale)) { |
|
2389 |
if (p_offset != NULL) { |
|
2390 |
Node *zero = _igvn.intcon(0); |
|
2391 |
set_ctrl(zero, C->root()); |
|
2392 |
Node *ctrl_off = get_ctrl(exp->in(2)); |
|
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
2393 |
Node* offset = new SubINode(zero, exp->in(2)); |
1 | 2394 |
register_new_node(offset, ctrl_off); |
2395 |
*p_offset = offset; |
|
2396 |
} |
|
2397 |
return true; |
|
2398 |
} |
|
2399 |
if (is_scaled_iv(exp->in(2), iv, p_scale)) { |
|
2400 |
if (p_offset != NULL) { |
|
2401 |
*p_scale *= -1; |
|
2402 |
*p_offset = exp->in(1); |
|
2403 |
} |
|
2404 |
return true; |
|
2405 |
} |
|
2406 |
} |
|
2407 |
return false; |
|
2408 |
} |
|
2409 |
||
49487
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2410 |
// Same as PhaseIdealLoop::duplicate_predicates() but for range checks |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2411 |
// eliminated by iteration splitting. |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2412 |
Node* PhaseIdealLoop::add_range_check_predicate(IdealLoopTree* loop, CountedLoopNode* cl, |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2413 |
Node* predicate_proj, int scale_con, Node* offset, |
53306
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
2414 |
Node* limit, jint stride_con, Node* value) { |
49487
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2415 |
bool overflow = false; |
53306
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
2416 |
BoolNode* bol = rc_predicate(loop, predicate_proj, scale_con, offset, value, NULL, stride_con, limit, (stride_con > 0) != (scale_con > 0), overflow); |
49487
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2417 |
Node* opaque_bol = new Opaque4Node(C, bol, _igvn.intcon(1)); |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2418 |
register_new_node(opaque_bol, predicate_proj); |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2419 |
IfNode* new_iff = NULL; |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2420 |
if (overflow) { |
53063
b04860fd2e2c
8211698: Crash in C2 compiled code during execution of double array heavy processing code
rraghavan
parents:
52925
diff
changeset
|
2421 |
new_iff = new IfNode(predicate_proj, opaque_bol, PROB_MAX, COUNT_UNKNOWN); |
49487
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2422 |
} else { |
53063
b04860fd2e2c
8211698: Crash in C2 compiled code during execution of double array heavy processing code
rraghavan
parents:
52925
diff
changeset
|
2423 |
new_iff = new RangeCheckNode(predicate_proj, opaque_bol, PROB_MAX, COUNT_UNKNOWN); |
49487
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2424 |
} |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2425 |
register_control(new_iff, loop->_parent, predicate_proj); |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2426 |
Node* iffalse = new IfFalseNode(new_iff); |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2427 |
register_control(iffalse, _ltree_root, new_iff); |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2428 |
ProjNode* iftrue = new IfTrueNode(new_iff); |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2429 |
register_control(iftrue, loop->_parent, new_iff); |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2430 |
Node *frame = new ParmNode(C->start(), TypeFunc::FramePtr); |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2431 |
register_new_node(frame, C->start()); |
58061
fafba5cf3546
8225653: Provide more information when hitting SIGILL from HaltNode
chagedorn
parents:
55150
diff
changeset
|
2432 |
Node* halt = new HaltNode(iffalse, frame, "range check predicate failed which is impossible"); |
49487
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2433 |
register_control(halt, _ltree_root, iffalse); |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2434 |
C->root()->add_req(halt); |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2435 |
return iftrue; |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2436 |
} |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2437 |
|
1 | 2438 |
//------------------------------do_range_check--------------------------------- |
2439 |
// Eliminate range-checks and other trip-counter vs loop-invariant tests. |
|
54703 | 2440 |
int PhaseIdealLoop::do_range_check(IdealLoopTree *loop, Node_List &old_new) { |
1 | 2441 |
#ifndef PRODUCT |
8732
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
2442 |
if (PrintOpto && VerifyLoopOptimizations) { |
1 | 2443 |
tty->print("Range Check Elimination "); |
2444 |
loop->dump_head(); |
|
8732
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
2445 |
} else if (TraceLoopOpts) { |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
2446 |
tty->print("RangeCheck "); |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
2447 |
loop->dump_head(); |
1 | 2448 |
} |
2449 |
#endif |
|
54703 | 2450 |
|
8732
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
2451 |
assert(RangeCheckElimination, ""); |
1 | 2452 |
CountedLoopNode *cl = loop->_head->as_CountedLoop(); |
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2453 |
// If we fail before trying to eliminate range checks, set multiversion state |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2454 |
int closed_range_checks = 1; |
8732
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
2455 |
|
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
2456 |
// protect against stride not being a constant |
54703 | 2457 |
if (!cl->stride_is_con()) { |
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2458 |
return closed_range_checks; |
54703 | 2459 |
} |
1 | 2460 |
// Find the trip counter; we are iteration splitting based on it |
2461 |
Node *trip_counter = cl->phi(); |
|
2462 |
// Find the main loop limit; we will trim it's iterations |
|
2463 |
// to not ever trip end tests |
|
2464 |
Node *main_limit = cl->limit(); |
|
8732
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
2465 |
|
36809
6f9362b27d4f
8148754: C2 loop unrolling fails due to unexpected graph shape
zmajo
parents:
36316
diff
changeset
|
2466 |
// Check graph shape. Cannot optimize a loop if zero-trip |
6f9362b27d4f
8148754: C2 loop unrolling fails due to unexpected graph shape
zmajo
parents:
36316
diff
changeset
|
2467 |
// Opaque1 node is optimized away and then another round |
6f9362b27d4f
8148754: C2 loop unrolling fails due to unexpected graph shape
zmajo
parents:
36316
diff
changeset
|
2468 |
// of loop opts attempted. |
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2469 |
if (!is_canonical_loop_entry(cl)) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2470 |
return closed_range_checks; |
36809
6f9362b27d4f
8148754: C2 loop unrolling fails due to unexpected graph shape
zmajo
parents:
36316
diff
changeset
|
2471 |
} |
6f9362b27d4f
8148754: C2 loop unrolling fails due to unexpected graph shape
zmajo
parents:
36316
diff
changeset
|
2472 |
|
8732
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
2473 |
// Need to find the main-loop zero-trip guard |
54703 | 2474 |
Node *ctrl = cl->skip_predicates(); |
8732
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
2475 |
Node *iffm = ctrl->in(0); |
36809
6f9362b27d4f
8148754: C2 loop unrolling fails due to unexpected graph shape
zmajo
parents:
36316
diff
changeset
|
2476 |
Node *opqzm = iffm->in(1)->in(1)->in(2); |
8732
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
2477 |
assert(opqzm->in(1) == main_limit, "do not understand situation"); |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
2478 |
|
31133
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
2479 |
// Find the pre-loop limit; we will expand its iterations to |
1 | 2480 |
// not ever trip low tests. |
2481 |
Node *p_f = iffm->in(0); |
|
31131
d92082b3ef93
8078866: compiler/eliminateAutobox/6934604/TestIntBoxing.java assert(p_f->Opcode() == Op_IfFalse) failed
roland
parents:
31048
diff
changeset
|
2482 |
// pre loop may have been optimized out |
d92082b3ef93
8078866: compiler/eliminateAutobox/6934604/TestIntBoxing.java assert(p_f->Opcode() == Op_IfFalse) failed
roland
parents:
31048
diff
changeset
|
2483 |
if (p_f->Opcode() != Op_IfFalse) { |
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2484 |
return closed_range_checks; |
31131
d92082b3ef93
8078866: compiler/eliminateAutobox/6934604/TestIntBoxing.java assert(p_f->Opcode() == Op_IfFalse) failed
roland
parents:
31048
diff
changeset
|
2485 |
} |
1 | 2486 |
CountedLoopEndNode *pre_end = p_f->in(0)->as_CountedLoopEnd(); |
8732
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
2487 |
assert(pre_end->loopnode()->is_pre_loop(), ""); |
1 | 2488 |
Node *pre_opaq1 = pre_end->limit(); |
2489 |
// Occasionally it's possible for a pre-loop Opaque1 node to be |
|
2490 |
// optimized away and then another round of loop opts attempted. |
|
2491 |
// We can not optimize this particular loop in that case. |
|
54703 | 2492 |
if (pre_opaq1->Opcode() != Op_Opaque1) { |
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2493 |
return closed_range_checks; |
54703 | 2494 |
} |
1 | 2495 |
Opaque1Node *pre_opaq = (Opaque1Node*)pre_opaq1; |
2496 |
Node *pre_limit = pre_opaq->in(1); |
|
2497 |
||
2498 |
// Where do we put new limit calculations |
|
2499 |
Node *pre_ctrl = pre_end->loopnode()->in(LoopNode::EntryControl); |
|
2500 |
||
2501 |
// Ensure the original loop limit is available from the |
|
2502 |
// pre-loop Opaque1 node. |
|
2503 |
Node *orig_limit = pre_opaq->original_loop_limit(); |
|
54703 | 2504 |
if (orig_limit == NULL || _igvn.type(orig_limit) == Type::TOP) { |
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2505 |
return closed_range_checks; |
54703 | 2506 |
} |
1 | 2507 |
// Must know if its a count-up or count-down loop |
2508 |
||
2509 |
int stride_con = cl->stride_con(); |
|
2510 |
Node *zero = _igvn.intcon(0); |
|
2511 |
Node *one = _igvn.intcon(1); |
|
9446 | 2512 |
// Use symmetrical int range [-max_jint,max_jint] |
2513 |
Node *mini = _igvn.intcon(-max_jint); |
|
1 | 2514 |
set_ctrl(zero, C->root()); |
2515 |
set_ctrl(one, C->root()); |
|
9446 | 2516 |
set_ctrl(mini, C->root()); |
1 | 2517 |
|
2518 |
// Range checks that do not dominate the loop backedge (ie. |
|
2519 |
// conditionally executed) can lengthen the pre loop limit beyond |
|
2520 |
// the original loop limit. To prevent this, the pre limit is |
|
2521 |
// (for stride > 0) MINed with the original loop limit (MAXed |
|
2522 |
// stride < 0) when some range_check (rc) is conditionally |
|
2523 |
// executed. |
|
2524 |
bool conditional_rc = false; |
|
2525 |
||
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2526 |
// Count number of range checks and reduce by load range limits, if zero, |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2527 |
// the loop is in canonical form to multiversion. |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2528 |
closed_range_checks = 0; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2529 |
|
49487
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2530 |
Node* predicate_proj = cl->skip_strip_mined()->in(LoopNode::EntryControl); |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2531 |
assert(predicate_proj->is_Proj() && predicate_proj->in(0)->is_If(), "if projection only"); |
54703 | 2532 |
|
40031
6cc034201dba
8159016: Over-unrolled loop is partially removed
thartmann
parents:
39429
diff
changeset
|
2533 |
// Check loop body for tests of trip-counter plus loop-invariant vs loop-variant. |
54703 | 2534 |
for (uint i = 0; i < loop->_body.size(); i++) { |
1 | 2535 |
Node *iff = loop->_body[i]; |
34164
a9e6034d7707
8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents:
33628
diff
changeset
|
2536 |
if (iff->Opcode() == Op_If || |
a9e6034d7707
8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents:
33628
diff
changeset
|
2537 |
iff->Opcode() == Op_RangeCheck) { // Test? |
1 | 2538 |
// Test is an IfNode, has 2 projections. If BOTH are in the loop |
2539 |
// we need loop unswitching instead of iteration splitting. |
|
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2540 |
closed_range_checks++; |
1 | 2541 |
Node *exit = loop->is_loop_exit(iff); |
54703 | 2542 |
if (!exit) continue; |
1 | 2543 |
int flip = (exit->Opcode() == Op_IfTrue) ? 1 : 0; |
2544 |
||
2545 |
// Get boolean condition to test |
|
2546 |
Node *i1 = iff->in(1); |
|
54703 | 2547 |
if (!i1->is_Bool()) continue; |
1 | 2548 |
BoolNode *bol = i1->as_Bool(); |
2549 |
BoolTest b_test = bol->_test; |
|
2550 |
// Flip sense of test if exit condition is flipped |
|
54703 | 2551 |
if (flip) { |
1 | 2552 |
b_test = b_test.negate(); |
54703 | 2553 |
} |
1 | 2554 |
// Get compare |
2555 |
Node *cmp = bol->in(1); |
|
2556 |
||
2557 |
// Look for trip_counter + offset vs limit |
|
2558 |
Node *rc_exp = cmp->in(1); |
|
2559 |
Node *limit = cmp->in(2); |
|
47765
b7c7428eaab9
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents:
47591
diff
changeset
|
2560 |
int scale_con= 1; // Assume trip counter not scaled |
1 | 2561 |
|
2562 |
Node *limit_c = get_ctrl(limit); |
|
54703 | 2563 |
if (loop->is_member(get_loop(limit_c))) { |
1 | 2564 |
// Compare might have operands swapped; commute them |
2565 |
b_test = b_test.commute(); |
|
2566 |
rc_exp = cmp->in(2); |
|
2567 |
limit = cmp->in(1); |
|
2568 |
limit_c = get_ctrl(limit); |
|
54703 | 2569 |
if (loop->is_member(get_loop(limit_c))) { |
1 | 2570 |
continue; // Both inputs are loop varying; cannot RCE |
54703 | 2571 |
} |
1 | 2572 |
} |
2573 |
// Here we know 'limit' is loop invariant |
|
2574 |
||
2575 |
// 'limit' maybe pinned below the zero trip test (probably from a |
|
2576 |
// previous round of rce), in which case, it can't be used in the |
|
2577 |
// zero trip test expression which must occur before the zero test's if. |
|
49487
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2578 |
if (is_dominator(ctrl, limit_c)) { |
1 | 2579 |
continue; // Don't rce this check but continue looking for other candidates. |
2580 |
} |
|
2581 |
||
2582 |
// Check for scaled induction variable plus an offset |
|
2583 |
Node *offset = NULL; |
|
2584 |
||
2585 |
if (!is_scaled_iv_plus_offset(rc_exp, trip_counter, &scale_con, &offset)) { |
|
2586 |
continue; |
|
2587 |
} |
|
2588 |
||
2589 |
Node *offset_c = get_ctrl(offset); |
|
54703 | 2590 |
if (loop->is_member(get_loop(offset_c))) { |
1 | 2591 |
continue; // Offset is not really loop invariant |
54703 | 2592 |
} |
1 | 2593 |
// Here we know 'offset' is loop invariant. |
2594 |
||
2595 |
// As above for the 'limit', the 'offset' maybe pinned below the |
|
2596 |
// zero trip test. |
|
49487
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2597 |
if (is_dominator(ctrl, offset_c)) { |
1 | 2598 |
continue; // Don't rce this check but continue looking for other candidates. |
2599 |
} |
|
9446 | 2600 |
#ifdef ASSERT |
2601 |
if (TraceRangeLimitCheck) { |
|
2602 |
tty->print_cr("RC bool node%s", flip ? " flipped:" : ":"); |
|
2603 |
bol->dump(2); |
|
2604 |
} |
|
2605 |
#endif |
|
1 | 2606 |
// At this point we have the expression as: |
2607 |
// scale_con * trip_counter + offset :: limit |
|
2608 |
// where scale_con, offset and limit are loop invariant. Trip_counter |
|
2609 |
// monotonically increases by stride_con, a constant. Both (or either) |
|
2610 |
// stride_con and scale_con can be negative which will flip about the |
|
2611 |
// sense of the test. |
|
2612 |
||
2613 |
// Adjust pre and main loop limits to guard the correct iteration set |
|
54703 | 2614 |
if (cmp->Opcode() == Op_CmpU) { // Unsigned compare is really 2 tests |
2615 |
if (b_test._test == BoolTest::lt) { // Range checks always use lt |
|
9446 | 2616 |
// The underflow and overflow limits: 0 <= scale*I+offset < limit |
54703 | 2617 |
add_constraint(stride_con, scale_con, offset, zero, limit, pre_ctrl, &pre_limit, &main_limit); |
39429 | 2618 |
// (0-offset)/scale could be outside of loop iterations range. |
2619 |
conditional_rc = true; |
|
53306
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
2620 |
Node* init = cl->init_trip(); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
2621 |
Node* opaque_init = new Opaque1Node(C, init); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
2622 |
register_new_node(opaque_init, predicate_proj); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
2623 |
// template predicate so it can be updated on next unrolling |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
2624 |
predicate_proj = add_range_check_predicate(loop, cl, predicate_proj, scale_con, offset, limit, stride_con, opaque_init); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
2625 |
assert(skeleton_predicate_has_opaque(predicate_proj->in(0)->as_If()), "unexpected"); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
2626 |
// predicate on first value of first iteration |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
2627 |
predicate_proj = add_range_check_predicate(loop, cl, predicate_proj, scale_con, offset, limit, stride_con, init); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
2628 |
assert(!skeleton_predicate_has_opaque(predicate_proj->in(0)->as_If()), "unexpected"); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
2629 |
int init_inc = stride_con/cl->unrolled_count(); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
2630 |
assert(init_inc != 0, "invalid loop increment"); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
2631 |
Node* max_value = _igvn.intcon(stride_con - init_inc); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
2632 |
max_value = new AddINode(init, max_value); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
2633 |
register_new_node(max_value, predicate_proj); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
2634 |
// predicate on last value of first iteration (in case unrolling has already happened) |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
2635 |
predicate_proj = add_range_check_predicate(loop, cl, predicate_proj, scale_con, offset, limit, stride_con, max_value); |
8e260023fc53
8216135: C2 assert(!had_error) failed: bad dominance
roland
parents:
53169
diff
changeset
|
2636 |
assert(!skeleton_predicate_has_opaque(predicate_proj->in(0)->as_If()), "unexpected"); |
1 | 2637 |
} else { |
34174
4db2fb26dc49
8140424: don't prefix developer and notproduct flag variables with CONST_ in product builds
twisti
parents:
34164
diff
changeset
|
2638 |
if (PrintOpto) { |
1 | 2639 |
tty->print_cr("missed RCE opportunity"); |
34174
4db2fb26dc49
8140424: don't prefix developer and notproduct flag variables with CONST_ in product builds
twisti
parents:
34164
diff
changeset
|
2640 |
} |
1 | 2641 |
continue; // In release mode, ignore it |
2642 |
} |
|
2643 |
} else { // Otherwise work on normal compares |
|
54703 | 2644 |
switch(b_test._test) { |
9446 | 2645 |
case BoolTest::gt: |
2646 |
// Fall into GE case |
|
2647 |
case BoolTest::ge: |
|
2648 |
// Convert (I*scale+offset) >= Limit to (I*(-scale)+(-offset)) <= -Limit |
|
1 | 2649 |
scale_con = -scale_con; |
54703 | 2650 |
offset = new SubINode(zero, offset); |
2651 |
register_new_node(offset, pre_ctrl); |
|
2652 |
limit = new SubINode(zero, limit); |
|
2653 |
register_new_node(limit, pre_ctrl); |
|
1 | 2654 |
// Fall into LE case |
9446 | 2655 |
case BoolTest::le: |
2656 |
if (b_test._test != BoolTest::gt) { |
|
2657 |
// Convert X <= Y to X < Y+1 |
|
54703 | 2658 |
limit = new AddINode(limit, one); |
2659 |
register_new_node(limit, pre_ctrl); |
|
9446 | 2660 |
} |
1 | 2661 |
// Fall into LT case |
2662 |
case BoolTest::lt: |
|
9446 | 2663 |
// The underflow and overflow limits: MIN_INT <= scale*I+offset < limit |
9941
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2664 |
// Note: (MIN_INT+1 == -MAX_INT) is used instead of MIN_INT here |
f2365fbd62f4
7044725: -XX:-UnrollLimitCheck -Xcomp : Exception: String index out of range: 29488
kvn
parents:
9634
diff
changeset
|
2665 |
// to avoid problem with scale == -1: MIN_INT/(-1) == MIN_INT. |
54703 | 2666 |
add_constraint(stride_con, scale_con, offset, mini, limit, pre_ctrl, &pre_limit, &main_limit); |
39429 | 2667 |
// ((MIN_INT+1)-offset)/scale could be outside of loop iterations range. |
2668 |
// Note: negative offset is replaced with 0 but (MIN_INT+1)/scale could |
|
2669 |
// still be outside of loop range. |
|
2670 |
conditional_rc = true; |
|
1 | 2671 |
break; |
2672 |
default: |
|
34174
4db2fb26dc49
8140424: don't prefix developer and notproduct flag variables with CONST_ in product builds
twisti
parents:
34164
diff
changeset
|
2673 |
if (PrintOpto) { |
1 | 2674 |
tty->print_cr("missed RCE opportunity"); |
34174
4db2fb26dc49
8140424: don't prefix developer and notproduct flag variables with CONST_ in product builds
twisti
parents:
34164
diff
changeset
|
2675 |
} |
1 | 2676 |
continue; // Unhandled case |
2677 |
} |
|
2678 |
} |
|
2679 |
||
2680 |
// Kill the eliminated test |
|
2681 |
C->set_major_progress(); |
|
54703 | 2682 |
Node *kill_con = _igvn.intcon(1-flip); |
1 | 2683 |
set_ctrl(kill_con, C->root()); |
12958
009b6c9586d8
7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents:
10538
diff
changeset
|
2684 |
_igvn.replace_input_of(iff, 1, kill_con); |
1 | 2685 |
// Find surviving projection |
2686 |
assert(iff->is_If(), ""); |
|
2687 |
ProjNode* dp = ((IfNode*)iff)->proj_out(1-flip); |
|
2688 |
// Find loads off the surviving projection; remove their control edge |
|
2689 |
for (DUIterator_Fast imax, i = dp->fast_outs(imax); i < imax; i++) { |
|
2690 |
Node* cd = dp->fast_out(i); // Control-dependent node |
|
21526
03b4acedb351
8017065: C2 allows safepoint checks to leak into G1 pre-barriers
iveresov
parents:
21208
diff
changeset
|
2691 |
if (cd->is_Load() && cd->depends_only_on_test()) { // Loads can now float around in the loop |
1 | 2692 |
// Allow the load to float around in the loop, or before it |
2693 |
// but NOT before the pre-loop. |
|
12958
009b6c9586d8
7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents:
10538
diff
changeset
|
2694 |
_igvn.replace_input_of(cd, 0, ctrl); // ctrl, not NULL |
1 | 2695 |
--i; |
2696 |
--imax; |
|
2697 |
} |
|
2698 |
} |
|
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2699 |
if (limit->Opcode() == Op_LoadRange) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2700 |
closed_range_checks--; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2701 |
} |
1 | 2702 |
} // End of is IF |
2703 |
} |
|
49487
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2704 |
if (predicate_proj != cl->skip_strip_mined()->in(LoopNode::EntryControl)) { |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2705 |
_igvn.replace_input_of(cl->skip_strip_mined(), LoopNode::EntryControl, predicate_proj); |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2706 |
set_idom(cl->skip_strip_mined(), predicate_proj, dom_depth(cl->skip_strip_mined())); |
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2707 |
} |
1 | 2708 |
|
2709 |
// Update loop limits |
|
2710 |
if (conditional_rc) { |
|
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
2711 |
pre_limit = (stride_con > 0) ? (Node*)new MinINode(pre_limit, orig_limit) |
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
2712 |
: (Node*)new MaxINode(pre_limit, orig_limit); |
1 | 2713 |
register_new_node(pre_limit, pre_ctrl); |
2714 |
} |
|
25913
81dbc151e91c
8040213: C2 does not put all modified nodes on IGVN worklist
thartmann
parents:
24923
diff
changeset
|
2715 |
_igvn.replace_input_of(pre_opaq, 1, pre_limit); |
1 | 2716 |
|
2717 |
// Note:: we are making the main loop limit no longer precise; |
|
2718 |
// need to round up based on stride. |
|
9446 | 2719 |
cl->set_nonexact_trip_count(); |
1 | 2720 |
Node *main_cle = cl->loopexit(); |
2721 |
Node *main_bol = main_cle->in(1); |
|
2722 |
// Hacking loop bounds; need private copies of exit test |
|
54703 | 2723 |
if (main_bol->outcnt() > 1) { // BoolNode shared? |
2724 |
main_bol = main_bol->clone(); // Clone a private BoolNode |
|
2725 |
register_new_node(main_bol, main_cle->in(0)); |
|
25927
29dc55d9e8a0
8053915: bigapps assert failure in C2: modified node is not on IGVN._worklist
thartmann
parents:
25913
diff
changeset
|
2726 |
_igvn.replace_input_of(main_cle, 1, main_bol); |
1 | 2727 |
} |
2728 |
Node *main_cmp = main_bol->in(1); |
|
54703 | 2729 |
if (main_cmp->outcnt() > 1) { // CmpNode shared? |
2730 |
main_cmp = main_cmp->clone(); // Clone a private CmpNode |
|
2731 |
register_new_node(main_cmp, main_cle->in(0)); |
|
28639
beee8cc25bbf
8068864: C2 failed: modified node is not on IGVN._worklist
kvn
parents:
27708
diff
changeset
|
2732 |
_igvn.replace_input_of(main_bol, 1, main_cmp); |
1 | 2733 |
} |
2734 |
// Hack the now-private loop bounds |
|
12958
009b6c9586d8
7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents:
10538
diff
changeset
|
2735 |
_igvn.replace_input_of(main_cmp, 2, main_limit); |
1 | 2736 |
// The OpaqueNode is unshared by design |
54703 | 2737 |
assert(opqzm->outcnt() == 1, "cannot hack shared node"); |
12958
009b6c9586d8
7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents:
10538
diff
changeset
|
2738 |
_igvn.replace_input_of(opqzm, 1, main_limit); |
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2739 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2740 |
return closed_range_checks; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2741 |
} |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2742 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2743 |
//------------------------------has_range_checks------------------------------- |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2744 |
// Check to see if RCE cleaned the current loop of range-checks. |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2745 |
void PhaseIdealLoop::has_range_checks(IdealLoopTree *loop) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2746 |
assert(RangeCheckElimination, ""); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2747 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2748 |
// skip if not a counted loop |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2749 |
if (!loop->is_counted()) return; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2750 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2751 |
CountedLoopNode *cl = loop->_head->as_CountedLoop(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2752 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2753 |
// skip this loop if it is already checked |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2754 |
if (cl->has_been_range_checked()) return; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2755 |
|
40031
6cc034201dba
8159016: Over-unrolled loop is partially removed
thartmann
parents:
39429
diff
changeset
|
2756 |
// Now check for existence of range checks |
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2757 |
for (uint i = 0; i < loop->_body.size(); i++) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2758 |
Node *iff = loop->_body[i]; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2759 |
int iff_opc = iff->Opcode(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2760 |
if (iff_opc == Op_If || iff_opc == Op_RangeCheck) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2761 |
cl->mark_has_range_checks(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2762 |
break; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2763 |
} |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2764 |
} |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2765 |
cl->set_has_been_range_checked(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2766 |
} |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2767 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2768 |
//-------------------------multi_version_post_loops---------------------------- |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2769 |
// Check the range checks that remain, if simple, use the bounds to guard |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2770 |
// which version to a post loop we execute, one with range checks or one without |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2771 |
bool PhaseIdealLoop::multi_version_post_loops(IdealLoopTree *rce_loop, IdealLoopTree *legacy_loop) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2772 |
bool multi_version_succeeded = false; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2773 |
assert(RangeCheckElimination, ""); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2774 |
CountedLoopNode *legacy_cl = legacy_loop->_head->as_CountedLoop(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2775 |
assert(legacy_cl->is_post_loop(), ""); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2776 |
|
40031
6cc034201dba
8159016: Over-unrolled loop is partially removed
thartmann
parents:
39429
diff
changeset
|
2777 |
// Check for existence of range checks using the unique instance to make a guard with |
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2778 |
Unique_Node_List worklist; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2779 |
for (uint i = 0; i < legacy_loop->_body.size(); i++) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2780 |
Node *iff = legacy_loop->_body[i]; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2781 |
int iff_opc = iff->Opcode(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2782 |
if (iff_opc == Op_If || iff_opc == Op_RangeCheck) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2783 |
worklist.push(iff); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2784 |
} |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2785 |
} |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2786 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2787 |
// Find RCE'd post loop so that we can stage its guard. |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2788 |
if (!is_canonical_loop_entry(legacy_cl)) return multi_version_succeeded; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2789 |
Node* ctrl = legacy_cl->in(LoopNode::EntryControl); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2790 |
Node* iffm = ctrl->in(0); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2791 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2792 |
// Now we test that both the post loops are connected |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2793 |
Node* post_loop_region = iffm->in(0); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2794 |
if (post_loop_region == NULL) return multi_version_succeeded; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2795 |
if (!post_loop_region->is_Region()) return multi_version_succeeded; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2796 |
Node* covering_region = post_loop_region->in(RegionNode::Control+1); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2797 |
if (covering_region == NULL) return multi_version_succeeded; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2798 |
if (!covering_region->is_Region()) return multi_version_succeeded; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2799 |
Node* p_f = covering_region->in(RegionNode::Control); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2800 |
if (p_f == NULL) return multi_version_succeeded; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2801 |
if (!p_f->is_IfFalse()) return multi_version_succeeded; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2802 |
if (!p_f->in(0)->is_CountedLoopEnd()) return multi_version_succeeded; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2803 |
CountedLoopEndNode* rce_loop_end = p_f->in(0)->as_CountedLoopEnd(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2804 |
if (rce_loop_end == NULL) return multi_version_succeeded; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2805 |
CountedLoopNode* rce_cl = rce_loop_end->loopnode(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2806 |
if (rce_cl == NULL || !rce_cl->is_post_loop()) return multi_version_succeeded; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2807 |
CountedLoopNode *known_rce_cl = rce_loop->_head->as_CountedLoop(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2808 |
if (rce_cl != known_rce_cl) return multi_version_succeeded; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2809 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2810 |
// Then we fetch the cover entry test |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2811 |
ctrl = rce_cl->in(LoopNode::EntryControl); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2812 |
if (!ctrl->is_IfTrue() && !ctrl->is_IfFalse()) return multi_version_succeeded; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2813 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2814 |
#ifndef PRODUCT |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2815 |
if (TraceLoopOpts) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2816 |
tty->print("PostMultiVersion\n"); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2817 |
rce_loop->dump_head(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2818 |
legacy_loop->dump_head(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2819 |
} |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2820 |
#endif |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2821 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2822 |
// Now fetch the limit we want to compare against |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2823 |
Node *limit = rce_cl->limit(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2824 |
bool first_time = true; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2825 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2826 |
// If we got this far, we identified the post loop which has been RCE'd and |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2827 |
// we have a work list. Now we will try to transform the if guard to cause |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2828 |
// the loop pair to be multi version executed with the determination left to runtime |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2829 |
// or the optimizer if full information is known about the given arrays at compile time. |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2830 |
Node *last_min = NULL; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2831 |
multi_version_succeeded = true; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2832 |
while (worklist.size()) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2833 |
Node* rc_iffm = worklist.pop(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2834 |
if (rc_iffm->is_If()) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2835 |
Node *rc_bolzm = rc_iffm->in(1); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2836 |
if (rc_bolzm->is_Bool()) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2837 |
Node *rc_cmpzm = rc_bolzm->in(1); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2838 |
if (rc_cmpzm->is_Cmp()) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2839 |
Node *rc_left = rc_cmpzm->in(2); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2840 |
if (rc_left->Opcode() != Op_LoadRange) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2841 |
multi_version_succeeded = false; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2842 |
break; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2843 |
} |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2844 |
if (first_time) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2845 |
last_min = rc_left; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2846 |
first_time = false; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2847 |
} else { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2848 |
Node *cur_min = new MinINode(last_min, rc_left); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2849 |
last_min = cur_min; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2850 |
_igvn.register_new_node_with_optimizer(last_min); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2851 |
} |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2852 |
} |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2853 |
} |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2854 |
} |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2855 |
} |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2856 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2857 |
// All we have to do is update the limit of the rce loop |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2858 |
// with the min of our expression and the current limit. |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2859 |
// We will use this expression to replace the current limit. |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2860 |
if (last_min && multi_version_succeeded) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2861 |
Node *cur_min = new MinINode(last_min, limit); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2862 |
_igvn.register_new_node_with_optimizer(cur_min); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2863 |
Node *cmp_node = rce_loop_end->cmp_node(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2864 |
_igvn.replace_input_of(cmp_node, 2, cur_min); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2865 |
set_ctrl(cur_min, ctrl); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2866 |
set_loop(cur_min, rce_loop->_parent); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2867 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2868 |
legacy_cl->mark_is_multiversioned(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2869 |
rce_cl->mark_is_multiversioned(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2870 |
multi_version_succeeded = true; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2871 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2872 |
C->set_major_progress(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2873 |
} |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2874 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2875 |
return multi_version_succeeded; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2876 |
} |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2877 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2878 |
//-------------------------poison_rce_post_loop-------------------------------- |
40031
6cc034201dba
8159016: Over-unrolled loop is partially removed
thartmann
parents:
39429
diff
changeset
|
2879 |
// Causes the rce'd post loop to be optimized away if multiversioning fails |
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2880 |
void PhaseIdealLoop::poison_rce_post_loop(IdealLoopTree *rce_loop) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2881 |
CountedLoopNode *rce_cl = rce_loop->_head->as_CountedLoop(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2882 |
Node* ctrl = rce_cl->in(LoopNode::EntryControl); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2883 |
if (ctrl->is_IfTrue() || ctrl->is_IfFalse()) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2884 |
Node* iffm = ctrl->in(0); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2885 |
if (iffm->is_If()) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2886 |
Node* cur_bool = iffm->in(1); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2887 |
if (cur_bool->is_Bool()) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2888 |
Node* cur_cmp = cur_bool->in(1); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2889 |
if (cur_cmp->is_Cmp()) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2890 |
BoolTest::mask new_test = BoolTest::gt; |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2891 |
BoolNode *new_bool = new BoolNode(cur_cmp, new_test); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2892 |
_igvn.replace_node(cur_bool, new_bool); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2893 |
_igvn._worklist.push(new_bool); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2894 |
Node* left_op = cur_cmp->in(1); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2895 |
_igvn.replace_input_of(cur_cmp, 2, left_op); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2896 |
C->set_major_progress(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2897 |
} |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2898 |
} |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2899 |
} |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
2900 |
} |
1 | 2901 |
} |
2902 |
||
2903 |
//------------------------------DCE_loop_body---------------------------------- |
|
2904 |
// Remove simplistic dead code from loop body |
|
2905 |
void IdealLoopTree::DCE_loop_body() { |
|
54703 | 2906 |
for (uint i = 0; i < _body.size(); i++) { |
2907 |
if (_body.at(i)->outcnt() == 0) { |
|
2908 |
_body.map(i, _body.pop()); |
|
2909 |
i--; // Ensure we revisit the updated index. |
|
2910 |
} |
|
2911 |
} |
|
1 | 2912 |
} |
2913 |
||
2914 |
||
2915 |
//------------------------------adjust_loop_exit_prob-------------------------- |
|
2916 |
// Look for loop-exit tests with the 50/50 (or worse) guesses from the parsing stage. |
|
2917 |
// Replace with a 1-in-10 exit guess. |
|
54703 | 2918 |
void IdealLoopTree::adjust_loop_exit_prob(PhaseIdealLoop *phase) { |
1 | 2919 |
Node *test = tail(); |
54703 | 2920 |
while (test != _head) { |
1 | 2921 |
uint top = test->Opcode(); |
54703 | 2922 |
if (top == Op_IfTrue || top == Op_IfFalse) { |
1 | 2923 |
int test_con = ((ProjNode*)test)->_con; |
2924 |
assert(top == (uint)(test_con? Op_IfTrue: Op_IfFalse), "sanity"); |
|
2925 |
IfNode *iff = test->in(0)->as_If(); |
|
54703 | 2926 |
if (iff->outcnt() == 2) { // Ignore dead tests |
1 | 2927 |
Node *bol = iff->in(1); |
54703 | 2928 |
if (bol && bol->req() > 1 && bol->in(1) && |
2929 |
((bol->in(1)->Opcode() == Op_StorePConditional) || |
|
2930 |
(bol->in(1)->Opcode() == Op_StoreIConditional) || |
|
2931 |
(bol->in(1)->Opcode() == Op_StoreLConditional) || |
|
2932 |
(bol->in(1)->Opcode() == Op_CompareAndExchangeB) || |
|
2933 |
(bol->in(1)->Opcode() == Op_CompareAndExchangeS) || |
|
2934 |
(bol->in(1)->Opcode() == Op_CompareAndExchangeI) || |
|
2935 |
(bol->in(1)->Opcode() == Op_CompareAndExchangeL) || |
|
2936 |
(bol->in(1)->Opcode() == Op_CompareAndExchangeP) || |
|
2937 |
(bol->in(1)->Opcode() == Op_CompareAndExchangeN) || |
|
2938 |
(bol->in(1)->Opcode() == Op_WeakCompareAndSwapB) || |
|
2939 |
(bol->in(1)->Opcode() == Op_WeakCompareAndSwapS) || |
|
2940 |
(bol->in(1)->Opcode() == Op_WeakCompareAndSwapI) || |
|
2941 |
(bol->in(1)->Opcode() == Op_WeakCompareAndSwapL) || |
|
2942 |
(bol->in(1)->Opcode() == Op_WeakCompareAndSwapP) || |
|
2943 |
(bol->in(1)->Opcode() == Op_WeakCompareAndSwapN) || |
|
2944 |
(bol->in(1)->Opcode() == Op_CompareAndSwapB) || |
|
2945 |
(bol->in(1)->Opcode() == Op_CompareAndSwapS) || |
|
2946 |
(bol->in(1)->Opcode() == Op_CompareAndSwapI) || |
|
2947 |
(bol->in(1)->Opcode() == Op_CompareAndSwapL) || |
|
2948 |
(bol->in(1)->Opcode() == Op_CompareAndSwapP) || |
|
2949 |
(bol->in(1)->Opcode() == Op_CompareAndSwapN) || |
|
2950 |
(bol->in(1)->Opcode() == Op_ShenandoahCompareAndExchangeP) || |
|
2951 |
(bol->in(1)->Opcode() == Op_ShenandoahCompareAndExchangeN) || |
|
2952 |
(bol->in(1)->Opcode() == Op_ShenandoahWeakCompareAndSwapP) || |
|
2953 |
(bol->in(1)->Opcode() == Op_ShenandoahWeakCompareAndSwapN) || |
|
2954 |
(bol->in(1)->Opcode() == Op_ShenandoahCompareAndSwapP) || |
|
2955 |
(bol->in(1)->Opcode() == Op_ShenandoahCompareAndSwapN))) |
|
1 | 2956 |
return; // Allocation loops RARELY take backedge |
2957 |
// Find the OTHER exit path from the IF |
|
2958 |
Node* ex = iff->proj_out(1-test_con); |
|
2959 |
float p = iff->_prob; |
|
54703 | 2960 |
if (!phase->is_member(this, ex) && iff->_fcnt == COUNT_UNKNOWN) { |
2961 |
if (top == Op_IfTrue) { |
|
2962 |
if (p < (PROB_FAIR + PROB_UNLIKELY_MAG(3))) { |
|
1 | 2963 |
iff->_prob = PROB_STATIC_FREQUENT; |
2964 |
} |
|
2965 |
} else { |
|
54703 | 2966 |
if (p > (PROB_FAIR - PROB_UNLIKELY_MAG(3))) { |
1 | 2967 |
iff->_prob = PROB_STATIC_INFREQUENT; |
2968 |
} |
|
2969 |
} |
|
2970 |
} |
|
2971 |
} |
|
2972 |
} |
|
2973 |
test = phase->idom(test); |
|
2974 |
} |
|
2975 |
} |
|
2976 |
||
31133
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
2977 |
#ifdef ASSERT |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
2978 |
static CountedLoopNode* locate_pre_from_main(CountedLoopNode *cl) { |
49487
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
2979 |
Node *ctrl = cl->skip_predicates(); |
31133
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
2980 |
assert(ctrl->Opcode() == Op_IfTrue || ctrl->Opcode() == Op_IfFalse, ""); |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
2981 |
Node *iffm = ctrl->in(0); |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
2982 |
assert(iffm->Opcode() == Op_If, ""); |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
2983 |
Node *p_f = iffm->in(0); |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
2984 |
assert(p_f->Opcode() == Op_IfFalse, ""); |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
2985 |
CountedLoopEndNode *pre_end = p_f->in(0)->as_CountedLoopEnd(); |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
2986 |
assert(pre_end->loopnode()->is_pre_loop(), ""); |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
2987 |
return pre_end->loopnode(); |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
2988 |
} |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
2989 |
#endif |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
2990 |
|
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
2991 |
// Remove the main and post loops and make the pre loop execute all |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
2992 |
// iterations. Useful when the pre loop is found empty. |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
2993 |
void IdealLoopTree::remove_main_post_loops(CountedLoopNode *cl, PhaseIdealLoop *phase) { |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
2994 |
CountedLoopEndNode* pre_end = cl->loopexit(); |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
2995 |
Node* pre_cmp = pre_end->cmp_node(); |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
2996 |
if (pre_cmp->in(2)->Opcode() != Op_Opaque1) { |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
2997 |
// Only safe to remove the main loop if the compiler optimized it |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
2998 |
// out based on an unknown number of iterations |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
2999 |
return; |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3000 |
} |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3001 |
|
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3002 |
// Can we find the main loop? |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3003 |
if (_next == NULL) { |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3004 |
return; |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3005 |
} |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3006 |
|
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3007 |
Node* next_head = _next->_head; |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3008 |
if (!next_head->is_CountedLoop()) { |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3009 |
return; |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3010 |
} |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3011 |
|
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3012 |
CountedLoopNode* main_head = next_head->as_CountedLoop(); |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3013 |
if (!main_head->is_main_loop()) { |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3014 |
return; |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3015 |
} |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3016 |
|
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3017 |
assert(locate_pre_from_main(main_head) == cl, "bad main loop"); |
49487
bde392011cd8
8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
48603
diff
changeset
|
3018 |
Node* main_iff = main_head->skip_predicates()->in(0); |
31133
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3019 |
|
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3020 |
// Remove the Opaque1Node of the pre loop and make it execute all iterations |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3021 |
phase->_igvn.replace_input_of(pre_cmp, 2, pre_cmp->in(2)->in(2)); |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3022 |
// Remove the Opaque1Node of the main loop so it can be optimized out |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3023 |
Node* main_cmp = main_iff->in(1)->in(1); |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3024 |
assert(main_cmp->in(2)->Opcode() == Op_Opaque1, "main loop has no opaque node?"); |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3025 |
phase->_igvn.replace_input_of(main_cmp, 2, main_cmp->in(2)->in(1)); |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3026 |
} |
1 | 3027 |
|
54700 | 3028 |
//------------------------------do_remove_empty_loop--------------------------- |
3029 |
// We always attempt remove empty loops. The approach is to replace the trip |
|
3030 |
// counter with the value it will have on the last iteration. This will break |
|
3031 |
// the loop. |
|
3032 |
bool IdealLoopTree::do_remove_empty_loop(PhaseIdealLoop *phase) { |
|
1 | 3033 |
// Minimum size must be empty loop |
54703 | 3034 |
if (_body.size() > EMPTY_LOOP_SIZE) { |
8732
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
3035 |
return false; |
54703 | 3036 |
} |
3037 |
if (!_head->is_CountedLoop()) { |
|
3038 |
return false; // Dead loop |
|
3039 |
} |
|
1 | 3040 |
CountedLoopNode *cl = _head->as_CountedLoop(); |
54703 | 3041 |
if (!cl->is_valid_counted_loop()) { |
3042 |
return false; // Malformed loop |
|
3043 |
} |
|
3044 |
if (!phase->is_member(this, phase->get_ctrl(cl->loopexit()->in(CountedLoopEndNode::TestValue)))) { |
|
3045 |
return false; // Infinite loop |
|
3046 |
} |
|
31133
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3047 |
if (cl->is_pre_loop()) { |
54703 | 3048 |
// If the loop we are removing is a pre-loop then the main and post loop |
3049 |
// can be removed as well. |
|
31133
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3050 |
remove_main_post_loops(cl, phase); |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3051 |
} |
3e7542b42a61
8085832: Optimize main and post loop out when pre loop is found empty
roland
parents:
31131
diff
changeset
|
3052 |
|
1 | 3053 |
#ifdef ASSERT |
3054 |
// Ensure only one phi which is the iv. |
|
3055 |
Node* iv = NULL; |
|
3056 |
for (DUIterator_Fast imax, i = cl->fast_outs(imax); i < imax; i++) { |
|
3057 |
Node* n = cl->fast_out(i); |
|
3058 |
if (n->Opcode() == Op_Phi) { |
|
54703 | 3059 |
assert(iv == NULL, "Too many phis"); |
1 | 3060 |
iv = n; |
3061 |
} |
|
3062 |
} |
|
54703 | 3063 |
assert(iv == cl->phi(), "Wrong phi"); |
1 | 3064 |
#endif |
8870 | 3065 |
|
3066 |
// main and post loops have explicitly created zero trip guard |
|
3067 |
bool needs_guard = !cl->is_main_loop() && !cl->is_post_loop(); |
|
3068 |
if (needs_guard) { |
|
9121 | 3069 |
// Skip guard if values not overlap. |
3070 |
const TypeInt* init_t = phase->_igvn.type(cl->init_trip())->is_int(); |
|
3071 |
const TypeInt* limit_t = phase->_igvn.type(cl->limit())->is_int(); |
|
3072 |
int stride_con = cl->stride_con(); |
|
3073 |
if (stride_con > 0) { |
|
3074 |
needs_guard = (init_t->_hi >= limit_t->_lo); |
|
3075 |
} else { |
|
3076 |
needs_guard = (init_t->_lo <= limit_t->_hi); |
|
3077 |
} |
|
3078 |
} |
|
3079 |
if (needs_guard) { |
|
8870 | 3080 |
// Check for an obvious zero trip guard. |
50623
5209d8a6303e
8203197: C2: consider all paths in loop body for loop predication
roland
parents:
50561
diff
changeset
|
3081 |
Node* inctrl = PhaseIdealLoop::skip_all_loop_predicates(cl->skip_predicates()); |
35838
a6e58eeeaa2e
8137049: Code quality: reducing an trivial integer loop does not produce an optimal code
roland
parents:
35759
diff
changeset
|
3082 |
if (inctrl->Opcode() == Op_IfTrue || inctrl->Opcode() == Op_IfFalse) { |
a6e58eeeaa2e
8137049: Code quality: reducing an trivial integer loop does not produce an optimal code
roland
parents:
35759
diff
changeset
|
3083 |
bool maybe_swapped = (inctrl->Opcode() == Op_IfFalse); |
8870 | 3084 |
// The test should look like just the backedge of a CountedLoop |
3085 |
Node* iff = inctrl->in(0); |
|
3086 |
if (iff->is_If()) { |
|
3087 |
Node* bol = iff->in(1); |
|
35838
a6e58eeeaa2e
8137049: Code quality: reducing an trivial integer loop does not produce an optimal code
roland
parents:
35759
diff
changeset
|
3088 |
if (bol->is_Bool()) { |
a6e58eeeaa2e
8137049: Code quality: reducing an trivial integer loop does not produce an optimal code
roland
parents:
35759
diff
changeset
|
3089 |
BoolTest test = bol->as_Bool()->_test; |
a6e58eeeaa2e
8137049: Code quality: reducing an trivial integer loop does not produce an optimal code
roland
parents:
35759
diff
changeset
|
3090 |
if (maybe_swapped) { |
a6e58eeeaa2e
8137049: Code quality: reducing an trivial integer loop does not produce an optimal code
roland
parents:
35759
diff
changeset
|
3091 |
test._test = test.commute(); |
a6e58eeeaa2e
8137049: Code quality: reducing an trivial integer loop does not produce an optimal code
roland
parents:
35759
diff
changeset
|
3092 |
test._test = test.negate(); |
a6e58eeeaa2e
8137049: Code quality: reducing an trivial integer loop does not produce an optimal code
roland
parents:
35759
diff
changeset
|
3093 |
} |
a6e58eeeaa2e
8137049: Code quality: reducing an trivial integer loop does not produce an optimal code
roland
parents:
35759
diff
changeset
|
3094 |
if (test._test == cl->loopexit()->test_trip()) { |
a6e58eeeaa2e
8137049: Code quality: reducing an trivial integer loop does not produce an optimal code
roland
parents:
35759
diff
changeset
|
3095 |
Node* cmp = bol->in(1); |
a6e58eeeaa2e
8137049: Code quality: reducing an trivial integer loop does not produce an optimal code
roland
parents:
35759
diff
changeset
|
3096 |
int init_idx = maybe_swapped ? 2 : 1; |
a6e58eeeaa2e
8137049: Code quality: reducing an trivial integer loop does not produce an optimal code
roland
parents:
35759
diff
changeset
|
3097 |
int limit_idx = maybe_swapped ? 1 : 2; |
a6e58eeeaa2e
8137049: Code quality: reducing an trivial integer loop does not produce an optimal code
roland
parents:
35759
diff
changeset
|
3098 |
if (cmp->is_Cmp() && cmp->in(init_idx) == cl->init_trip() && cmp->in(limit_idx) == cl->limit()) { |
a6e58eeeaa2e
8137049: Code quality: reducing an trivial integer loop does not produce an optimal code
roland
parents:
35759
diff
changeset
|
3099 |
needs_guard = false; |
a6e58eeeaa2e
8137049: Code quality: reducing an trivial integer loop does not produce an optimal code
roland
parents:
35759
diff
changeset
|
3100 |
} |
8870 | 3101 |
} |
3102 |
} |
|
3103 |
} |
|
3104 |
} |
|
3105 |
} |
|
3106 |
||
3107 |
#ifndef PRODUCT |
|
3108 |
if (PrintOpto) { |
|
3109 |
tty->print("Removing empty loop with%s zero trip guard", needs_guard ? "out" : ""); |
|
3110 |
this->dump_head(); |
|
3111 |
} else if (TraceLoopOpts) { |
|
3112 |
tty->print("Empty with%s zero trip guard ", needs_guard ? "out" : ""); |
|
3113 |
this->dump_head(); |
|
3114 |
} |
|
3115 |
#endif |
|
3116 |
||
3117 |
if (needs_guard) { |
|
3118 |
// Peel the loop to ensure there's a zero trip guard |
|
3119 |
Node_List old_new; |
|
3120 |
phase->do_peeling(this, old_new); |
|
3121 |
} |
|
3122 |
||
1 | 3123 |
// Replace the phi at loop head with the final value of the last |
3124 |
// iteration. Then the CountedLoopEnd will collapse (backedge never |
|
3125 |
// taken) and all loop-invariant uses of the exit values will be correct. |
|
3126 |
Node *phi = cl->phi(); |
|
9446 | 3127 |
Node *exact_limit = phase->exact_limit(this); |
3128 |
if (exact_limit != cl->limit()) { |
|
3129 |
// We also need to replace the original limit to collapse loop exit. |
|
3130 |
Node* cmp = cl->loopexit()->cmp_node(); |
|
3131 |
assert(cl->limit() == cmp->in(2), "sanity"); |
|
58589
45a085445a8c
8231988: Unexpected test result caused by C2 IdealLoopTree::do_remove_empty_loop
fyang
parents:
58354
diff
changeset
|
3132 |
// Duplicate cmp node if it has other users |
45a085445a8c
8231988: Unexpected test result caused by C2 IdealLoopTree::do_remove_empty_loop
fyang
parents:
58354
diff
changeset
|
3133 |
if (cmp->outcnt() > 1) { |
45a085445a8c
8231988: Unexpected test result caused by C2 IdealLoopTree::do_remove_empty_loop
fyang
parents:
58354
diff
changeset
|
3134 |
cmp = cmp->clone(); |
45a085445a8c
8231988: Unexpected test result caused by C2 IdealLoopTree::do_remove_empty_loop
fyang
parents:
58354
diff
changeset
|
3135 |
cmp = phase->_igvn.register_new_node_with_optimizer(cmp); |
45a085445a8c
8231988: Unexpected test result caused by C2 IdealLoopTree::do_remove_empty_loop
fyang
parents:
58354
diff
changeset
|
3136 |
BoolNode *bol = cl->loopexit()->in(CountedLoopEndNode::TestValue)->as_Bool(); |
45a085445a8c
8231988: Unexpected test result caused by C2 IdealLoopTree::do_remove_empty_loop
fyang
parents:
58354
diff
changeset
|
3137 |
phase->_igvn.replace_input_of(bol, 1, cmp); // put bol on worklist |
45a085445a8c
8231988: Unexpected test result caused by C2 IdealLoopTree::do_remove_empty_loop
fyang
parents:
58354
diff
changeset
|
3138 |
} |
9446 | 3139 |
phase->_igvn._worklist.push(cmp->in(2)); // put limit on worklist |
12958
009b6c9586d8
7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents:
10538
diff
changeset
|
3140 |
phase->_igvn.replace_input_of(cmp, 2, exact_limit); // put cmp on worklist |
9446 | 3141 |
} |
3142 |
// Note: the final value after increment should not overflow since |
|
3143 |
// counted loop has limit check predicate. |
|
54703 | 3144 |
Node *final = new SubINode(exact_limit, cl->stride()); |
1 | 3145 |
phase->register_new_node(final,cl->in(LoopNode::EntryControl)); |
5901
c046f8e9c52b
6677629: PhaseIterGVN::subsume_node() should call hash_delete() and add_users_to_worklist()
kvn
parents:
5547
diff
changeset
|
3146 |
phase->_igvn.replace_node(phi,final); |
1 | 3147 |
phase->C->set_major_progress(); |
3148 |
return true; |
|
3149 |
} |
|
3150 |
||
54700 | 3151 |
//------------------------------do_one_iteration_loop-------------------------- |
9121 | 3152 |
// Convert one iteration loop into normal code. |
54700 | 3153 |
bool IdealLoopTree::do_one_iteration_loop(PhaseIdealLoop *phase) { |
3154 |
if (!_head->as_Loop()->is_valid_counted_loop()) { |
|
9121 | 3155 |
return false; // Only for counted loop |
54700 | 3156 |
} |
9121 | 3157 |
CountedLoopNode *cl = _head->as_CountedLoop(); |
3158 |
if (!cl->has_exact_trip_count() || cl->trip_count() != 1) { |
|
3159 |
return false; |
|
3160 |
} |
|
3161 |
||
3162 |
#ifndef PRODUCT |
|
54703 | 3163 |
if (TraceLoopOpts) { |
9121 | 3164 |
tty->print("OneIteration "); |
3165 |
this->dump_head(); |
|
3166 |
} |
|
3167 |
#endif |
|
3168 |
||
3169 |
Node *init_n = cl->init_trip(); |
|
3170 |
#ifdef ASSERT |
|
3171 |
// Loop boundaries should be constant since trip count is exact. |
|
3172 |
assert(init_n->get_int() + cl->stride_con() >= cl->limit()->get_int(), "should be one iteration"); |
|
3173 |
#endif |
|
3174 |
// Replace the phi at loop head with the value of the init_trip. |
|
3175 |
// Then the CountedLoopEnd will collapse (backedge will not be taken) |
|
3176 |
// and all loop-invariant uses of the exit values will be correct. |
|
3177 |
phase->_igvn.replace_node(cl->phi(), cl->init_trip()); |
|
3178 |
phase->C->set_major_progress(); |
|
3179 |
return true; |
|
3180 |
} |
|
1 | 3181 |
|
3182 |
//============================================================================= |
|
3183 |
//------------------------------iteration_split_impl--------------------------- |
|
54703 | 3184 |
bool IdealLoopTree::iteration_split_impl(PhaseIdealLoop *phase, Node_List &old_new) { |
40031
6cc034201dba
8159016: Over-unrolled loop is partially removed
thartmann
parents:
39429
diff
changeset
|
3185 |
// Compute loop trip count if possible. |
6cc034201dba
8159016: Over-unrolled loop is partially removed
thartmann
parents:
39429
diff
changeset
|
3186 |
compute_trip_count(phase); |
9121 | 3187 |
|
3188 |
// Convert one iteration loop into normal code. |
|
54700 | 3189 |
if (do_one_iteration_loop(phase)) { |
9121 | 3190 |
return true; |
54700 | 3191 |
} |
1 | 3192 |
// Check and remove empty loops (spam micro-benchmarks) |
54700 | 3193 |
if (do_remove_empty_loop(phase)) { |
4643 | 3194 |
return true; // Here we removed an empty loop |
54700 | 3195 |
} |
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
3196 |
|
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
3197 |
AutoNodeBudget node_budget(phase); |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
3198 |
|
1 | 3199 |
// Non-counted loops may be peeled; exactly 1 iteration is peeled. |
3200 |
// This removes loop-invariant tests (usually null checks). |
|
9121 | 3201 |
if (!_head->is_CountedLoop()) { // Non-counted loop |
1 | 3202 |
if (PartialPeelLoop && phase->partial_peel(this, old_new)) { |
1433
ee60bd139c07
6743188: incomplete fix for 6700047 C2 failed in idom_no_update
never
parents:
1432
diff
changeset
|
3203 |
// Partial peel succeeded so terminate this round of loop opts |
ee60bd139c07
6743188: incomplete fix for 6700047 C2 failed in idom_no_update
never
parents:
1432
diff
changeset
|
3204 |
return false; |
1 | 3205 |
} |
55150 | 3206 |
if (policy_peeling(phase)) { // Should we peel? |
34174
4db2fb26dc49
8140424: don't prefix developer and notproduct flag variables with CONST_ in product builds
twisti
parents:
34164
diff
changeset
|
3207 |
if (PrintOpto) { tty->print_cr("should_peel"); } |
55150 | 3208 |
phase->do_peeling(this, old_new); |
3209 |
} else if (policy_unswitching(phase)) { |
|
1 | 3210 |
phase->do_unswitching(this, old_new); |
3211 |
} |
|
1433
ee60bd139c07
6743188: incomplete fix for 6700047 C2 failed in idom_no_update
never
parents:
1432
diff
changeset
|
3212 |
return true; |
1 | 3213 |
} |
3214 |
CountedLoopNode *cl = _head->as_CountedLoop(); |
|
3215 |
||
10263
fa58671dde31
7077439: Possible reference through NULL in loopPredicate.cpp:726
kvn
parents:
10258
diff
changeset
|
3216 |
if (!cl->is_valid_counted_loop()) return true; // Ignore various kinds of broken loops |
1 | 3217 |
|
3218 |
// Do nothing special to pre- and post- loops |
|
9121 | 3219 |
if (cl->is_pre_loop() || cl->is_post_loop()) return true; |
1 | 3220 |
|
3221 |
// Compute loop trip count from profile data |
|
3222 |
compute_profile_trip_cnt(phase); |
|
3223 |
||
3224 |
// Before attempting fancy unrolling, RCE or alignment, see if we want |
|
3225 |
// to completely unroll this loop or do loop unswitching. |
|
9121 | 3226 |
if (cl->is_normal_loop()) { |
55150 | 3227 |
if (policy_unswitching(phase)) { |
2876
b8ebc85d0b47
6837146: Should perform unswitch before maximally unroll in loop transformation
cfang
parents:
2131
diff
changeset
|
3228 |
phase->do_unswitching(this, old_new); |
b8ebc85d0b47
6837146: Should perform unswitch before maximally unroll in loop transformation
cfang
parents:
2131
diff
changeset
|
3229 |
return true; |
b8ebc85d0b47
6837146: Should perform unswitch before maximally unroll in loop transformation
cfang
parents:
2131
diff
changeset
|
3230 |
} |
55150 | 3231 |
if (policy_maximally_unroll(phase)) { |
1 | 3232 |
// Here we did some unrolling and peeling. Eventually we will |
3233 |
// completely unroll this loop and it will no longer be a loop. |
|
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
3234 |
phase->do_maximally_unroll(this, old_new); |
1433
ee60bd139c07
6743188: incomplete fix for 6700047 C2 failed in idom_no_update
never
parents:
1432
diff
changeset
|
3235 |
return true; |
1 | 3236 |
} |
3237 |
} |
|
3238 |
||
55150 | 3239 |
uint est_peeling = estimate_peeling(phase); |
3240 |
bool should_peel = 0 < est_peeling; |
|
3241 |
||
1 | 3242 |
// Counted loops may be peeled, may need some iterations run up |
3243 |
// front for RCE, and may want to align loop refs to a cache |
|
3244 |
// line. Thus we clone a full loop up front whose trip count is |
|
3245 |
// at least 1 (if peeling), but may be several more. |
|
3246 |
||
3247 |
// The main loop will start cache-line aligned with at least 1 |
|
3248 |
// iteration of the unrolled body (zero-trip test required) and |
|
3249 |
// will have some range checks removed. |
|
3250 |
||
3251 |
// A post-loop will finish any odd iterations (leftover after |
|
3252 |
// unrolling), plus any needed for RCE purposes. |
|
3253 |
||
3254 |
bool should_unroll = policy_unroll(phase); |
|
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
3255 |
bool should_rce = policy_range_check(phase); |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
3256 |
// TODO: Remove align -- not used. |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
3257 |
bool should_align = policy_align(phase); |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
3258 |
|
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
3259 |
// If not RCE'ing (iteration splitting) or Aligning, then we do not need a |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
3260 |
// pre-loop. We may still need to peel an initial iteration but we will not |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
3261 |
// be needing an unknown number of pre-iterations. |
1 | 3262 |
// |
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
3263 |
// Basically, if may_rce_align reports FALSE first time through, we will not |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
3264 |
// be able to later do RCE or Aligning on this loop. |
1 | 3265 |
bool may_rce_align = !policy_peel_only(phase) || should_rce || should_align; |
3266 |
||
3267 |
// If we have any of these conditions (RCE, alignment, unrolling) met, then |
|
3268 |
// we switch to the pre-/main-/post-loop model. This model also covers |
|
3269 |
// peeling. |
|
9121 | 3270 |
if (should_rce || should_align || should_unroll) { |
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
3271 |
if (cl->is_normal_loop()) { // Convert to 'pre/main/post' loops |
55150 | 3272 |
uint estimate = est_loop_clone_sz(3); |
3273 |
if (!phase->may_require_nodes(estimate)) { |
|
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
3274 |
return false; |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
3275 |
} |
55150 | 3276 |
phase->insert_pre_post_loops(this, old_new, !may_rce_align); |
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
3277 |
} |
55150 | 3278 |
// Adjust the pre- and main-loop limits to let the pre and post loops run |
3279 |
// with full checks, but the main-loop with no checks. Remove said checks |
|
3280 |
// from the main body. |
|
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
3281 |
if (should_rce) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
3282 |
if (phase->do_range_check(this, old_new) != 0) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
3283 |
cl->mark_has_range_checks(); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
3284 |
} |
38129
7adeefaa6d1d
8154763: Crash with "assert(RangeCheckElimination)" if RangeCheckElimination is disabled
thartmann
parents:
37292
diff
changeset
|
3285 |
} else if (PostLoopMultiversioning) { |
37292
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
3286 |
phase->has_range_checks(this); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
3287 |
} |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
3288 |
|
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
3289 |
if (should_unroll && !should_peel && PostLoopMultiversioning) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
3290 |
// Try to setup multiversioning on main loops before they are unrolled |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
3291 |
if (cl->is_main_loop() && (cl->unrolled_count() == 1)) { |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
3292 |
phase->insert_scalar_rced_post_loop(this, old_new); |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
3293 |
} |
64f6ae06310e
8151573: Multiversioning for range check elimination
mcberg
parents:
37287
diff
changeset
|
3294 |
} |
1 | 3295 |
|
3296 |
// Double loop body for unrolling. Adjust the minimum-trip test (will do |
|
3297 |
// twice as many iterations as before) and the main body limit (only do |
|
3298 |
// an even number of trips). If we are peeling, we might enable some RCE |
|
3299 |
// and we'd rather unroll the post-RCE'd loop SO... do not unroll if |
|
3300 |
// peeling. |
|
30211 | 3301 |
if (should_unroll && !should_peel) { |
36066 | 3302 |
if (SuperWordLoopUnrollAnalysis) { |
3303 |
phase->insert_vector_post_loop(this, old_new); |
|
3304 |
} |
|
30211 | 3305 |
phase->do_unroll(this, old_new, true); |
3306 |
} |
|
1 | 3307 |
|
54703 | 3308 |
// Adjust the pre-loop limits to align the main body iterations. |
3309 |
if (should_align) { |
|
1 | 3310 |
Unimplemented(); |
54703 | 3311 |
} |
1 | 3312 |
} else { // Else we have an unchanged counted loop |
54703 | 3313 |
if (should_peel) { // Might want to peel but do nothing else |
55150 | 3314 |
if (phase->may_require_nodes(est_peeling)) { |
3315 |
phase->do_peeling(this, old_new); |
|
3316 |
} |
|
54703 | 3317 |
} |
1 | 3318 |
} |
1433
ee60bd139c07
6743188: incomplete fix for 6700047 C2 failed in idom_no_update
never
parents:
1432
diff
changeset
|
3319 |
return true; |
1 | 3320 |
} |
3321 |
||
3322 |
||
3323 |
//============================================================================= |
|
3324 |
//------------------------------iteration_split-------------------------------- |
|
54703 | 3325 |
bool IdealLoopTree::iteration_split(PhaseIdealLoop* phase, Node_List &old_new) { |
1 | 3326 |
// Recursively iteration split nested loops |
54703 | 3327 |
if (_child && !_child->iteration_split(phase, old_new)) { |
1433
ee60bd139c07
6743188: incomplete fix for 6700047 C2 failed in idom_no_update
never
parents:
1432
diff
changeset
|
3328 |
return false; |
54703 | 3329 |
} |
1 | 3330 |
|
3331 |
// Clean out prior deadwood |
|
3332 |
DCE_loop_body(); |
|
3333 |
||
3334 |
// Look for loop-exit tests with my 50/50 guesses from the Parsing stage. |
|
3335 |
// Replace with a 1-in-10 exit guess. |
|
54699 | 3336 |
if (!is_root() && is_loop()) { |
1 | 3337 |
adjust_loop_exit_prob(phase); |
3338 |
} |
|
3339 |
||
54699 | 3340 |
// Unrolling, RCE and peeling efforts, iff innermost loop. |
3341 |
if (_allow_optimizations && is_innermost()) { |
|
1 | 3342 |
if (!_has_call) { |
54699 | 3343 |
if (!iteration_split_impl(phase, old_new)) { |
3344 |
return false; |
|
3345 |
} |
|
54705
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
3346 |
} else { |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
3347 |
AutoNodeBudget node_budget(phase); |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
3348 |
if (policy_unswitching(phase)) { |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
3349 |
phase->do_unswitching(this, old_new); |
fc7627bf4b01
8216137: assert failed: Live node limit exceeded.
phedlin
parents:
54703
diff
changeset
|
3350 |
} |
1 | 3351 |
} |
3352 |
} |
|
3353 |
||
3354 |
// Minor offset re-organization to remove loop-fallout uses of |
|
8732
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
3355 |
// trip counter when there was no major reshaping. |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
3356 |
phase->reorg_offsets(this); |
16fc1c68714b
7008866: Missing loop predicate for loop with multiple entries
kvn
parents:
7397
diff
changeset
|
3357 |
|
54703 | 3358 |
if (_next && !_next->iteration_split(phase, old_new)) { |
1433
ee60bd139c07
6743188: incomplete fix for 6700047 C2 failed in idom_no_update
never
parents:
1432
diff
changeset
|
3359 |
return false; |
54703 | 3360 |
} |
1433
ee60bd139c07
6743188: incomplete fix for 6700047 C2 failed in idom_no_update
never
parents:
1432
diff
changeset
|
3361 |
return true; |
1 | 3362 |
} |
4643 | 3363 |
|
3364 |
||
9101 | 3365 |
//============================================================================= |
6433 | 3366 |
// Process all the loops in the loop tree and replace any fill |
35574
2b25eb88c8d6
6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
35155
diff
changeset
|
3367 |
// patterns with an intrinsic version. |
6433 | 3368 |
bool PhaseIdealLoop::do_intrinsify_fill() { |
3369 |
bool changed = false; |
|
3370 |
for (LoopTreeIterator iter(_ltree_root); !iter.done(); iter.next()) { |
|
3371 |
IdealLoopTree* lpt = iter.current(); |
|
3372 |
changed |= intrinsify_fill(lpt); |
|
3373 |
} |
|
3374 |
return changed; |
|
3375 |
} |
|
3376 |
||
3377 |
||
3378 |
// Examine an inner loop looking for a a single store of an invariant |
|
3379 |
// value in a unit stride loop, |
|
3380 |
bool PhaseIdealLoop::match_fill_loop(IdealLoopTree* lpt, Node*& store, Node*& store_value, |
|
3381 |
Node*& shift, Node*& con) { |
|
3382 |
const char* msg = NULL; |
|
3383 |
Node* msg_node = NULL; |
|
3384 |
||
3385 |
store_value = NULL; |
|
3386 |
con = NULL; |
|
3387 |
shift = NULL; |
|
3388 |
||
3389 |
// Process the loop looking for stores. If there are multiple |
|
3390 |
// stores or extra control flow give at this point. |
|
3391 |
CountedLoopNode* head = lpt->_head->as_CountedLoop(); |
|
3392 |
for (uint i = 0; msg == NULL && i < lpt->_body.size(); i++) { |
|
3393 |
Node* n = lpt->_body.at(i); |
|
3394 |
if (n->outcnt() == 0) continue; // Ignore dead |
|
3395 |
if (n->is_Store()) { |
|
3396 |
if (store != NULL) { |
|
3397 |
msg = "multiple stores"; |
|
3398 |
break; |
|
3399 |
} |
|
3400 |
int opc = n->Opcode(); |
|
13969
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13967
diff
changeset
|
3401 |
if (opc == Op_StoreP || opc == Op_StoreN || opc == Op_StoreNKlass || opc == Op_StoreCM) { |
6433 | 3402 |
msg = "oop fills not handled"; |
3403 |
break; |
|
3404 |
} |
|
3405 |
Node* value = n->in(MemNode::ValueIn); |
|
3406 |
if (!lpt->is_invariant(value)) { |
|
3407 |
msg = "variant store value"; |
|
6455
4a8142e5f75f
6982533: Crash in ~StubRoutines::jbyte_fill with AggressiveOpts enabled
never
parents:
6433
diff
changeset
|
3408 |
} else if (!_igvn.type(n->in(MemNode::Address))->isa_aryptr()) { |
4a8142e5f75f
6982533: Crash in ~StubRoutines::jbyte_fill with AggressiveOpts enabled
never
parents:
6433
diff
changeset
|
3409 |
msg = "not array address"; |
6433 | 3410 |
} |
3411 |
store = n; |
|
3412 |
store_value = value; |
|
48603
e5da6c246176
8194992: Null pointer dereference in MultiNode::proj_out related to loopexit()
dlong
parents:
48595
diff
changeset
|
3413 |
} else if (n->is_If() && n != head->loopexit_or_null()) { |
6433 | 3414 |
msg = "extra control flow"; |
3415 |
msg_node = n; |
|
3416 |
} |
|
3417 |
} |
|
3418 |
||
3419 |
if (store == NULL) { |
|
3420 |
// No store in loop |
|
3421 |
return false; |
|
3422 |
} |
|
3423 |
||
3424 |
if (msg == NULL && head->stride_con() != 1) { |
|
3425 |
// could handle negative strides too |
|
3426 |
if (head->stride_con() < 0) { |
|
3427 |
msg = "negative stride"; |
|
3428 |
} else { |
|
3429 |
msg = "non-unit stride"; |
|
3430 |
} |
|
3431 |
} |
|
3432 |
||
3433 |
if (msg == NULL && !store->in(MemNode::Address)->is_AddP()) { |
|
3434 |
msg = "can't handle store address"; |
|
3435 |
msg_node = store->in(MemNode::Address); |
|
3436 |
} |
|
3437 |
||
6739
750998abc20f
6984979: OptimizeFill misses some cases with an odd memory graph
never
parents:
6455
diff
changeset
|
3438 |
if (msg == NULL && |
750998abc20f
6984979: OptimizeFill misses some cases with an odd memory graph
never
parents:
6455
diff
changeset
|
3439 |
(!store->in(MemNode::Memory)->is_Phi() || |
750998abc20f
6984979: OptimizeFill misses some cases with an odd memory graph
never
parents:
6455
diff
changeset
|
3440 |
store->in(MemNode::Memory)->in(LoopNode::LoopBackControl) != store)) { |
750998abc20f
6984979: OptimizeFill misses some cases with an odd memory graph
never
parents:
6455
diff
changeset
|
3441 |
msg = "store memory isn't proper phi"; |
750998abc20f
6984979: OptimizeFill misses some cases with an odd memory graph
never
parents:
6455
diff
changeset
|
3442 |
msg_node = store->in(MemNode::Memory); |
750998abc20f
6984979: OptimizeFill misses some cases with an odd memory graph
never
parents:
6455
diff
changeset
|
3443 |
} |
750998abc20f
6984979: OptimizeFill misses some cases with an odd memory graph
never
parents:
6455
diff
changeset
|
3444 |
|
6433 | 3445 |
// Make sure there is an appropriate fill routine |
3446 |
BasicType t = store->as_Mem()->memory_type(); |
|
3447 |
const char* fill_name; |
|
3448 |
if (msg == NULL && |
|
3449 |
StubRoutines::select_fill_function(t, false, fill_name) == NULL) { |
|
3450 |
msg = "unsupported store"; |
|
3451 |
msg_node = store; |
|
3452 |
} |
|
3453 |
||
3454 |
if (msg != NULL) { |
|
3455 |
#ifndef PRODUCT |
|
3456 |
if (TraceOptimizeFill) { |
|
3457 |
tty->print_cr("not fill intrinsic candidate: %s", msg); |
|
3458 |
if (msg_node != NULL) msg_node->dump(); |
|
3459 |
} |
|
3460 |
#endif |
|
3461 |
return false; |
|
3462 |
} |
|
3463 |
||
3464 |
// Make sure the address expression can be handled. It should be |
|
35574
2b25eb88c8d6
6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
35155
diff
changeset
|
3465 |
// head->phi * elsize + con. head->phi might have a ConvI2L(CastII()). |
6433 | 3466 |
Node* elements[4]; |
35574
2b25eb88c8d6
6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
35155
diff
changeset
|
3467 |
Node* cast = NULL; |
6433 | 3468 |
Node* conv = NULL; |
6455
4a8142e5f75f
6982533: Crash in ~StubRoutines::jbyte_fill with AggressiveOpts enabled
never
parents:
6433
diff
changeset
|
3469 |
bool found_index = false; |
6433 | 3470 |
int count = store->in(MemNode::Address)->as_AddP()->unpack_offsets(elements, ARRAY_SIZE(elements)); |
3471 |
for (int e = 0; e < count; e++) { |
|
3472 |
Node* n = elements[e]; |
|
3473 |
if (n->is_Con() && con == NULL) { |
|
3474 |
con = n; |
|
3475 |
} else if (n->Opcode() == Op_LShiftX && shift == NULL) { |
|
3476 |
Node* value = n->in(1); |
|
3477 |
#ifdef _LP64 |
|
3478 |
if (value->Opcode() == Op_ConvI2L) { |
|
3479 |
conv = value; |
|
3480 |
value = value->in(1); |
|
3481 |
} |
|
35574
2b25eb88c8d6
6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
35155
diff
changeset
|
3482 |
if (value->Opcode() == Op_CastII && |
2b25eb88c8d6
6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
35155
diff
changeset
|
3483 |
value->as_CastII()->has_range_check()) { |
2b25eb88c8d6
6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
35155
diff
changeset
|
3484 |
// Skip range check dependent CastII nodes |
2b25eb88c8d6
6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
35155
diff
changeset
|
3485 |
cast = value; |
2b25eb88c8d6
6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
35155
diff
changeset
|
3486 |
value = value->in(1); |
2b25eb88c8d6
6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
35155
diff
changeset
|
3487 |
} |
6433 | 3488 |
#endif |
3489 |
if (value != head->phi()) { |
|
3490 |
msg = "unhandled shift in address"; |
|
3491 |
} else { |
|
9104
85edf8ec98b2
7026957: assert(type2aelembytes(store->as_Mem()->memory_type(), true) == 1 << shift->in(2)->get_int()) failed
never
parents:
9101
diff
changeset
|
3492 |
if (type2aelembytes(store->as_Mem()->memory_type(), true) != (1 << n->in(2)->get_int())) { |
85edf8ec98b2
7026957: assert(type2aelembytes(store->as_Mem()->memory_type(), true) == 1 << shift->in(2)->get_int()) failed
never
parents:
9101
diff
changeset
|
3493 |
msg = "scale doesn't match"; |
85edf8ec98b2
7026957: assert(type2aelembytes(store->as_Mem()->memory_type(), true) == 1 << shift->in(2)->get_int()) failed
never
parents:
9101
diff
changeset
|
3494 |
} else { |
85edf8ec98b2
7026957: assert(type2aelembytes(store->as_Mem()->memory_type(), true) == 1 << shift->in(2)->get_int()) failed
never
parents:
9101
diff
changeset
|
3495 |
found_index = true; |
85edf8ec98b2
7026957: assert(type2aelembytes(store->as_Mem()->memory_type(), true) == 1 << shift->in(2)->get_int()) failed
never
parents:
9101
diff
changeset
|
3496 |
shift = n; |
85edf8ec98b2
7026957: assert(type2aelembytes(store->as_Mem()->memory_type(), true) == 1 << shift->in(2)->get_int()) failed
never
parents:
9101
diff
changeset
|
3497 |
} |
6433 | 3498 |
} |
3499 |
} else if (n->Opcode() == Op_ConvI2L && conv == NULL) { |
|
35574
2b25eb88c8d6
6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
35155
diff
changeset
|
3500 |
conv = n; |
2b25eb88c8d6
6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
35155
diff
changeset
|
3501 |
n = n->in(1); |
2b25eb88c8d6
6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
35155
diff
changeset
|
3502 |
if (n->Opcode() == Op_CastII && |
2b25eb88c8d6
6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
35155
diff
changeset
|
3503 |
n->as_CastII()->has_range_check()) { |
2b25eb88c8d6
6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
35155
diff
changeset
|
3504 |
// Skip range check dependent CastII nodes |
2b25eb88c8d6
6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
35155
diff
changeset
|
3505 |
cast = n; |
2b25eb88c8d6
6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
35155
diff
changeset
|
3506 |
n = n->in(1); |
2b25eb88c8d6
6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
35155
diff
changeset
|
3507 |
} |
2b25eb88c8d6
6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
35155
diff
changeset
|
3508 |
if (n == head->phi()) { |
6455
4a8142e5f75f
6982533: Crash in ~StubRoutines::jbyte_fill with AggressiveOpts enabled
never
parents:
6433
diff
changeset
|
3509 |
found_index = true; |
6433 | 3510 |
} else { |
3511 |
msg = "unhandled input to ConvI2L"; |
|
3512 |
} |
|
3513 |
} else if (n == head->phi()) { |
|
3514 |
// no shift, check below for allowed cases |
|
6455
4a8142e5f75f
6982533: Crash in ~StubRoutines::jbyte_fill with AggressiveOpts enabled
never
parents:
6433
diff
changeset
|
3515 |
found_index = true; |
6433 | 3516 |
} else { |
3517 |
msg = "unhandled node in address"; |
|
3518 |
msg_node = n; |
|
3519 |
} |
|
3520 |
} |
|
3521 |
||
3522 |
if (count == -1) { |
|
3523 |
msg = "malformed address expression"; |
|
3524 |
msg_node = store; |
|
3525 |
} |
|
3526 |
||
6455
4a8142e5f75f
6982533: Crash in ~StubRoutines::jbyte_fill with AggressiveOpts enabled
never
parents:
6433
diff
changeset
|
3527 |
if (!found_index) { |
4a8142e5f75f
6982533: Crash in ~StubRoutines::jbyte_fill with AggressiveOpts enabled
never
parents:
6433
diff
changeset
|
3528 |
msg = "missing use of index"; |
4a8142e5f75f
6982533: Crash in ~StubRoutines::jbyte_fill with AggressiveOpts enabled
never
parents:
6433
diff
changeset
|
3529 |
} |
4a8142e5f75f
6982533: Crash in ~StubRoutines::jbyte_fill with AggressiveOpts enabled
never
parents:
6433
diff
changeset
|
3530 |
|
6433 | 3531 |
// byte sized items won't have a shift |
3532 |
if (msg == NULL && shift == NULL && t != T_BYTE && t != T_BOOLEAN) { |
|
3533 |
msg = "can't find shift"; |
|
3534 |
msg_node = store; |
|
3535 |
} |
|
3536 |
||
3537 |
if (msg != NULL) { |
|
3538 |
#ifndef PRODUCT |
|
3539 |
if (TraceOptimizeFill) { |
|
3540 |
tty->print_cr("not fill intrinsic: %s", msg); |
|
3541 |
if (msg_node != NULL) msg_node->dump(); |
|
3542 |
} |
|
3543 |
#endif |
|
3544 |
return false; |
|
3545 |
} |
|
3546 |
||
3547 |
// No make sure all the other nodes in the loop can be handled |
|
3548 |
VectorSet ok(Thread::current()->resource_area()); |
|
3549 |
||
3550 |
// store related values are ok |
|
3551 |
ok.set(store->_idx); |
|
3552 |
ok.set(store->in(MemNode::Memory)->_idx); |
|
3553 |
||
16380
d1e1ca068275
8009181: [parfait] Null pointer deference in hotspot/src/share/vm/opto/loopTransform.cpp
morris
parents:
15919
diff
changeset
|
3554 |
CountedLoopEndNode* loop_exit = head->loopexit(); |
d1e1ca068275
8009181: [parfait] Null pointer deference in hotspot/src/share/vm/opto/loopTransform.cpp
morris
parents:
15919
diff
changeset
|
3555 |
|
6433 | 3556 |
// Loop structure is ok |
3557 |
ok.set(head->_idx); |
|
16380
d1e1ca068275
8009181: [parfait] Null pointer deference in hotspot/src/share/vm/opto/loopTransform.cpp
morris
parents:
15919
diff
changeset
|
3558 |
ok.set(loop_exit->_idx); |
6433 | 3559 |
ok.set(head->phi()->_idx); |
3560 |
ok.set(head->incr()->_idx); |
|
16380
d1e1ca068275
8009181: [parfait] Null pointer deference in hotspot/src/share/vm/opto/loopTransform.cpp
morris
parents:
15919
diff
changeset
|
3561 |
ok.set(loop_exit->cmp_node()->_idx); |
d1e1ca068275
8009181: [parfait] Null pointer deference in hotspot/src/share/vm/opto/loopTransform.cpp
morris
parents:
15919
diff
changeset
|
3562 |
ok.set(loop_exit->in(1)->_idx); |
6433 | 3563 |
|
3564 |
// Address elements are ok |
|
3565 |
if (con) ok.set(con->_idx); |
|
3566 |
if (shift) ok.set(shift->_idx); |
|
35574
2b25eb88c8d6
6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
35155
diff
changeset
|
3567 |
if (cast) ok.set(cast->_idx); |
6433 | 3568 |
if (conv) ok.set(conv->_idx); |
3569 |
||
3570 |
for (uint i = 0; msg == NULL && i < lpt->_body.size(); i++) { |
|
3571 |
Node* n = lpt->_body.at(i); |
|
3572 |
if (n->outcnt() == 0) continue; // Ignore dead |
|
3573 |
if (ok.test(n->_idx)) continue; |
|
3574 |
// Backedge projection is ok |
|
16380
d1e1ca068275
8009181: [parfait] Null pointer deference in hotspot/src/share/vm/opto/loopTransform.cpp
morris
parents:
15919
diff
changeset
|
3575 |
if (n->is_IfTrue() && n->in(0) == loop_exit) continue; |
6433 | 3576 |
if (!n->is_AddP()) { |
3577 |
msg = "unhandled node"; |
|
3578 |
msg_node = n; |
|
3579 |
break; |
|
3580 |
} |
|
3581 |
} |
|
3582 |
||
3583 |
// Make sure no unexpected values are used outside the loop |
|
3584 |
for (uint i = 0; msg == NULL && i < lpt->_body.size(); i++) { |
|
3585 |
Node* n = lpt->_body.at(i); |
|
3586 |
// These values can be replaced with other nodes if they are used |
|
3587 |
// outside the loop. |
|
16380
d1e1ca068275
8009181: [parfait] Null pointer deference in hotspot/src/share/vm/opto/loopTransform.cpp
morris
parents:
15919
diff
changeset
|
3588 |
if (n == store || n == loop_exit || n == head->incr() || n == store->in(MemNode::Memory)) continue; |
6433 | 3589 |
for (SimpleDUIterator iter(n); iter.has_next(); iter.next()) { |
3590 |
Node* use = iter.get(); |
|
3591 |
if (!lpt->_body.contains(use)) { |
|
3592 |
msg = "node is used outside loop"; |
|
3593 |
// lpt->_body.dump(); |
|
3594 |
msg_node = n; |
|
3595 |
break; |
|
3596 |
} |
|
3597 |
} |
|
3598 |
} |
|
3599 |
||
3600 |
#ifdef ASSERT |
|
3601 |
if (TraceOptimizeFill) { |
|
3602 |
if (msg != NULL) { |
|
3603 |
tty->print_cr("no fill intrinsic: %s", msg); |
|
3604 |
if (msg_node != NULL) msg_node->dump(); |
|
3605 |
} else { |
|
3606 |
tty->print_cr("fill intrinsic for:"); |
|
3607 |
} |
|
3608 |
store->dump(); |
|
3609 |
if (Verbose) { |
|
3610 |
lpt->_body.dump(); |
|
3611 |
} |
|
3612 |
} |
|
3613 |
#endif |
|
3614 |
||
3615 |
return msg == NULL; |
|
3616 |
} |
|
3617 |
||
3618 |
||
3619 |
||
3620 |
bool PhaseIdealLoop::intrinsify_fill(IdealLoopTree* lpt) { |
|
3621 |
// Only for counted inner loops |
|
54699 | 3622 |
if (!lpt->is_counted() || !lpt->is_innermost()) { |
6433 | 3623 |
return false; |
3624 |
} |
|
3625 |
||
3626 |
// Must have constant stride |
|
3627 |
CountedLoopNode* head = lpt->_head->as_CountedLoop(); |
|
10263
fa58671dde31
7077439: Possible reference through NULL in loopPredicate.cpp:726
kvn
parents:
10258
diff
changeset
|
3628 |
if (!head->is_valid_counted_loop() || !head->is_normal_loop()) { |
6433 | 3629 |
return false; |
3630 |
} |
|
3631 |
||
48145 | 3632 |
head->verify_strip_mined(1); |
3633 |
||
6433 | 3634 |
// Check that the body only contains a store of a loop invariant |
3635 |
// value that is indexed by the loop phi. |
|
3636 |
Node* store = NULL; |
|
3637 |
Node* store_value = NULL; |
|
3638 |
Node* shift = NULL; |
|
3639 |
Node* offset = NULL; |
|
3640 |
if (!match_fill_loop(lpt, store, store_value, shift, offset)) { |
|
3641 |
return false; |
|
3642 |
} |
|
3643 |
||
48595
5d699d81c10c
8194988: 8 Null pointer dereference defect groups related to MultiNode::proj_out()
dlong
parents:
48145
diff
changeset
|
3644 |
Node* exit = head->loopexit()->proj_out_or_null(0); |
44314
30ae899b9eca
8175345: Reported null pointer dereference defect groups
rraghavan
parents:
42622
diff
changeset
|
3645 |
if (exit == NULL) { |
30ae899b9eca
8175345: Reported null pointer dereference defect groups
rraghavan
parents:
42622
diff
changeset
|
3646 |
return false; |
30ae899b9eca
8175345: Reported null pointer dereference defect groups
rraghavan
parents:
42622
diff
changeset
|
3647 |
} |
30ae899b9eca
8175345: Reported null pointer dereference defect groups
rraghavan
parents:
42622
diff
changeset
|
3648 |
|
9101 | 3649 |
#ifndef PRODUCT |
3650 |
if (TraceLoopOpts) { |
|
3651 |
tty->print("ArrayFill "); |
|
3652 |
lpt->dump_head(); |
|
3653 |
} |
|
3654 |
#endif |
|
3655 |
||
6433 | 3656 |
// Now replace the whole loop body by a call to a fill routine that |
3657 |
// covers the same region as the loop. |
|
3658 |
Node* base = store->in(MemNode::Address)->as_AddP()->in(AddPNode::Base); |
|
3659 |
||
3660 |
// Build an expression for the beginning of the copy region |
|
3661 |
Node* index = head->init_trip(); |
|
3662 |
#ifdef _LP64 |
|
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
3663 |
index = new ConvI2LNode(index); |
6433 | 3664 |
_igvn.register_new_node_with_optimizer(index); |
3665 |
#endif |
|
3666 |
if (shift != NULL) { |
|
3667 |
// byte arrays don't require a shift but others do. |
|
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
3668 |
index = new LShiftXNode(index, shift->in(2)); |
6433 | 3669 |
_igvn.register_new_node_with_optimizer(index); |
3670 |
} |
|
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
3671 |
index = new AddPNode(base, base, index); |
6433 | 3672 |
_igvn.register_new_node_with_optimizer(index); |
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
3673 |
Node* from = new AddPNode(base, index, offset); |
6433 | 3674 |
_igvn.register_new_node_with_optimizer(from); |
3675 |
// Compute the number of elements to copy |
|
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
3676 |
Node* len = new SubINode(head->limit(), head->init_trip()); |
6433 | 3677 |
_igvn.register_new_node_with_optimizer(len); |
3678 |
||
3679 |
BasicType t = store->as_Mem()->memory_type(); |
|
3680 |
bool aligned = false; |
|
3681 |
if (offset != NULL && head->init_trip()->is_Con()) { |
|
3682 |
int element_size = type2aelembytes(t); |
|
3683 |
aligned = (offset->find_intptr_t_type()->get_con() + head->init_trip()->get_int() * element_size) % HeapWordSize == 0; |
|
3684 |
} |
|
3685 |
||
3686 |
// Build a call to the fill routine |
|
3687 |
const char* fill_name; |
|
3688 |
address fill = StubRoutines::select_fill_function(t, aligned, fill_name); |
|
3689 |
assert(fill != NULL, "what?"); |
|
3690 |
||
3691 |
// Convert float/double to int/long for fill routines |
|
3692 |
if (t == T_FLOAT) { |
|
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
3693 |
store_value = new MoveF2INode(store_value); |
6433 | 3694 |
_igvn.register_new_node_with_optimizer(store_value); |
3695 |
} else if (t == T_DOUBLE) { |
|
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
3696 |
store_value = new MoveD2LNode(store_value); |
6433 | 3697 |
_igvn.register_new_node_with_optimizer(store_value); |
3698 |
} |
|
3699 |
||
3700 |
Node* mem_phi = store->in(MemNode::Memory); |
|
3701 |
Node* result_ctrl; |
|
3702 |
Node* result_mem; |
|
3703 |
const TypeFunc* call_type = OptoRuntime::array_fill_Type(); |
|
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
3704 |
CallLeafNode *call = new CallLeafNoFPNode(call_type, fill, |
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
3705 |
fill_name, TypeAryPtr::get_array_body_type(t)); |
22834
3e2df6a4a28c
8024342: PPC64 (part 111): Support for C calling conventions that require 64-bit ints.
goetz
parents:
19283
diff
changeset
|
3706 |
uint cnt = 0; |
3e2df6a4a28c
8024342: PPC64 (part 111): Support for C calling conventions that require 64-bit ints.
goetz
parents:
19283
diff
changeset
|
3707 |
call->init_req(TypeFunc::Parms + cnt++, from); |
3e2df6a4a28c
8024342: PPC64 (part 111): Support for C calling conventions that require 64-bit ints.
goetz
parents:
19283
diff
changeset
|
3708 |
call->init_req(TypeFunc::Parms + cnt++, store_value); |
6770
a67870aaedb3
6980792: Crash "exception happened outside interpreter, nmethods and vtable stubs (1)"
never
parents:
6739
diff
changeset
|
3709 |
#ifdef _LP64 |
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
3710 |
len = new ConvI2LNode(len); |
6770
a67870aaedb3
6980792: Crash "exception happened outside interpreter, nmethods and vtable stubs (1)"
never
parents:
6739
diff
changeset
|
3711 |
_igvn.register_new_node_with_optimizer(len); |
a67870aaedb3
6980792: Crash "exception happened outside interpreter, nmethods and vtable stubs (1)"
never
parents:
6739
diff
changeset
|
3712 |
#endif |
22834
3e2df6a4a28c
8024342: PPC64 (part 111): Support for C calling conventions that require 64-bit ints.
goetz
parents:
19283
diff
changeset
|
3713 |
call->init_req(TypeFunc::Parms + cnt++, len); |
6770
a67870aaedb3
6980792: Crash "exception happened outside interpreter, nmethods and vtable stubs (1)"
never
parents:
6739
diff
changeset
|
3714 |
#ifdef _LP64 |
22834
3e2df6a4a28c
8024342: PPC64 (part 111): Support for C calling conventions that require 64-bit ints.
goetz
parents:
19283
diff
changeset
|
3715 |
call->init_req(TypeFunc::Parms + cnt++, C->top()); |
6770
a67870aaedb3
6980792: Crash "exception happened outside interpreter, nmethods and vtable stubs (1)"
never
parents:
6739
diff
changeset
|
3716 |
#endif |
22834
3e2df6a4a28c
8024342: PPC64 (part 111): Support for C calling conventions that require 64-bit ints.
goetz
parents:
19283
diff
changeset
|
3717 |
call->init_req(TypeFunc::Control, head->init_control()); |
3e2df6a4a28c
8024342: PPC64 (part 111): Support for C calling conventions that require 64-bit ints.
goetz
parents:
19283
diff
changeset
|
3718 |
call->init_req(TypeFunc::I_O, C->top()); // Does no I/O. |
3e2df6a4a28c
8024342: PPC64 (part 111): Support for C calling conventions that require 64-bit ints.
goetz
parents:
19283
diff
changeset
|
3719 |
call->init_req(TypeFunc::Memory, mem_phi->in(LoopNode::EntryControl)); |
48595
5d699d81c10c
8194988: 8 Null pointer dereference defect groups related to MultiNode::proj_out()
dlong
parents:
48145
diff
changeset
|
3720 |
call->init_req(TypeFunc::ReturnAdr, C->start()->proj_out_or_null(TypeFunc::ReturnAdr)); |
5d699d81c10c
8194988: 8 Null pointer dereference defect groups related to MultiNode::proj_out()
dlong
parents:
48145
diff
changeset
|
3721 |
call->init_req(TypeFunc::FramePtr, C->start()->proj_out_or_null(TypeFunc::FramePtr)); |
6433 | 3722 |
_igvn.register_new_node_with_optimizer(call); |
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
3723 |
result_ctrl = new ProjNode(call,TypeFunc::Control); |
6433 | 3724 |
_igvn.register_new_node_with_optimizer(result_ctrl); |
24923
9631f7d691dc
8034812: remove IDX_INIT macro hack in Node class
thartmann
parents:
24020
diff
changeset
|
3725 |
result_mem = new ProjNode(call,TypeFunc::Memory); |
6433 | 3726 |
_igvn.register_new_node_with_optimizer(result_mem); |
3727 |
||
14144 | 3728 |
/* Disable following optimization until proper fix (add missing checks). |
3729 |
||
6433 | 3730 |
// If this fill is tightly coupled to an allocation and overwrites |
3731 |
// the whole body, allow it to take over the zeroing. |
|
3732 |
AllocateNode* alloc = AllocateNode::Ideal_allocation(base, this); |
|
3733 |
if (alloc != NULL && alloc->is_AllocateArray()) { |
|
3734 |
Node* length = alloc->as_AllocateArray()->Ideal_length(); |
|
3735 |
if (head->limit() == length && |
|
3736 |
head->init_trip() == _igvn.intcon(0)) { |
|
3737 |
if (TraceOptimizeFill) { |
|
3738 |
tty->print_cr("Eliminated zeroing in allocation"); |
|
3739 |
} |
|
3740 |
alloc->maybe_set_complete(&_igvn); |
|
3741 |
} else { |
|
3742 |
#ifdef ASSERT |
|
3743 |
if (TraceOptimizeFill) { |
|
3744 |
tty->print_cr("filling array but bounds don't match"); |
|
3745 |
alloc->dump(); |
|
3746 |
head->init_trip()->dump(); |
|
3747 |
head->limit()->dump(); |
|
3748 |
length->dump(); |
|
3749 |
} |
|
3750 |
#endif |
|
3751 |
} |
|
3752 |
} |
|
14144 | 3753 |
*/ |
6433 | 3754 |
|
48145 | 3755 |
if (head->is_strip_mined()) { |
3756 |
// Inner strip mined loop goes away so get rid of outer strip |
|
3757 |
// mined loop |
|
3758 |
Node* outer_sfpt = head->outer_safepoint(); |
|
3759 |
Node* in = outer_sfpt->in(0); |
|
3760 |
Node* outer_out = head->outer_loop_exit(); |
|
3761 |
lazy_replace(outer_out, in); |
|
3762 |
_igvn.replace_input_of(outer_sfpt, 0, C->top()); |
|
3763 |
} |
|
3764 |
||
6433 | 3765 |
// Redirect the old control and memory edges that are outside the loop. |
6739
750998abc20f
6984979: OptimizeFill misses some cases with an odd memory graph
never
parents:
6455
diff
changeset
|
3766 |
// Sometimes the memory phi of the head is used as the outgoing |
750998abc20f
6984979: OptimizeFill misses some cases with an odd memory graph
never
parents:
6455
diff
changeset
|
3767 |
// state of the loop. It's safe in this case to replace it with the |
750998abc20f
6984979: OptimizeFill misses some cases with an odd memory graph
never
parents:
6455
diff
changeset
|
3768 |
// result_mem. |
750998abc20f
6984979: OptimizeFill misses some cases with an odd memory graph
never
parents:
6455
diff
changeset
|
3769 |
_igvn.replace_node(store->in(MemNode::Memory), result_mem); |
35759 | 3770 |
lazy_replace(exit, result_ctrl); |
6433 | 3771 |
_igvn.replace_node(store, result_mem); |
3772 |
// Any uses the increment outside of the loop become the loop limit. |
|
3773 |
_igvn.replace_node(head->incr(), head->limit()); |
|
3774 |
||
3775 |
// Disconnect the head from the loop. |
|
3776 |
for (uint i = 0; i < lpt->_body.size(); i++) { |
|
3777 |
Node* n = lpt->_body.at(i); |
|
3778 |
_igvn.replace_node(n, C->top()); |
|
3779 |
} |
|
3780 |
||
3781 |
return true; |
|
3782 |
} |