Skip to content

Commit 9862f8f

Browse files
committed
8373513: C2: Move ProjNode::other_if_proj() to IfProjNode
Reviewed-by: epeter, roland
1 parent 39306d7 commit 9862f8f

File tree

8 files changed

+49
-51
lines changed

8 files changed

+49
-51
lines changed

src/hotspot/share/opto/cfgnode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,8 +933,8 @@ bool RegionNode::optimize_trichotomy(PhaseIterGVN* igvn) {
933933
}
934934
// At this point we know that region->in(idx1) and region->(idx2) map to the same
935935
// value and control flow. Now search for ifs that feed into these region inputs.
936-
ProjNode* proj1 = region->in(idx1)->isa_Proj();
937-
ProjNode* proj2 = region->in(idx2)->isa_Proj();
936+
IfProjNode* proj1 = region->in(idx1)->isa_IfProj();
937+
IfProjNode* proj2 = region->in(idx2)->isa_IfProj();
938938
if (proj1 == nullptr || proj1->outcnt() != 1 ||
939939
proj2 == nullptr || proj2->outcnt() != 1) {
940940
return false; // No projection inputs with region as unique user found

src/hotspot/share/opto/cfgnode.hpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -342,15 +342,15 @@ class IfNode : public MultiBranchNode {
342342
// Helper methods for fold_compares
343343
bool cmpi_folds(PhaseIterGVN* igvn, bool fold_ne = false);
344344
bool is_ctrl_folds(Node* ctrl, PhaseIterGVN* igvn);
345-
bool has_shared_region(ProjNode* proj, ProjNode*& success, ProjNode*& fail);
346-
bool has_only_uncommon_traps(ProjNode* proj, ProjNode*& success, ProjNode*& fail, PhaseIterGVN* igvn);
347-
Node* merge_uncommon_traps(ProjNode* proj, ProjNode* success, ProjNode* fail, PhaseIterGVN* igvn);
345+
bool has_shared_region(IfProjNode* proj, IfProjNode*& success, IfProjNode*& fail) const;
346+
bool has_only_uncommon_traps(IfProjNode* proj, IfProjNode*& success, IfProjNode*& fail, PhaseIterGVN* igvn) const;
347+
Node* merge_uncommon_traps(IfProjNode* proj, IfProjNode* success, IfProjNode* fail, PhaseIterGVN* igvn);
348348
static void improve_address_types(Node* l, Node* r, ProjNode* fail, PhaseIterGVN* igvn);
349-
bool is_cmp_with_loadrange(ProjNode* proj);
350-
bool is_null_check(ProjNode* proj, PhaseIterGVN* igvn);
351-
bool is_side_effect_free_test(ProjNode* proj, PhaseIterGVN* igvn);
352-
void reroute_side_effect_free_unc(ProjNode* proj, ProjNode* dom_proj, PhaseIterGVN* igvn);
353-
bool fold_compares_helper(ProjNode* proj, ProjNode* success, ProjNode* fail, PhaseIterGVN* igvn);
349+
bool is_cmp_with_loadrange(IfProjNode* proj) const;
350+
bool is_null_check(IfProjNode* proj, PhaseIterGVN* igvn) const;
351+
bool is_side_effect_free_test(IfProjNode* proj, PhaseIterGVN* igvn) const;
352+
static void reroute_side_effect_free_unc(IfProjNode* proj, IfProjNode* dom_proj, PhaseIterGVN* igvn);
353+
bool fold_compares_helper(IfProjNode* proj, IfProjNode* success, IfProjNode* fail, PhaseIterGVN* igvn);
354354
static bool is_dominator_unc(CallStaticJavaNode* dom_unc, CallStaticJavaNode* unc);
355355

356356
protected:
@@ -559,6 +559,11 @@ class IfProjNode : public CProjNode {
559559
IfProjNode(IfNode *ifnode, uint idx) : CProjNode(ifnode,idx) {}
560560
virtual Node* Identity(PhaseGVN* phase);
561561

562+
// Return the other IfProj node.
563+
IfProjNode* other_if_proj() const {
564+
return in(0)->as_If()->proj_out(1 - _con)->as_IfProj();
565+
}
566+
562567
void pin_array_access_nodes(PhaseIterGVN* igvn);
563568

564569
protected:

src/hotspot/share/opto/ifnode.cpp

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ bool IfNode::cmpi_folds(PhaseIterGVN* igvn, bool fold_ne) {
771771
// Is a dominating control suitable for folding with this if?
772772
bool IfNode::is_ctrl_folds(Node* ctrl, PhaseIterGVN* igvn) {
773773
return ctrl != nullptr &&
774-
ctrl->is_Proj() &&
774+
ctrl->is_IfProj() &&
775775
ctrl->outcnt() == 1 && // No side-effects
776776
ctrl->in(0) != nullptr &&
777777
ctrl->in(0)->Opcode() == Op_If &&
@@ -784,22 +784,23 @@ bool IfNode::is_ctrl_folds(Node* ctrl, PhaseIterGVN* igvn) {
784784
}
785785

786786
// Do this If and the dominating If share a region?
787-
bool IfNode::has_shared_region(ProjNode* proj, ProjNode*& success, ProjNode*& fail) {
788-
ProjNode* otherproj = proj->other_if_proj();
787+
bool IfNode::has_shared_region(IfProjNode* proj, IfProjNode*& success, IfProjNode*& fail) const {
788+
IfProjNode* otherproj = proj->other_if_proj();
789789
Node* otherproj_ctrl_use = otherproj->unique_ctrl_out_or_null();
790790
RegionNode* region = (otherproj_ctrl_use != nullptr && otherproj_ctrl_use->is_Region()) ? otherproj_ctrl_use->as_Region() : nullptr;
791791
success = nullptr;
792792
fail = nullptr;
793793

794794
if (otherproj->outcnt() == 1 && region != nullptr && !region->has_phi()) {
795795
for (int i = 0; i < 2; i++) {
796-
ProjNode* proj = proj_out(i);
797-
if (success == nullptr && proj->outcnt() == 1 && proj->unique_out() == region) {
798-
success = proj;
796+
IfProjNode* next_proj = proj_out(i)->as_IfProj();
797+
if (success == nullptr && next_proj->outcnt() == 1 && next_proj->unique_out() == region) {
798+
success = next_proj;
799799
} else if (fail == nullptr) {
800-
fail = proj;
800+
fail = next_proj;
801801
} else {
802-
success = fail = nullptr;
802+
success = nullptr;
803+
fail = nullptr;
803804
}
804805
}
805806
}
@@ -850,8 +851,8 @@ ProjNode* IfNode::uncommon_trap_proj(CallStaticJavaNode*& call, Deoptimization::
850851
}
851852

852853
// Do this If and the dominating If both branch out to an uncommon trap
853-
bool IfNode::has_only_uncommon_traps(ProjNode* proj, ProjNode*& success, ProjNode*& fail, PhaseIterGVN* igvn) {
854-
ProjNode* otherproj = proj->other_if_proj();
854+
bool IfNode::has_only_uncommon_traps(IfProjNode* proj, IfProjNode*& success, IfProjNode*& fail, PhaseIterGVN* igvn) const {
855+
IfProjNode* otherproj = proj->other_if_proj();
855856
CallStaticJavaNode* dom_unc = otherproj->is_uncommon_trap_proj();
856857

857858
if (otherproj->outcnt() == 1 && dom_unc != nullptr) {
@@ -888,8 +889,8 @@ bool IfNode::has_only_uncommon_traps(ProjNode* proj, ProjNode*& success, ProjNod
888889
!igvn->C->too_many_traps(dom_method, dom_bci, Deoptimization::Reason_range_check) &&
889890
// Return true if c2 manages to reconcile with UnstableIf optimization. See the comments for it.
890891
igvn->C->remove_unstable_if_trap(dom_unc, true/*yield*/)) {
891-
success = unc_proj;
892-
fail = unc_proj->other_if_proj();
892+
success = unc_proj->as_IfProj();
893+
fail = unc_proj->as_IfProj()->other_if_proj();
893894
return true;
894895
}
895896
}
@@ -898,15 +899,15 @@ bool IfNode::has_only_uncommon_traps(ProjNode* proj, ProjNode*& success, ProjNod
898899
}
899900

900901
// Check that the 2 CmpI can be folded into as single CmpU and proceed with the folding
901-
bool IfNode::fold_compares_helper(ProjNode* proj, ProjNode* success, ProjNode* fail, PhaseIterGVN* igvn) {
902+
bool IfNode::fold_compares_helper(IfProjNode* proj, IfProjNode* success, IfProjNode* fail, PhaseIterGVN* igvn) {
902903
Node* this_cmp = in(1)->in(1);
903904
BoolNode* this_bool = in(1)->as_Bool();
904905
IfNode* dom_iff = proj->in(0)->as_If();
905906
BoolNode* dom_bool = dom_iff->in(1)->as_Bool();
906907
Node* lo = dom_iff->in(1)->in(1)->in(2);
907908
Node* hi = this_cmp->in(2);
908909
Node* n = this_cmp->in(1);
909-
ProjNode* otherproj = proj->other_if_proj();
910+
IfProjNode* otherproj = proj->other_if_proj();
910911

911912
const TypeInt* lo_type = IfNode::filtered_int_type(igvn, n, otherproj);
912913
const TypeInt* hi_type = IfNode::filtered_int_type(igvn, n, success);
@@ -1108,11 +1109,11 @@ bool IfNode::fold_compares_helper(ProjNode* proj, ProjNode* success, ProjNode* f
11081109
// Merge the branches that trap for this If and the dominating If into
11091110
// a single region that branches to the uncommon trap for the
11101111
// dominating If
1111-
Node* IfNode::merge_uncommon_traps(ProjNode* proj, ProjNode* success, ProjNode* fail, PhaseIterGVN* igvn) {
1112+
Node* IfNode::merge_uncommon_traps(IfProjNode* proj, IfProjNode* success, IfProjNode* fail, PhaseIterGVN* igvn) {
11121113
Node* res = this;
11131114
assert(success->in(0) == this, "bad projection");
11141115

1115-
ProjNode* otherproj = proj->other_if_proj();
1116+
IfProjNode* otherproj = proj->other_if_proj();
11161117

11171118
CallStaticJavaNode* unc = success->is_uncommon_trap_proj();
11181119
CallStaticJavaNode* dom_unc = otherproj->is_uncommon_trap_proj();
@@ -1239,7 +1240,7 @@ void IfNode::improve_address_types(Node* l, Node* r, ProjNode* fail, PhaseIterGV
12391240
#endif
12401241
}
12411242

1242-
bool IfNode::is_cmp_with_loadrange(ProjNode* proj) {
1243+
bool IfNode::is_cmp_with_loadrange(IfProjNode* proj) const {
12431244
if (in(1) != nullptr &&
12441245
in(1)->in(1) != nullptr &&
12451246
in(1)->in(1)->in(2) != nullptr) {
@@ -1258,7 +1259,7 @@ bool IfNode::is_cmp_with_loadrange(ProjNode* proj) {
12581259
return false;
12591260
}
12601261

1261-
bool IfNode::is_null_check(ProjNode* proj, PhaseIterGVN* igvn) {
1262+
bool IfNode::is_null_check(IfProjNode* proj, PhaseIterGVN* igvn) const {
12621263
Node* other = in(1)->in(1)->in(2);
12631264
if (other->in(MemNode::Address) != nullptr &&
12641265
proj->in(0)->in(1) != nullptr &&
@@ -1275,7 +1276,7 @@ bool IfNode::is_null_check(ProjNode* proj, PhaseIterGVN* igvn) {
12751276

12761277
// Check that the If that is in between the 2 integer comparisons has
12771278
// no side effect
1278-
bool IfNode::is_side_effect_free_test(ProjNode* proj, PhaseIterGVN* igvn) {
1279+
bool IfNode::is_side_effect_free_test(IfProjNode* proj, PhaseIterGVN* igvn) const {
12791280
if (proj == nullptr) {
12801281
return false;
12811282
}
@@ -1315,9 +1316,9 @@ bool IfNode::is_side_effect_free_test(ProjNode* proj, PhaseIterGVN* igvn) {
13151316
// won't be guarded by the first CmpI anymore. It can trap in cases
13161317
// where the first CmpI would have prevented it from executing: on a
13171318
// trap, we need to restart execution at the state of the first CmpI
1318-
void IfNode::reroute_side_effect_free_unc(ProjNode* proj, ProjNode* dom_proj, PhaseIterGVN* igvn) {
1319+
void IfNode::reroute_side_effect_free_unc(IfProjNode* proj, IfProjNode* dom_proj, PhaseIterGVN* igvn) {
13191320
CallStaticJavaNode* dom_unc = dom_proj->is_uncommon_trap_if_pattern();
1320-
ProjNode* otherproj = proj->other_if_proj();
1321+
IfProjNode* otherproj = proj->other_if_proj();
13211322
CallStaticJavaNode* unc = proj->is_uncommon_trap_if_pattern();
13221323
Node* call_proj = dom_unc->unique_ctrl_out();
13231324
Node* halt = call_proj->unique_ctrl_out();
@@ -1348,9 +1349,9 @@ Node* IfNode::fold_compares(PhaseIterGVN* igvn) {
13481349
if (is_ctrl_folds(ctrl, igvn)) {
13491350
// A integer comparison immediately dominated by another integer
13501351
// comparison
1351-
ProjNode* success = nullptr;
1352-
ProjNode* fail = nullptr;
1353-
ProjNode* dom_cmp = ctrl->as_Proj();
1352+
IfProjNode* success = nullptr;
1353+
IfProjNode* fail = nullptr;
1354+
IfProjNode* dom_cmp = ctrl->as_IfProj();
13541355
if (has_shared_region(dom_cmp, success, fail) &&
13551356
// Next call modifies graph so must be last
13561357
fold_compares_helper(dom_cmp, success, fail, igvn)) {
@@ -1364,11 +1365,11 @@ Node* IfNode::fold_compares(PhaseIterGVN* igvn) {
13641365
return nullptr;
13651366
} else if (ctrl->in(0) != nullptr &&
13661367
ctrl->in(0)->in(0) != nullptr) {
1367-
ProjNode* success = nullptr;
1368-
ProjNode* fail = nullptr;
1368+
IfProjNode* success = nullptr;
1369+
IfProjNode* fail = nullptr;
13691370
Node* dom = ctrl->in(0)->in(0);
1370-
ProjNode* dom_cmp = dom->isa_Proj();
1371-
ProjNode* other_cmp = ctrl->isa_Proj();
1371+
IfProjNode* dom_cmp = dom->isa_IfProj();
1372+
IfProjNode* other_cmp = ctrl->isa_IfProj();
13721373

13731374
// Check if it's an integer comparison dominated by another
13741375
// integer comparison with another test in between

src/hotspot/share/opto/library_call.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6171,7 +6171,7 @@ LibraryCallKit::tightly_coupled_allocation(Node* ptr) {
61716171

61726172
CallStaticJavaNode* LibraryCallKit::get_uncommon_trap_from_success_proj(Node* node) {
61736173
if (node->is_IfProj()) {
6174-
Node* other_proj = node->as_IfProj()->other_if_proj();
6174+
IfProjNode* other_proj = node->as_IfProj()->other_if_proj();
61756175
for (DUIterator_Fast jmax, j = other_proj->fast_outs(jmax); j < jmax; j++) {
61766176
Node* obs = other_proj->fast_out(j);
61776177
if (obs->in(0) == other_proj && obs->is_CallStaticJava() &&

src/hotspot/share/opto/memnode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3103,7 +3103,7 @@ MergePrimitiveStores::CFGStatus MergePrimitiveStores::cfg_status_for_pair(const
31033103
ctrl_use->in(0)->outcnt() != 2) {
31043104
return CFGStatus::Failure; // Not RangeCheck.
31053105
}
3106-
ProjNode* other_proj = ctrl_use->as_IfProj()->other_if_proj();
3106+
IfProjNode* other_proj = ctrl_use->as_IfProj()->other_if_proj();
31073107
Node* trap = other_proj->is_uncommon_trap_proj(Deoptimization::Reason_range_check);
31083108
if (trap != merge_mem->unique_out() ||
31093109
ctrl_use->in(0)->in(0) != ctrl_def) {

src/hotspot/share/opto/multnode.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,7 @@ CallStaticJavaNode* ProjNode::is_uncommon_trap_if_pattern(Deoptimization::DeoptR
260260
// Not a projection of an If or variation of a dead If node.
261261
return nullptr;
262262
}
263-
return other_if_proj()->is_uncommon_trap_proj(reason);
264-
}
265-
266-
ProjNode* ProjNode::other_if_proj() const {
267-
assert(_con == 0 || _con == 1, "not an if?");
268-
return in(0)->as_If()->proj_out(1-_con);
263+
return as_IfProj()->other_if_proj()->is_uncommon_trap_proj(reason);
269264
}
270265

271266
NarrowMemProjNode::NarrowMemProjNode(InitializeNode* src, const TypePtr* adr_type)

src/hotspot/share/opto/multnode.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,6 @@ class ProjNode : public Node {
200200
// other_proj->[region->..]call_uct"
201201
// null otherwise
202202
CallStaticJavaNode* is_uncommon_trap_if_pattern(Deoptimization::DeoptReason reason = Deoptimization::Reason_none) const;
203-
204-
// Return other proj node when this is a If proj node
205-
ProjNode* other_if_proj() const;
206203
};
207204

208205
// A ProjNode variant that captures an adr_type(). Used as a projection of InitializeNode to have the right adr_type()

src/hotspot/share/opto/predicates.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ bool AssertionPredicate::has_assertion_predicate_opaque(const Node* predicate_pr
6565

6666
// Check if the other projection (UCT projection) of `success_proj` has a Halt node as output.
6767
bool AssertionPredicate::has_halt(const IfTrueNode* success_proj) {
68-
ProjNode* other_proj = success_proj->other_if_proj();
68+
IfProjNode* other_proj = success_proj->other_if_proj();
6969
return other_proj->outcnt() == 1 && other_proj->unique_out()->Opcode() == Op_Halt;
7070
}
7171

@@ -396,7 +396,7 @@ bool InitializedAssertionPredicate::is_predicate(const Node* maybe_success_proj)
396396

397397
#ifdef ASSERT
398398
bool InitializedAssertionPredicate::has_halt(const IfTrueNode* success_proj) {
399-
ProjNode* other_proj = success_proj->other_if_proj();
399+
IfProjNode* other_proj = success_proj->other_if_proj();
400400
if (other_proj->outcnt() != 1) {
401401
return false;
402402
}

0 commit comments

Comments
 (0)