Reviewers: Sven Panne,

Description:
[turbofan] Also update the BranchHint when merging a BooleanNot.

[email protected]

Please review this at https://codereview.chromium.org/1218443002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+25, -0 lines):
  M src/compiler/common-operator.h
  M src/compiler/common-operator-reducer.cc
  M test/unittests/compiler/common-operator-reducer-unittest.cc


Index: src/compiler/common-operator-reducer.cc
diff --git a/src/compiler/common-operator-reducer.cc b/src/compiler/common-operator-reducer.cc index 1ed05f1834bf7b214db79526d8fc5a2f3698c736..24760dc2f596398de81f39aab9d9819d6b263124 100644
--- a/src/compiler/common-operator-reducer.cc
+++ b/src/compiler/common-operator-reducer.cc
@@ -99,6 +99,17 @@ Reduction CommonOperatorReducer::ReduceBranch(Node* node) { // since we tell the graph reducer that the {branch} was changed and the // graph reduction logic will ensure that the uses are revisited properly.
     node->ReplaceInput(0, cond->InputAt(0));
+    // Negative the hint for {branch}.
+    switch (BranchHintOf(node->op())) {
+      case BranchHint::kTrue:
+        node->set_op(common()->Branch(BranchHint::kFalse));
+        break;
+      case BranchHint::kFalse:
+        node->set_op(common()->Branch(BranchHint::kTrue));
+        break;
+      case BranchHint::kNone:
+        break;
+    }
     return Changed(node);
   }
   Decision const decision = DecideCondition(cond);
Index: src/compiler/common-operator.h
diff --git a/src/compiler/common-operator.h b/src/compiler/common-operator.h
index 4d8b1694b1cb35e906f10be59e8cc3761befd3ed..3b89b2cd038431d26ff745c88ab3edeaa8affa68 100644
--- a/src/compiler/common-operator.h
+++ b/src/compiler/common-operator.h
@@ -27,6 +27,19 @@ class Operator;
 // Prediction hint for branches.
 enum class BranchHint : uint8_t { kNone, kTrue, kFalse };

+inline BranchHint NegateBranchHint(BranchHint hint) {
+  switch (hint) {
+    case BranchHint::kNone:
+      return hint;
+    case BranchHint::kTrue:
+      return BranchHint::kFalse;
+    case BranchHint::kFalse:
+      return BranchHint::kTrue;
+  }
+  UNREACHABLE();
+  return hint;
+}
+
inline size_t hash_value(BranchHint hint) { return static_cast<size_t>(hint); }

 std::ostream& operator<<(std::ostream&, BranchHint);
Index: test/unittests/compiler/common-operator-reducer-unittest.cc
diff --git a/test/unittests/compiler/common-operator-reducer-unittest.cc b/test/unittests/compiler/common-operator-reducer-unittest.cc index c33d10700b923f0420ce8556d9f9d890a6350825..13d2d6707a23bfc78ee5a9247791a70156e3716c 100644
--- a/test/unittests/compiler/common-operator-reducer-unittest.cc
+++ b/test/unittests/compiler/common-operator-reducer-unittest.cc
@@ -187,6 +187,7 @@ TEST_F(CommonOperatorReducerTest, BranchWithBooleanNot) {
     EXPECT_THAT(branch, IsBranch(value, control));
     EXPECT_THAT(if_false, IsIfTrue(branch));
     EXPECT_THAT(if_true, IsIfFalse(branch));
+    EXPECT_EQ(NegateBranchHint(hint), BranchHintOf(branch->op()));
   }
 }



--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to