Skip to content

Commit

Permalink
8223140: Clean-up in 'ok_to_convert()'
Browse files Browse the repository at this point in the history
Simplify logic in function. Added precond/postcond macros.

Reviewed-by: shade
Backport-of: f4faee7
  • Loading branch information
GoeLin committed Oct 6, 2021
1 parent 5d6ddbe commit 45d63a8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 37 deletions.
18 changes: 7 additions & 11 deletions src/hotspot/share/opto/loopnode.cpp
Expand Up @@ -46,17 +46,13 @@
#endif

//=============================================================================
//------------------------------is_loop_iv-------------------------------------
// Determine if a node is Counted loop induction variable.
// The method is declared in node.hpp.
const Node* Node::is_loop_iv() const {
if (this->is_Phi() && !this->as_Phi()->is_copy() &&
this->as_Phi()->region()->is_CountedLoop() &&
this->as_Phi()->region()->as_CountedLoop()->phi() == this) {
return this;
} else {
return NULL;
}
//--------------------------is_cloop_ind_var-----------------------------------
// Determine if a node is a counted loop induction variable.
// NOTE: The method is declared in "node.hpp".
bool Node::is_cloop_ind_var() const {
return (is_Phi() && !as_Phi()->is_copy() &&
as_Phi()->region()->is_CountedLoop() &&
as_Phi()->region()->as_CountedLoop()->phi() == this);
}

//=============================================================================
Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/share/opto/node.hpp
Expand Up @@ -1021,9 +1021,9 @@ class Node {
// value, if it appears (by local graph inspection) to be computed by a simple conditional.
bool is_iteratively_computed();

// Determine if a node is Counted loop induction variable.
// The method is defined in loopnode.cpp.
const Node* is_loop_iv() const;
// Determine if a node is a counted loop induction variable.
// NOTE: The method is defined in "loopnode.cpp".
bool is_cloop_ind_var() const;

// Return a node with opcode "opc" and same inputs as "this" if one can
// be found; Otherwise return NULL;
Expand Down
52 changes: 29 additions & 23 deletions src/hotspot/share/opto/subnode.cpp
Expand Up @@ -114,31 +114,37 @@ const Type* SubNode::Value(PhaseGVN* phase) const {
}

//=============================================================================

//------------------------------Helper function--------------------------------
static bool ok_to_convert(Node* inc, Node* iv) {
// Do not collapse (x+c0)-y if "+" is a loop increment, because the
// "-" is loop invariant and collapsing extends the live-range of "x"
// to overlap with the "+", forcing another register to be used in
// the loop.
// This test will be clearer with '&&' (apply DeMorgan's rule)
// but I like the early cutouts that happen here.
const PhiNode *phi;
if( ( !inc->in(1)->is_Phi() ||
!(phi=inc->in(1)->as_Phi()) ||
phi->is_copy() ||
!phi->region()->is_CountedLoop() ||
inc != phi->region()->as_CountedLoop()->incr() )
&&
// Do not collapse (x+c0)-iv if "iv" is a loop induction variable,
// because "x" maybe invariant.
( !iv->is_loop_iv() )
) {
return true;
} else {
return false;
}

static bool is_cloop_increment(Node* inc) {
precond(inc->Opcode() == Op_AddI || inc->Opcode() == Op_AddL);

if (!inc->in(1)->is_Phi()) {
return false;
}
const PhiNode* phi = inc->in(1)->as_Phi();

if (phi->is_copy() || !phi->region()->is_CountedLoop()) {
return false;
}

return inc == phi->region()->as_CountedLoop()->incr();
}

// Given the expression '(x + C) - v', or
// 'v - (x + C)', we examine nodes '+' and 'v':
//
// 1. Do not convert if '+' is a counted-loop increment, because the '-' is
// loop invariant and converting extends the live-range of 'x' to overlap
// with the '+', forcing another register to be used in the loop.
//
// 2. Do not convert if 'v' is a counted-loop induction variable, because
// 'x' might be invariant.
//
static bool ok_to_convert(Node* inc, Node* var) {
return !(is_cloop_increment(inc) || var->is_cloop_ind_var());
}

//------------------------------Ideal------------------------------------------
Node *SubINode::Ideal(PhaseGVN *phase, bool can_reshape){
Node *in1 = in(1);
Expand Down

1 comment on commit 45d63a8

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.