diff --git a/src/share/vm/opto/superword.cpp b/src/share/vm/opto/superword.cpp index c8198392c331bab66dc7305da76cd67e77bc1e37..6709d15b9e75946865e8dc3e5ef1765f59339859 100644 --- a/src/share/vm/opto/superword.cpp +++ b/src/share/vm/opto/superword.cpp @@ -990,8 +990,8 @@ void SuperWord::remove_and_insert(MemNode *current, MemNode *prev, MemNode *lip, // (5) We know there is no dependence cycle, so there in no other case; // (6) Finally, all memory ops in another single pack should be moved in the same direction. // -// To schedule a load pack: the memory edge of every loads in the pack must be -// the same as the memory edge of the last executed load in the pack +// To schedule a load pack, we use the memory state of either the first or the last load in +// the pack, based on the dependence constraint. void SuperWord::co_locate_pack(Node_List* pk) { if (pk->at(0)->is_Store()) { MemNode* first = executed_first(pk)->as_Mem(); @@ -1076,15 +1076,32 @@ void SuperWord::co_locate_pack(Node_List* pk) { current = my_mem->as_Mem(); } // end while } else if (pk->at(0)->is_Load()) { //load - // all use the memory state that the last executed load uses - LoadNode* last_load = executed_last(pk)->as_Load(); - Node* last_mem = last_load->in(MemNode::Memory); - _igvn.hash_delete(last_mem); - // Give each load same memory state as last + // all loads in the pack should have the same memory state. By default, + // we use the memory state of the last load. However, if any load could + // not be moved down due to the dependence constraint, we use the memory + // state of the first load. + Node* last_mem = executed_last(pk)->in(MemNode::Memory); + Node* first_mem = executed_first(pk)->in(MemNode::Memory); + bool schedule_last = true; + for (uint i = 0; i < pk->size(); i++) { + Node* ld = pk->at(i); + for (Node* current = last_mem; current != ld->in(MemNode::Memory); + current=current->in(MemNode::Memory)) { + assert(current != first_mem, "corrupted memory graph"); + if(current->is_Mem() && !independent(current, ld)){ + schedule_last = false; // a later store depends on this load + break; + } + } + } + + Node* mem_input = schedule_last ? last_mem : first_mem; + _igvn.hash_delete(mem_input); + // Give each load the same memory state for (uint i = 0; i < pk->size(); i++) { LoadNode* ld = pk->at(i)->as_Load(); _igvn.hash_delete(ld); - ld->set_req(MemNode::Memory, last_mem); + ld->set_req(MemNode::Memory, mem_input); _igvn._worklist.push(ld); } } diff --git a/test/compiler/6636138/Test1.java b/test/compiler/6636138/Test1.java index 8efc9d4f192c9496628f9e20e96f2359b0eeecb1..306db6d106cec2376e3c266a5faa7544946b0fad 100644 --- a/test/compiler/6636138/Test1.java +++ b/test/compiler/6636138/Test1.java @@ -45,7 +45,7 @@ public class Test1 { for (int i = 0; i < src.length; i++) { if (src[i] != ref[i]) { System.out.println("Error: src and ref don't match at " + i); - System.exit(-1); + System.exit(97); } } } diff --git a/test/compiler/6636138/Test2.java b/test/compiler/6636138/Test2.java index 27bc41060c8c5d33bda519fafc0825786bef45a8..b9d9831e6c3d1e62150b2994ec6055a795594a2f 100644 --- a/test/compiler/6636138/Test2.java +++ b/test/compiler/6636138/Test2.java @@ -51,7 +51,7 @@ public class Test2 { int value = (i-1 + src.length)%src.length; // correct value after shifting if (src[i] != value) { System.out.println("Error: src["+i+"] should be "+ value + " instead of " + src[i]); - System.exit(-1); + System.exit(97); } } }