Skip to content

Commit 6cad07c

Browse files
committed
8325746: Refactor Loop Unswitching code
Reviewed-by: epeter, kvn
1 parent 4dd6c44 commit 6cad07c

File tree

6 files changed

+464
-183
lines changed

6 files changed

+464
-183
lines changed

src/hotspot/share/opto/cfgnode.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ class IfNode : public MultiBranchNode {
421421
init_req(0,control);
422422
init_req(1,b);
423423
}
424+
425+
static IfNode* make_with_same_profile(IfNode* if_node_profile, Node* ctrl, BoolNode* bol);
426+
424427
virtual int Opcode() const;
425428
virtual bool pinned() const { return true; }
426429
virtual const Type *bottom_type() const { return TypeTuple::IFBOTH; }

src/hotspot/share/opto/ifnode.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,22 @@ static Node* split_if(IfNode *iff, PhaseIterGVN *igvn) {
454454
return new ConINode(TypeInt::ZERO);
455455
}
456456

457+
IfNode* IfNode::make_with_same_profile(IfNode* if_node_profile, Node* ctrl, BoolNode* bol) {
458+
// Assert here that we only try to create a clone from an If node with the same profiling if that actually makes sense.
459+
// Some If node subtypes should not be cloned in this way. In theory, we should not clone BaseCountedLoopEndNodes.
460+
// But they can end up being used as normal If nodes when peeling a loop - they serve as zero-trip guard.
461+
// Allow them as well.
462+
assert(if_node_profile->Opcode() == Op_If || if_node_profile->is_RangeCheck()
463+
|| if_node_profile->is_BaseCountedLoopEnd(), "should not clone other nodes");
464+
if (if_node_profile->is_RangeCheck()) {
465+
// RangeCheck nodes could be further optimized.
466+
return new RangeCheckNode(ctrl, bol, if_node_profile->_prob, if_node_profile->_fcnt);
467+
} else {
468+
// Not a RangeCheckNode? Fall back to IfNode.
469+
return new IfNode(ctrl, bol, if_node_profile->_prob, if_node_profile->_fcnt);
470+
}
471+
}
472+
457473
// if this IfNode follows a range check pattern return the projection
458474
// for the failed path
459475
ProjNode* IfNode::range_check_trap_proj(int& flip_test, Node*& l, Node*& r) {

0 commit comments

Comments
 (0)