changeset 56054:6b77693eda6a

8223140: Clean-up in 'ok_to_convert()'. Summary: Simplify logic in function. Added precond/postcond macros. Reviewed-by: vlivanov, neliasso
author phedlin
date Wed, 17 Apr 2019 14:55:11 +0200
parents d6f55ea4e325
children 45b84dd85b9e
files src/hotspot/share/opto/loopnode.cpp src/hotspot/share/opto/node.hpp src/hotspot/share/opto/subnode.cpp src/hotspot/share/utilities/debug.hpp
diffstat 4 files changed, 42 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/opto/loopnode.cpp	Wed Apr 17 14:55:01 2019 +0200
+++ b/src/hotspot/share/opto/loopnode.cpp	Wed Apr 17 14:55:11 2019 +0200
@@ -42,17 +42,13 @@
 #include "opto/superword.hpp"
 
 //=============================================================================
-//------------------------------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);
 }
 
 //=============================================================================
--- a/src/hotspot/share/opto/node.hpp	Wed Apr 17 14:55:01 2019 +0200
+++ b/src/hotspot/share/opto/node.hpp	Wed Apr 17 14:55:11 2019 +0200
@@ -1007,9 +1007,9 @@
   // 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;
--- a/src/hotspot/share/opto/subnode.cpp	Wed Apr 17 14:55:01 2019 +0200
+++ b/src/hotspot/share/opto/subnode.cpp	Wed Apr 17 14:55:11 2019 +0200
@@ -114,31 +114,37 @@
 }
 
 //=============================================================================
+//------------------------------Helper function--------------------------------
 
-//------------------------------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);
--- a/src/hotspot/share/utilities/debug.hpp	Wed Apr 17 14:55:01 2019 +0200
+++ b/src/hotspot/share/utilities/debug.hpp	Wed Apr 17 14:55:11 2019 +0200
@@ -63,6 +63,9 @@
 // For backward compatibility.
 #define assert(p, ...) vmassert(p, __VA_ARGS__)
 
+#define precond(p)   assert(p, "precond")
+#define postcond(p)  assert(p, "postcond")
+
 #ifndef ASSERT
 #define vmassert_status(p, status, msg)
 #else