Commit 1c13f873 authored by Hao Xu's avatar Hao Xu Committed by V8 LUCI CQ

[compiler] Optimize BranchConditionDuplicationPhase

Only apply this optimization to the conditions that have multiple
branch uses.

Bug: v8:12484
Change-Id: Ieb74b8e879e62aa96344f2903f1fea6a1b769549
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3902559Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Hao A Xu <hao.a.xu@intel.com>
Cr-Commit-Position: refs/heads/main@{#83347}
parent 2d53c3a7
......@@ -70,7 +70,7 @@ void BranchConditionDuplicator::DuplicateConditionIfNeeded(Node* node) {
if (!IsBranch(node)) return;
Node* condNode = node->InputAt(0);
if (condNode->UseCount() > 1 && CanDuplicate(condNode)) {
if (condNode->BranchUseCount() > 1 && CanDuplicate(condNode)) {
node->ReplaceInput(0, DuplicateNode(condNode));
}
}
......
......@@ -293,6 +293,15 @@ int Node::UseCount() const {
return use_count;
}
int Node::BranchUseCount() const {
int use_count = 0;
for (Use* use = first_use_; use; use = use->next) {
if (use->from()->opcode() == IrOpcode::kBranch) {
++use_count;
}
}
return use_count;
}
void Node::ReplaceUses(Node* that) {
DCHECK(this->first_use_ == nullptr || this->first_use_->prev == nullptr);
......
......@@ -98,6 +98,7 @@ class V8_EXPORT_PRIVATE Node final {
void EnsureInputCount(Zone* zone, int new_input_count);
int UseCount() const;
int BranchUseCount() const;
void ReplaceUses(Node* replace_to);
class InputEdges;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment