Skip to content

Commit 3a88fd4

Browse files
committed
8334724: C2: remove PhaseIdealLoop::cast_incr_before_loop()
Reviewed-by: chagedorn, kvn
1 parent 62dad3a commit 3a88fd4

File tree

3 files changed

+32
-33
lines changed

3 files changed

+32
-33
lines changed

src/hotspot/share/opto/loopTransform.cpp

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,19 +1309,6 @@ Node *PhaseIdealLoop::clone_up_backedge_goo(Node *back_ctrl, Node *preheader_ctr
13091309
return n;
13101310
}
13111311

1312-
Node* PhaseIdealLoop::cast_incr_before_loop(Node* incr, Node* ctrl, Node* loop) {
1313-
Node* castii = new CastIINode(ctrl, incr, TypeInt::INT, ConstraintCastNode::UnconditionalDependency);
1314-
register_new_node(castii, ctrl);
1315-
for (DUIterator_Fast imax, i = incr->fast_outs(imax); i < imax; i++) {
1316-
Node* n = incr->fast_out(i);
1317-
if (n->is_Phi() && n->in(0) == loop) {
1318-
int nrep = n->replace_edge(incr, castii, &_igvn);
1319-
return castii;
1320-
}
1321-
}
1322-
return nullptr;
1323-
}
1324-
13251312
#ifdef ASSERT
13261313
void PhaseIdealLoop::ensure_zero_trip_guard_proj(Node* node, bool is_main_loop) {
13271314
assert(node->is_IfProj(), "must be the zero trip guard If node");
@@ -1680,14 +1667,11 @@ void PhaseIdealLoop::insert_pre_post_loops(IdealLoopTree *loop, Node_List &old_n
16801667
// variable value and the induction variable Phi to preserve correct
16811668
// dependencies.
16821669

1683-
// CastII for the main loop:
1684-
Node* castii = cast_incr_before_loop(pre_incr, min_taken, main_head);
1685-
assert(castii != nullptr, "no castII inserted");
16861670
assert(post_head->in(1)->is_IfProj(), "must be zero-trip guard If node projection of the post loop");
1687-
copy_assertion_predicates_to_main_loop(pre_head, castii, stride, outer_loop, outer_main_head, dd_main_head,
1671+
copy_assertion_predicates_to_main_loop(pre_head, pre_incr, stride, outer_loop, outer_main_head, dd_main_head,
16881672
idx_before_pre_post, idx_after_post_before_pre, min_taken, post_head->in(1),
16891673
old_new);
1690-
copy_assertion_predicates_to_post_loop(outer_main_head, post_head, post_incr, stride);
1674+
copy_assertion_predicates_to_post_loop(outer_main_head, post_head, stride);
16911675

16921676
// Step B4: Shorten the pre-loop to run only 1 iteration (for now).
16931677
// RCE and alignment may change this later.
@@ -1812,7 +1796,7 @@ void PhaseIdealLoop::insert_vector_post_loop(IdealLoopTree *loop, Node_List &old
18121796
// In this case we throw away the result as we are not using it to connect anything else.
18131797
CountedLoopNode *post_head = nullptr;
18141798
insert_post_loop(loop, old_new, main_head, main_end, incr, limit, post_head);
1815-
copy_assertion_predicates_to_post_loop(main_head->skip_strip_mined(), post_head, incr, main_head->stride());
1799+
copy_assertion_predicates_to_post_loop(main_head->skip_strip_mined(), post_head, main_head->stride());
18161800

18171801
// It's difficult to be precise about the trip-counts
18181802
// for post loops. They are usually very short,
@@ -1915,10 +1899,6 @@ Node *PhaseIdealLoop::insert_post_loop(IdealLoopTree* loop, Node_List& old_new,
19151899
}
19161900
}
19171901

1918-
// CastII for the new post loop:
1919-
incr = cast_incr_before_loop(zer_opaq->in(1), zer_taken, post_head);
1920-
assert(incr != nullptr, "no castII inserted");
1921-
19221902
return new_main_exit;
19231903
}
19241904

@@ -1934,12 +1914,6 @@ bool IdealLoopTree::is_invariant(Node* n) const {
19341914
// to the new stride.
19351915
void PhaseIdealLoop::update_main_loop_assertion_predicates(Node* ctrl, CountedLoopNode* loop_head, Node* init,
19361916
const int stride_con) {
1937-
if (init->is_CastII()) {
1938-
// skip over the cast added by PhaseIdealLoop::cast_incr_before_loop() when pre/post/main loops are created because
1939-
// it can get in the way of type propagation
1940-
assert(init->as_CastII()->carry_dependency() && loop_head->skip_assertion_predicates_with_halt() == init->in(0), "casted iv phi from pre loop expected");
1941-
init = init->in(1);
1942-
}
19431917
Node* entry = ctrl;
19441918
Node* prev_proj = ctrl;
19451919
LoopNode* outer_loop_head = loop_head->skip_strip_mined();
@@ -1988,7 +1962,9 @@ void PhaseIdealLoop::update_main_loop_assertion_predicates(Node* ctrl, CountedLo
19881962
// Go over the Assertion Predicates of the main loop and make a copy for the post loop with its initial iv value and
19891963
// stride as inputs.
19901964
void PhaseIdealLoop::copy_assertion_predicates_to_post_loop(LoopNode* main_loop_head, CountedLoopNode* post_loop_head,
1991-
Node* init, Node* stride) {
1965+
Node* stride) {
1966+
Node* opaq = post_loop_head->is_canonical_loop_entry();
1967+
Node* init = opaq->in(1);
19921968
Node* post_loop_entry = post_loop_head->in(LoopNode::EntryControl);
19931969
Node* main_loop_entry = main_loop_head->in(LoopNode::EntryControl);
19941970
IdealLoopTree* post_loop = get_loop(post_loop_head);

src/hotspot/share/opto/loopnode.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -938,8 +938,6 @@ class PhaseIdealLoop : public PhaseTransform {
938938
return ctrl;
939939
}
940940

941-
Node* cast_incr_before_loop(Node* incr, Node* ctrl, Node* loop);
942-
943941
#ifdef ASSERT
944942
void ensure_zero_trip_guard_proj(Node* node, bool is_main_loop);
945943
#endif
@@ -960,7 +958,7 @@ class PhaseIdealLoop : public PhaseTransform {
960958
static bool assertion_predicate_has_loop_opaque_node(IfNode* iff);
961959
static void get_assertion_predicates(Node* predicate, Unique_Node_List& list, bool get_opaque = false);
962960
void update_main_loop_assertion_predicates(Node* ctrl, CountedLoopNode* loop_head, Node* init, int stride_con);
963-
void copy_assertion_predicates_to_post_loop(LoopNode* main_loop_head, CountedLoopNode* post_loop_head, Node* init,
961+
void copy_assertion_predicates_to_post_loop(LoopNode* main_loop_head, CountedLoopNode* post_loop_head,
964962
Node* stride);
965963
void initialize_assertion_predicates_for_peeled_loop(const PredicateBlock* predicate_block, LoopNode* outer_loop_head,
966964
int dd_outer_loop_head, Node* init, Node* stride,
@@ -1534,6 +1532,8 @@ class PhaseIdealLoop : public PhaseTransform {
15341532
// Attempt to use a conditional move instead of a phi/branch
15351533
Node *conditional_move( Node *n );
15361534

1535+
bool split_thru_phi_could_prevent_vectorization(Node* n, Node* n_blk);
1536+
15371537
// Check for aggressive application of 'split-if' optimization,
15381538
// using basic block level info.
15391539
void split_if_with_blocks ( VectorSet &visited, Node_Stack &nstack);

src/hotspot/share/opto/loopopts.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,25 @@ void PhaseIdealLoop::try_move_store_after_loop(Node* n) {
10891089
}
10901090
}
10911091

1092+
// Split some nodes that take a counted loop phi as input at a counted
1093+
// loop can cause vectorization of some expressions to fail
1094+
bool PhaseIdealLoop::split_thru_phi_could_prevent_vectorization(Node* n, Node* n_blk) {
1095+
if (!n_blk->is_CountedLoop()) {
1096+
return false;
1097+
}
1098+
1099+
int opcode = n->Opcode();
1100+
1101+
if (opcode != Op_AndI &&
1102+
opcode != Op_MulI &&
1103+
opcode != Op_RotateRight &&
1104+
opcode != Op_RShiftI) {
1105+
return false;
1106+
}
1107+
1108+
return n->in(1) == n_blk->as_BaseCountedLoop()->phi();
1109+
}
1110+
10921111
//------------------------------split_if_with_blocks_pre-----------------------
10931112
// Do the real work in a non-recursive function. Data nodes want to be
10941113
// cloned in the pre-order so they can feed each other nicely.
@@ -1175,6 +1194,10 @@ Node *PhaseIdealLoop::split_if_with_blocks_pre( Node *n ) {
11751194
return n;
11761195
}
11771196

1197+
if (split_thru_phi_could_prevent_vectorization(n, n_blk)) {
1198+
return n;
1199+
}
1200+
11781201
// Check for having no control input; not pinned. Allow
11791202
// dominating control.
11801203
if (n->in(0)) {

0 commit comments

Comments
 (0)