Skip to content

Commit 10ff90d

Browse files
committed
8385137: C2: Uncast arguments to MemNode::all_control_dominate in some cases
Reviewed-by: dlong, kvn
1 parent 93c22db commit 10ff90d

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

src/hotspot/share/opto/memnode.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ bool MemNode::detect_ptr_independence(Node* p1, AllocateNode* a1,
562562
// TypePtr::NULL_PTR, so we exclude that case.
563563
const Type* p1_type = p1->bottom_type();
564564
const Type* p2_type = p2->bottom_type();
565-
if (p1_type->isa_oopptr() && p2_type->isa_oopptr() &&
565+
if (p1_type != p2_type && p1_type->isa_oopptr() && p2_type->isa_oopptr() &&
566566
(!p1_type->maybe_null() || !p2_type->maybe_null()) &&
567567
p1_type->join(p2_type)->empty()) {
568568
return true;
@@ -578,9 +578,9 @@ bool MemNode::detect_ptr_independence(Node* p1, AllocateNode* a1,
578578
return (a1 != a2);
579579
} else if (a1 != nullptr) { // one allocation a1
580580
// (Note: p2->is_Con implies p2->in(0)->is_Root, which dominates.)
581-
return all_controls_dominate(p2, a1, phase);
581+
return all_controls_dominate(p2->uncast(), a1, phase);
582582
} else { //(a2 != null) // one allocation a2
583-
return all_controls_dominate(p1, a2, phase);
583+
return all_controls_dominate(p1->uncast(), a2, phase);
584584
}
585585
return false;
586586
}
@@ -886,14 +886,14 @@ AccessAnalyzer::AccessIndependence AccessAnalyzer::detect_access_independence(No
886886
known_identical = true;
887887
} else if (_alloc != nullptr) {
888888
known_independent = true;
889-
} else if (MemNode::all_controls_dominate(_n, st_alloc, _phase)) {
889+
} else if (MemNode::all_controls_dominate(_base->uncast(), st_alloc, _phase)) {
890890
known_independent = true;
891891
}
892892

893893
if (known_independent) {
894894
// The bases are provably independent: Either they are
895895
// manifestly distinct allocations, or else the control
896-
// of _n dominates the store's allocation.
896+
// of _base dominates the store's allocation.
897897
if (_alias_idx == Compile::AliasIdxRaw) {
898898
other = st_alloc->in(TypeFunc::Memory);
899899
} else {

test/hotspot/jtreg/compiler/c2/gvn/TestFindStore.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public static void main(String[] args) {
5555

5656
@Run(test = {"testLoad", "testStore", "testLoadDependent1", "testLoadDependent2", "testLoadArray",
5757
"testLoadArrayOverlap", "testLoadIndependentAliasClasses", "testLoadMismatched",
58-
"testLoadArrayCopy", "testLoadArrayCopyUnknownLength"})
58+
"testLoadArrayCopy", "testLoadArrayCopyUnknownLength",
59+
"testAllocationIndependence1", "testAllocationIndependence2"})
5960
public void run() {
6061
C1 c1 = new C1();
6162
C2 c2 = new C2();
@@ -81,6 +82,9 @@ public void run() {
8182
Asserts.assertEQ(1, testLoadArrayCopyUnknownLength(a1, a2, 100, 1));
8283
a1[2] = 0;
8384
Asserts.assertEQ(0, testLoadArrayCopyUnknownLength(a1, a2, 2, 1));
85+
86+
Asserts.assertEQ(3, testAllocationIndependence1(c1, 1, 2).v);
87+
Asserts.assertEQ(3, testAllocationIndependence2(c1, 1, 2).v);
8488
}
8589

8690
@Test
@@ -170,4 +174,25 @@ static int testLoadArrayCopyUnknownLength(int[] a1, int[] a2, int len, int v) {
170174
System.arraycopy(a2, 0, a1, 0, len);
171175
return a1[2];
172176
}
177+
178+
@Test
179+
@IR(failOn = IRNode.LOAD, phase = CompilePhase.BEFORE_MACRO_EXPANSION)
180+
static C1 testAllocationIndependence1(C1 o1, int v1, int v2) {
181+
// o1 and o2 are independent
182+
o1.v = v1;
183+
C1 o2 = new C1();
184+
o2.v = o1.v + v2;
185+
return o2;
186+
}
187+
188+
@Test
189+
@IR(failOn = IRNode.LOAD, phase = CompilePhase.BEFORE_MACRO_EXPANSION)
190+
static C1 testAllocationIndependence2(C1 o1, int v1, int v2) {
191+
// o1 and o2 are independent, but we also want CastPP(o1) and o2 being independent
192+
C1 o2 = new C1();
193+
o1.v = v1;
194+
o2.v = v2;
195+
o2.v = o1.v + o2.v;
196+
return o2;
197+
}
173198
}

0 commit comments

Comments
 (0)