[csa] fix variable merge for switch default label

Bug: 
Change-Id: I52e757aa2de951ff40660545472321c7dec84241
Reviewed-on: https://chromium-review.googlesource.com/632156
Reviewed-by: Daniel Clifford <danno@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48167}
This commit is contained in:
Tobias Tebbi 2017-08-30 22:28:04 +02:00 committed by Commit Bot
parent e0b76c9a84
commit e6d84f4ecb
3 changed files with 17 additions and 9 deletions

View File

@ -1208,8 +1208,8 @@ void CodeAssembler::Switch(Node* index, Label* default_label,
for (size_t i = 0; i < case_count; ++i) {
labels[i] = case_labels[i]->label_;
case_labels[i]->MergeVariables();
default_label->MergeVariables();
}
default_label->MergeVariables();
return raw_assembler()->Switch(index, default_label->label_, case_values,
labels, case_count);
}

View File

@ -2473,6 +2473,7 @@ void InstructionSelector::VisitOsrValue(Node* node) {
void InstructionSelector::VisitPhi(Node* node) {
const int input_count = node->op()->ValueInputCount();
DCHECK_EQ(input_count, current_block_->PredecessorCount());
PhiInstruction* phi = new (instruction_zone())
PhiInstruction(instruction_zone(), GetVirtualRegister(node),
static_cast<size_t>(input_count));

View File

@ -4,6 +4,8 @@
#include "src/code-factory.h"
#include "src/compiler/code-assembler.h"
#include "src/compiler/node-properties.h"
#include "src/compiler/opcodes.h"
#include "src/isolate.h"
#include "src/objects-inl.h"
#include "test/cctest/compiler/code-assembler-tester.h"
@ -309,18 +311,23 @@ TEST(VariableMergeSwitch) {
Label l1(&m), l2(&m), default_label(&m);
Label* labels[] = {&l1, &l2};
int32_t values[] = {1, 2};
Node* temp = m.Int32Constant(0);
var1.Bind(temp);
Node* temp1 = m.Int32Constant(0);
var1.Bind(temp1);
m.Switch(m.Int32Constant(2), &default_label, values, labels, 2);
m.Bind(&l1);
DCHECK_EQ(temp, var1.value());
m.Return(temp);
CHECK_EQ(temp1, var1.value());
m.Return(temp1);
m.Bind(&l2);
DCHECK_EQ(temp, var1.value());
m.Return(temp);
CHECK_EQ(temp1, var1.value());
Node* temp2 = m.Int32Constant(7);
var1.Bind(temp2);
m.Goto(&default_label);
m.Bind(&default_label);
DCHECK_EQ(temp, var1.value());
m.Return(temp);
CHECK_EQ(IrOpcode::kPhi, var1.value()->opcode());
CHECK_EQ(2, var1.value()->op()->ValueInputCount());
CHECK_EQ(temp1, NodeProperties::GetValueInput(var1.value(), 0));
CHECK_EQ(temp2, NodeProperties::GetValueInput(var1.value(), 1));
m.Return(temp1);
}
TEST(SplitEdgeBranchMerge) {