Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.

Commit e4a32be

Browse files
committed
8251925: C2: RenaissanceStressTest fails with assert(!had_error): bad dominance
Reviewed-by: kvn, thartmann
1 parent 1f32c11 commit e4a32be

File tree

2 files changed

+95
-51
lines changed

2 files changed

+95
-51
lines changed

src/hotspot/share/opto/superword.cpp

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ SuperWord::SuperWord(PhaseIdealLoop* phase) :
6969
_nlist(arena(), 8, 0, NULL), // scratch list of nodes
7070
_stk(arena(), 8, 0, NULL), // scratch stack of nodes
7171
_lpt(NULL), // loop tree node
72-
_lp(NULL), // LoopNode
72+
_lp(NULL), // CountedLoopNode
73+
_pre_loop_end(NULL), // Pre loop CountedLoopEndNode
7374
_bb(NULL), // basic block
7475
_iv(NULL), // induction var
7576
_race_possible(false), // cases where SDMU is true
@@ -155,10 +156,15 @@ void SuperWord::transform_loop(IdealLoopTree* lpt, bool do_optimization) {
155156

156157
if (cl->is_main_loop()) {
157158
// Check for pre-loop ending with CountedLoopEnd(Bool(Cmp(x,Opaque1(limit))))
158-
CountedLoopEndNode* pre_end = get_pre_loop_end(cl);
159-
if (pre_end == NULL) return;
160-
Node *pre_opaq1 = pre_end->limit();
161-
if (pre_opaq1->Opcode() != Op_Opaque1) return;
159+
CountedLoopEndNode* pre_end = find_pre_loop_end(cl);
160+
if (pre_end == NULL) {
161+
return;
162+
}
163+
Node* pre_opaq1 = pre_end->limit();
164+
if (pre_opaq1->Opcode() != Op_Opaque1) {
165+
return;
166+
}
167+
set_pre_loop_end(pre_end);
162168
}
163169

164170
init(); // initialize data structures
@@ -911,8 +917,7 @@ bool SuperWord::ref_is_alignable(SWPointer& p) {
911917
if (!p.has_iv()) {
912918
return true; // no induction variable
913919
}
914-
CountedLoopEndNode* pre_end = get_pre_loop_end(lp()->as_CountedLoop());
915-
assert(pre_end != NULL, "we must have a correct pre-loop");
920+
CountedLoopEndNode* pre_end = pre_loop_end();
916921
assert(pre_end->stride_is_con(), "pre loop stride is constant");
917922
int preloop_stride = pre_end->stride_con();
918923

@@ -3431,21 +3436,19 @@ LoadNode::ControlDependency SuperWord::control_dependency(Node_List* p) {
34313436
// to align_to_ref will be a position zero in the vector.
34323437
// (iv + k) mod vector_align == 0
34333438
void SuperWord::align_initial_loop_index(MemNode* align_to_ref) {
3434-
CountedLoopNode *main_head = lp()->as_CountedLoop();
3435-
assert(main_head->is_main_loop(), "");
3436-
CountedLoopEndNode* pre_end = get_pre_loop_end(main_head);
3437-
assert(pre_end != NULL, "we must have a correct pre-loop");
3438-
Node *pre_opaq1 = pre_end->limit();
3439+
assert(lp()->is_main_loop(), "");
3440+
CountedLoopEndNode* pre_end = pre_loop_end();
3441+
Node* pre_opaq1 = pre_end->limit();
34393442
assert(pre_opaq1->Opcode() == Op_Opaque1, "");
3440-
Opaque1Node *pre_opaq = (Opaque1Node*)pre_opaq1;
3441-
Node *lim0 = pre_opaq->in(1);
3443+
Opaque1Node* pre_opaq = (Opaque1Node*)pre_opaq1;
3444+
Node* lim0 = pre_opaq->in(1);
34423445

34433446
// Where we put new limit calculations
3444-
Node *pre_ctrl = pre_end->loopnode()->in(LoopNode::EntryControl);
3447+
Node* pre_ctrl = pre_loop_head()->in(LoopNode::EntryControl);
34453448

34463449
// Ensure the original loop limit is available from the
34473450
// pre-loop Opaque1 node.
3448-
Node *orig_limit = pre_opaq->original_loop_limit();
3451+
Node* orig_limit = pre_opaq->original_loop_limit();
34493452
assert(orig_limit != NULL && _igvn.type(orig_limit) != Type::TOP, "");
34503453

34513454
SWPointer align_to_ref_p(align_to_ref, this, NULL, false);
@@ -3596,7 +3599,7 @@ void SuperWord::align_initial_loop_index(MemNode* align_to_ref) {
35963599

35973600
//----------------------------get_pre_loop_end---------------------------
35983601
// Find pre loop end from main loop. Returns null if none.
3599-
CountedLoopEndNode* SuperWord::get_pre_loop_end(CountedLoopNode* cl) {
3602+
CountedLoopEndNode* SuperWord::find_pre_loop_end(CountedLoopNode* cl) const {
36003603
// The loop cannot be optimized if the graph shape at
36013604
// the loop entry is inappropriate.
36023605
if (!PhaseIdealLoop::is_canonical_loop_entry(cl)) {
@@ -3724,7 +3727,7 @@ SWPointer::SWPointer(MemNode* mem, SuperWord* slp, Node_Stack *nstack, bool anal
37243727
// Match AddP(base, AddP(ptr, k*iv [+ invariant]), constant)
37253728
Node* base = adr->in(AddPNode::Base);
37263729
// The base address should be loop invariant
3727-
if (!invariant(base)) {
3730+
if (is_main_loop_member(base)) {
37283731
assert(!valid(), "base address is loop variant");
37293732
return;
37303733
}
@@ -3753,7 +3756,7 @@ SWPointer::SWPointer(MemNode* mem, SuperWord* slp, Node_Stack *nstack, bool anal
37533756
break; // stop looking at addp's
37543757
}
37553758
}
3756-
if (!invariant(adr)) {
3759+
if (is_main_loop_member(adr)) {
37573760
assert(!valid(), "adr is loop variant");
37583761
return;
37593762
}
@@ -3783,12 +3786,23 @@ SWPointer::SWPointer(SWPointer* p) :
37833786
#endif
37843787
{}
37853788

3789+
bool SWPointer::is_main_loop_member(Node* n) const {
3790+
Node* n_c = phase()->get_ctrl(n);
3791+
return lpt()->is_member(phase()->get_loop(n_c));
3792+
}
37863793

3787-
bool SWPointer::invariant(Node* n) {
3794+
bool SWPointer::invariant(Node* n) const {
37883795
NOT_PRODUCT(Tracer::Depth dd;)
3789-
Node *n_c = phase()->get_ctrl(n);
3796+
Node* n_c = phase()->get_ctrl(n);
37903797
NOT_PRODUCT(_tracer.invariant_1(n, n_c);)
3791-
return !lpt()->is_member(phase()->get_loop(n_c));
3798+
bool is_not_member = !is_main_loop_member(n);
3799+
if (is_not_member && _slp->lp()->is_main_loop()) {
3800+
// Check that n_c dominates the pre loop head node. If it does not, then we cannot use n as invariant for the pre loop
3801+
// CountedLoopEndNode check because n_c is either part of the pre loop or between the pre and the main loop (illegal
3802+
// invariant: Happens, for example, when n_c is a CastII node that prevents data nodes to flow above the main loop).
3803+
return phase()->is_dominator(n_c, _slp->pre_loop_head());
3804+
}
3805+
return is_not_member;
37923806
}
37933807

37943808
//------------------------scaled_iv_plus_offset--------------------
@@ -3851,7 +3865,7 @@ bool SWPointer::scaled_iv(Node* n) {
38513865
NOT_PRODUCT(_tracer.scaled_iv_3(n, _scale);)
38523866
return true;
38533867
}
3854-
if (_analyze_only && (invariant(n) == false)) {
3868+
if (_analyze_only && (is_main_loop_member(n))) {
38553869
_nstack->push(n, _stack_idx++);
38563870
}
38573871

@@ -3937,7 +3951,7 @@ bool SWPointer::offset_plus_k(Node* n, bool negate) {
39373951
return false;
39383952
}
39393953

3940-
if (_analyze_only && (invariant(n) == false)) {
3954+
if (_analyze_only && is_main_loop_member(n)) {
39413955
_nstack->push(n, _stack_idx++);
39423956
}
39433957
if (opc == Op_AddI) {
@@ -3970,20 +3984,27 @@ bool SWPointer::offset_plus_k(Node* n, bool negate) {
39703984
return true;
39713985
}
39723986
}
3973-
if (invariant(n)) {
3987+
3988+
if (!is_main_loop_member(n)) {
3989+
// 'n' is loop invariant. Skip range check dependent CastII nodes before checking if 'n' is dominating the pre loop.
39743990
if (opc == Op_ConvI2L) {
39753991
n = n->in(1);
39763992
if (n->Opcode() == Op_CastII &&
39773993
n->as_CastII()->has_range_check()) {
39783994
// Skip range check dependent CastII nodes
3979-
assert(invariant(n), "sanity");
3995+
assert(!is_main_loop_member(n), "sanity");
39803996
n = n->in(1);
39813997
}
3998+
3999+
// Check if 'n' can really be used as invariant (not in main loop and dominating the pre loop).
4000+
if (invariant(n)) {
4001+
_negate_invar = negate;
4002+
_invar = n;
4003+
NOT_PRODUCT(_tracer.offset_plus_k_10(n, _invar, _negate_invar, _offset);)
4004+
return true;
4005+
}
39824006
}
3983-
_negate_invar = negate;
3984-
_invar = n;
3985-
NOT_PRODUCT(_tracer.offset_plus_k_10(n, _invar, _negate_invar, _offset);)
3986-
return true;
4007+
return false;
39874008
}
39884009

39894010
NOT_PRODUCT(_tracer.offset_plus_k_11(n);)
@@ -4004,8 +4025,10 @@ void SWPointer::print() {
40044025

40054026
//----------------------------tracing------------------------
40064027
#ifndef PRODUCT
4007-
void SWPointer::Tracer::print_depth() {
4008-
for (int ii = 0; ii<_depth; ++ii) tty->print(" ");
4028+
void SWPointer::Tracer::print_depth() const {
4029+
for (int ii = 0; ii < _depth; ++ii) {
4030+
tty->print(" ");
4031+
}
40094032
}
40104033

40114034
void SWPointer::Tracer::ctor_1 (Node* mem) {
@@ -4057,7 +4080,7 @@ void SWPointer::Tracer::ctor_6(Node* mem) {
40574080
}
40584081
}
40594082

4060-
void SWPointer::Tracer::invariant_1(Node *n, Node *n_c) {
4083+
void SWPointer::Tracer::invariant_1(Node *n, Node *n_c) const {
40614084
if (_slp->do_vector_loop() && _slp->is_debug() && _slp->_lpt->is_member(_slp->_phase->get_loop(n_c)) != (int)_slp->in_bb(n)) {
40624085
int is_member = _slp->_lpt->is_member(_slp->_phase->get_loop(n_c));
40634086
int in_bb = _slp->in_bb(n);

src/hotspot/share/opto/superword.hpp

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,11 @@ class SuperWord : public ResourceObj {
291291
void unrolling_analysis(int &local_loop_unroll_factor);
292292

293293
// Accessors for SWPointer
294-
PhaseIdealLoop* phase() { return _phase; }
295-
IdealLoopTree* lpt() { return _lpt; }
296-
PhiNode* iv() { return _iv; }
294+
PhaseIdealLoop* phase() const { return _phase; }
295+
IdealLoopTree* lpt() const { return _lpt; }
296+
PhiNode* iv() const { return _iv; }
297297

298-
bool early_return() { return _early_return; }
298+
bool early_return() const { return _early_return; }
299299

300300
#ifndef PRODUCT
301301
bool is_debug() { return _vector_loop_debug > 0; }
@@ -310,7 +310,8 @@ class SuperWord : public ResourceObj {
310310
bool do_reserve_copy() { return _do_reserve_copy; }
311311
private:
312312
IdealLoopTree* _lpt; // Current loop tree node
313-
LoopNode* _lp; // Current LoopNode
313+
CountedLoopNode* _lp; // Current CountedLoopNode
314+
CountedLoopEndNode* _pre_loop_end; // Current CountedLoopEndNode of pre loop
314315
Node* _bb; // Current basic block
315316
PhiNode* _iv; // Induction var
316317
bool _race_possible; // In cases where SDMU is true
@@ -330,14 +331,33 @@ class SuperWord : public ResourceObj {
330331
Arena* arena() { return _arena; }
331332

332333
Node* bb() { return _bb; }
333-
void set_bb(Node* bb) { _bb = bb; }
334-
334+
void set_bb(Node* bb) { _bb = bb; }
335335
void set_lpt(IdealLoopTree* lpt) { _lpt = lpt; }
336+
CountedLoopNode* lp() const { return _lp; }
337+
void set_lp(CountedLoopNode* lp) {
338+
_lp = lp;
339+
_iv = lp->as_CountedLoop()->phi()->as_Phi();
340+
}
341+
int iv_stride() const { return lp()->stride_con(); }
336342

337-
LoopNode* lp() { return _lp; }
338-
void set_lp(LoopNode* lp) { _lp = lp;
339-
_iv = lp->as_CountedLoop()->phi()->as_Phi(); }
340-
int iv_stride() { return lp()->as_CountedLoop()->stride_con(); }
343+
CountedLoopNode* pre_loop_head() const {
344+
assert(_pre_loop_end != NULL && _pre_loop_end->loopnode() != NULL, "should find head from pre loop end");
345+
return _pre_loop_end->loopnode();
346+
}
347+
void set_pre_loop_end(CountedLoopEndNode* pre_loop_end) {
348+
assert(pre_loop_end, "must be valid");
349+
_pre_loop_end = pre_loop_end;
350+
}
351+
CountedLoopEndNode* pre_loop_end() const {
352+
#ifdef ASSERT
353+
assert(_lp != NULL, "sanity");
354+
assert(_pre_loop_end != NULL, "should be set when fetched");
355+
Node* found_pre_end = find_pre_loop_end(_lp);
356+
assert(_pre_loop_end == found_pre_end && _pre_loop_end == pre_loop_head()->loopexit(),
357+
"should find the pre loop end and must be the same result");
358+
#endif
359+
return _pre_loop_end;
360+
}
341361

342362
int vector_width(Node* n) {
343363
BasicType bt = velt_basic_type(n);
@@ -531,7 +551,7 @@ class SuperWord : public ResourceObj {
531551
// to align_to_ref will be a position zero in the vector.
532552
void align_initial_loop_index(MemNode* align_to_ref);
533553
// Find pre loop end from main loop. Returns null if none.
534-
CountedLoopEndNode* get_pre_loop_end(CountedLoopNode *cl);
554+
CountedLoopEndNode* find_pre_loop_end(CountedLoopNode *cl) const;
535555
// Is the use of d1 in u1 at the same operand position as d2 in u2?
536556
bool opnd_positions_match(Node* d1, Node* u1, Node* d2, Node* u2);
537557
void init();
@@ -567,11 +587,12 @@ class SWPointer {
567587
bool _analyze_only; // Used in loop unrolling only for swpointer trace
568588
uint _stack_idx; // Used in loop unrolling only for swpointer trace
569589

570-
PhaseIdealLoop* phase() { return _slp->phase(); }
571-
IdealLoopTree* lpt() { return _slp->lpt(); }
572-
PhiNode* iv() { return _slp->iv(); } // Induction var
590+
PhaseIdealLoop* phase() const { return _slp->phase(); }
591+
IdealLoopTree* lpt() const { return _slp->lpt(); }
592+
PhiNode* iv() const { return _slp->iv(); } // Induction var
573593

574-
bool invariant(Node* n);
594+
bool is_main_loop_member(Node* n) const;
595+
bool invariant(Node* n) const;
575596

576597
// Match: k*iv + offset
577598
bool scaled_iv_plus_offset(Node* n);
@@ -638,7 +659,7 @@ class SWPointer {
638659
SuperWord* _slp;
639660
static int _depth;
640661
int _depth_save;
641-
void print_depth();
662+
void print_depth() const;
642663
int depth() const { return _depth; }
643664
void set_depth(int d) { _depth = d; }
644665
void inc_depth() { _depth++;}
@@ -664,7 +685,7 @@ class SWPointer {
664685
void ctor_5(Node* adr, Node* base, int i);
665686
void ctor_6(Node* mem);
666687

667-
void invariant_1(Node *n, Node *n_c);
688+
void invariant_1(Node *n, Node *n_c) const;
668689

669690
void scaled_iv_plus_offset_1(Node* n);
670691
void scaled_iv_plus_offset_2(Node* n);

0 commit comments

Comments
 (0)