[turbofan] Fix matching of the lea instruction.
Resets the scaled exponent to 0 when the scaling match fails. BUG= Review URL: https://codereview.chromium.org/756643002 Cr-Commit-Position: refs/heads/master@{#25491}
This commit is contained in:
parent
100db75808
commit
d9cabb9b22
@ -298,14 +298,16 @@ struct ScaledWithOffsetMatcher {
|
||||
Node* left_left = left_matcher.left().node();
|
||||
Node* left_right = left_matcher.right().node();
|
||||
if (left_matcher.HasScaledInput() && left_left->OwnedBy(left)) {
|
||||
scaled_ = left_matcher.ScaledInput();
|
||||
scale_exponent_ = left_matcher.ScaleExponent();
|
||||
if (left_matcher.right().HasValue()) {
|
||||
// ((S + C) + O)
|
||||
scaled_ = left_matcher.ScaledInput();
|
||||
scale_exponent_ = left_matcher.ScaleExponent();
|
||||
constant_ = left_right;
|
||||
offset_ = right;
|
||||
} else if (base_matcher.right().HasValue()) {
|
||||
// ((S + O) + C)
|
||||
scaled_ = left_matcher.ScaledInput();
|
||||
scale_exponent_ = left_matcher.ScaleExponent();
|
||||
offset_ = left_right;
|
||||
constant_ = right;
|
||||
} else {
|
||||
|
14
test/mjsunit/regress/regress-lea-matching.js
Normal file
14
test/mjsunit/regress/regress-lea-matching.js
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2014 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
function f(a, b, c) {
|
||||
a = a|0;
|
||||
b = b|0;
|
||||
c = c|0;
|
||||
var r = 0;
|
||||
r = a + ((b << 1) + c) | 0;
|
||||
return r|0;
|
||||
}
|
||||
|
||||
assertEquals(8, f(1, 2, 3));
|
@ -741,6 +741,31 @@ TEST_F(InstructionSelectorTest, Int32SubConstantAsLea) {
|
||||
}
|
||||
|
||||
|
||||
TEST_F(InstructionSelectorTest, Int32AddScaled2Other) {
|
||||
StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32, kMachInt32);
|
||||
Node* const p0 = m.Parameter(0);
|
||||
Node* const p1 = m.Parameter(1);
|
||||
Node* const p2 = m.Parameter(2);
|
||||
Node* const s0 = m.Int32Mul(p1, m.Int32Constant(2));
|
||||
Node* const a0 = m.Int32Add(s0, p2);
|
||||
Node* const a1 = m.Int32Add(p0, a0);
|
||||
m.Return(a1);
|
||||
Stream s = m.Build();
|
||||
ASSERT_EQ(2U, s.size());
|
||||
EXPECT_EQ(kX64Lea32, s[0]->arch_opcode());
|
||||
EXPECT_EQ(kMode_MR2, s[0]->addressing_mode());
|
||||
ASSERT_EQ(2U, s[0]->InputCount());
|
||||
EXPECT_EQ(s.ToVreg(p2), s.ToVreg(s[0]->InputAt(0)));
|
||||
EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
|
||||
EXPECT_EQ(s.ToVreg(a0), s.ToVreg(s[0]->OutputAt(0)));
|
||||
ASSERT_EQ(2U, s[1]->InputCount());
|
||||
EXPECT_EQ(kX64Add32, s[1]->arch_opcode());
|
||||
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[1]->InputAt(0)));
|
||||
EXPECT_EQ(s.ToVreg(a0), s.ToVreg(s[1]->InputAt(1)));
|
||||
EXPECT_EQ(s.ToVreg(a1), s.ToVreg(s[1]->OutputAt(0)));
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Multiplication.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user