2014-07-30 13:54:45 +00:00
|
|
|
// 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.
|
|
|
|
|
2019-01-10 10:38:25 +00:00
|
|
|
#include "src/base/overflowing-math.h"
|
2017-02-23 11:46:29 +00:00
|
|
|
#include "src/objects-inl.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
|
|
|
#include "test/cctest/compiler/codegen-tester.h"
|
|
|
|
#include "test/cctest/compiler/value-helper.h"
|
|
|
|
|
2015-10-30 09:16:26 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
static IrOpcode::Value int32cmp_opcodes[] = {
|
|
|
|
IrOpcode::kWord32Equal, IrOpcode::kInt32LessThan,
|
|
|
|
IrOpcode::kInt32LessThanOrEqual, IrOpcode::kUint32LessThan,
|
|
|
|
IrOpcode::kUint32LessThanOrEqual};
|
|
|
|
|
|
|
|
|
|
|
|
TEST(BranchCombineWord32EqualZero_1) {
|
|
|
|
// Test combining a branch with x == 0
|
2015-12-10 09:03:30 +00:00
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Int32());
|
2014-07-30 13:54:45 +00:00
|
|
|
int32_t eq_constant = -1033;
|
|
|
|
int32_t ne_constant = 825118;
|
|
|
|
Node* p0 = m.Parameter(0);
|
|
|
|
|
2015-11-30 11:28:50 +00:00
|
|
|
RawMachineLabel blocka, blockb;
|
2014-07-30 13:54:45 +00:00
|
|
|
m.Branch(m.Word32Equal(p0, m.Int32Constant(0)), &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(eq_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(ne_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_INT32_INPUTS(a) {
|
2014-07-30 13:54:45 +00:00
|
|
|
int32_t expect = a == 0 ? eq_constant : ne_constant;
|
|
|
|
CHECK_EQ(expect, m.Call(a));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(BranchCombineWord32EqualZero_chain) {
|
|
|
|
// Test combining a branch with a chain of x == 0 == 0 == 0 ...
|
|
|
|
int32_t eq_constant = -1133;
|
|
|
|
int32_t ne_constant = 815118;
|
|
|
|
|
|
|
|
for (int k = 0; k < 6; k++) {
|
2015-12-10 09:03:30 +00:00
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Int32());
|
2014-07-30 13:54:45 +00:00
|
|
|
Node* p0 = m.Parameter(0);
|
2015-11-30 11:28:50 +00:00
|
|
|
RawMachineLabel blocka, blockb;
|
2014-07-30 13:54:45 +00:00
|
|
|
Node* cond = p0;
|
|
|
|
for (int j = 0; j < k; j++) {
|
|
|
|
cond = m.Word32Equal(cond, m.Int32Constant(0));
|
|
|
|
}
|
|
|
|
m.Branch(cond, &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(eq_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(ne_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_INT32_INPUTS(a) {
|
2014-07-30 13:54:45 +00:00
|
|
|
int32_t expect = (k & 1) == 1 ? (a == 0 ? eq_constant : ne_constant)
|
|
|
|
: (a == 0 ? ne_constant : eq_constant);
|
|
|
|
CHECK_EQ(expect, m.Call(a));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(BranchCombineInt32LessThanZero_1) {
|
|
|
|
// Test combining a branch with x < 0
|
2015-12-10 09:03:30 +00:00
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Int32());
|
2014-07-30 13:54:45 +00:00
|
|
|
int32_t eq_constant = -1433;
|
|
|
|
int32_t ne_constant = 845118;
|
|
|
|
Node* p0 = m.Parameter(0);
|
|
|
|
|
2015-11-30 11:28:50 +00:00
|
|
|
RawMachineLabel blocka, blockb;
|
2014-07-30 13:54:45 +00:00
|
|
|
m.Branch(m.Int32LessThan(p0, m.Int32Constant(0)), &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(eq_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(ne_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_INT32_INPUTS(a) {
|
2014-07-30 13:54:45 +00:00
|
|
|
int32_t expect = a < 0 ? eq_constant : ne_constant;
|
|
|
|
CHECK_EQ(expect, m.Call(a));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(BranchCombineUint32LessThan100_1) {
|
|
|
|
// Test combining a branch with x < 100
|
2015-12-10 09:03:30 +00:00
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Uint32());
|
2014-07-30 13:54:45 +00:00
|
|
|
int32_t eq_constant = 1471;
|
|
|
|
int32_t ne_constant = 88845718;
|
|
|
|
Node* p0 = m.Parameter(0);
|
|
|
|
|
2015-11-30 11:28:50 +00:00
|
|
|
RawMachineLabel blocka, blockb;
|
2014-07-30 13:54:45 +00:00
|
|
|
m.Branch(m.Uint32LessThan(p0, m.Int32Constant(100)), &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(eq_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(ne_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_UINT32_INPUTS(a) {
|
2014-07-30 13:54:45 +00:00
|
|
|
int32_t expect = a < 100 ? eq_constant : ne_constant;
|
|
|
|
CHECK_EQ(expect, m.Call(a));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(BranchCombineUint32LessThanOrEqual100_1) {
|
|
|
|
// Test combining a branch with x <= 100
|
2015-12-10 09:03:30 +00:00
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Uint32());
|
2014-07-30 13:54:45 +00:00
|
|
|
int32_t eq_constant = 1479;
|
|
|
|
int32_t ne_constant = 77845719;
|
|
|
|
Node* p0 = m.Parameter(0);
|
|
|
|
|
2015-11-30 11:28:50 +00:00
|
|
|
RawMachineLabel blocka, blockb;
|
2014-07-30 13:54:45 +00:00
|
|
|
m.Branch(m.Uint32LessThanOrEqual(p0, m.Int32Constant(100)), &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(eq_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(ne_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_UINT32_INPUTS(a) {
|
2014-07-30 13:54:45 +00:00
|
|
|
int32_t expect = a <= 100 ? eq_constant : ne_constant;
|
|
|
|
CHECK_EQ(expect, m.Call(a));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(BranchCombineZeroLessThanInt32_1) {
|
|
|
|
// Test combining a branch with 0 < x
|
2015-12-10 09:03:30 +00:00
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Int32());
|
2014-07-30 13:54:45 +00:00
|
|
|
int32_t eq_constant = -2033;
|
|
|
|
int32_t ne_constant = 225118;
|
|
|
|
Node* p0 = m.Parameter(0);
|
|
|
|
|
2015-11-30 11:28:50 +00:00
|
|
|
RawMachineLabel blocka, blockb;
|
2014-07-30 13:54:45 +00:00
|
|
|
m.Branch(m.Int32LessThan(m.Int32Constant(0), p0), &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(eq_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(ne_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_INT32_INPUTS(a) {
|
2014-07-30 13:54:45 +00:00
|
|
|
int32_t expect = 0 < a ? eq_constant : ne_constant;
|
|
|
|
CHECK_EQ(expect, m.Call(a));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(BranchCombineInt32GreaterThanZero_1) {
|
|
|
|
// Test combining a branch with x > 0
|
2015-12-10 09:03:30 +00:00
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Int32());
|
2014-07-30 13:54:45 +00:00
|
|
|
int32_t eq_constant = -1073;
|
|
|
|
int32_t ne_constant = 825178;
|
|
|
|
Node* p0 = m.Parameter(0);
|
|
|
|
|
2015-11-30 11:28:50 +00:00
|
|
|
RawMachineLabel blocka, blockb;
|
2014-07-30 13:54:45 +00:00
|
|
|
m.Branch(m.Int32GreaterThan(p0, m.Int32Constant(0)), &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(eq_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(ne_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_INT32_INPUTS(a) {
|
2014-07-30 13:54:45 +00:00
|
|
|
int32_t expect = a > 0 ? eq_constant : ne_constant;
|
|
|
|
CHECK_EQ(expect, m.Call(a));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(BranchCombineWord32EqualP) {
|
|
|
|
// Test combining a branch with an Word32Equal.
|
2015-12-10 09:03:30 +00:00
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Int32(),
|
|
|
|
MachineType::Int32());
|
2014-07-30 13:54:45 +00:00
|
|
|
int32_t eq_constant = -1035;
|
|
|
|
int32_t ne_constant = 825018;
|
|
|
|
Node* p0 = m.Parameter(0);
|
|
|
|
Node* p1 = m.Parameter(1);
|
|
|
|
|
2015-11-30 11:28:50 +00:00
|
|
|
RawMachineLabel blocka, blockb;
|
2014-07-30 13:54:45 +00:00
|
|
|
m.Branch(m.Word32Equal(p0, p1), &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(eq_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(ne_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_INT32_INPUTS(a) {
|
|
|
|
FOR_INT32_INPUTS(b) {
|
2014-07-30 13:54:45 +00:00
|
|
|
int32_t expect = a == b ? eq_constant : ne_constant;
|
|
|
|
CHECK_EQ(expect, m.Call(a, b));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(BranchCombineWord32EqualI) {
|
|
|
|
int32_t eq_constant = -1135;
|
|
|
|
int32_t ne_constant = 925718;
|
|
|
|
|
|
|
|
for (int left = 0; left < 2; left++) {
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_INT32_INPUTS(a) {
|
2015-12-10 09:03:30 +00:00
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Int32());
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
Node* p0 = m.Int32Constant(a);
|
|
|
|
Node* p1 = m.Parameter(0);
|
|
|
|
|
2015-11-30 11:28:50 +00:00
|
|
|
RawMachineLabel blocka, blockb;
|
2014-07-30 13:54:45 +00:00
|
|
|
if (left == 1) m.Branch(m.Word32Equal(p0, p1), &blocka, &blockb);
|
|
|
|
if (left == 0) m.Branch(m.Word32Equal(p1, p0), &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(eq_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(ne_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_INT32_INPUTS(b) {
|
2014-07-30 13:54:45 +00:00
|
|
|
int32_t expect = a == b ? eq_constant : ne_constant;
|
|
|
|
CHECK_EQ(expect, m.Call(b));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(BranchCombineInt32CmpP) {
|
|
|
|
int32_t eq_constant = -1235;
|
|
|
|
int32_t ne_constant = 725018;
|
|
|
|
|
|
|
|
for (int op = 0; op < 2; op++) {
|
2015-12-10 09:03:30 +00:00
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Int32(),
|
|
|
|
MachineType::Int32());
|
2014-07-30 13:54:45 +00:00
|
|
|
Node* p0 = m.Parameter(0);
|
|
|
|
Node* p1 = m.Parameter(1);
|
|
|
|
|
2015-11-30 11:28:50 +00:00
|
|
|
RawMachineLabel blocka, blockb;
|
2014-07-30 13:54:45 +00:00
|
|
|
if (op == 0) m.Branch(m.Int32LessThan(p0, p1), &blocka, &blockb);
|
|
|
|
if (op == 1) m.Branch(m.Int32LessThanOrEqual(p0, p1), &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(eq_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(ne_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_INT32_INPUTS(a) {
|
|
|
|
FOR_INT32_INPUTS(b) {
|
2014-07-30 13:54:45 +00:00
|
|
|
int32_t expect = 0;
|
|
|
|
if (op == 0) expect = a < b ? eq_constant : ne_constant;
|
|
|
|
if (op == 1) expect = a <= b ? eq_constant : ne_constant;
|
|
|
|
CHECK_EQ(expect, m.Call(a, b));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(BranchCombineInt32CmpI) {
|
|
|
|
int32_t eq_constant = -1175;
|
|
|
|
int32_t ne_constant = 927711;
|
|
|
|
|
|
|
|
for (int op = 0; op < 2; op++) {
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_INT32_INPUTS(a) {
|
2015-12-10 09:03:30 +00:00
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Int32());
|
2014-07-30 13:54:45 +00:00
|
|
|
Node* p0 = m.Int32Constant(a);
|
|
|
|
Node* p1 = m.Parameter(0);
|
|
|
|
|
2015-11-30 11:28:50 +00:00
|
|
|
RawMachineLabel blocka, blockb;
|
2014-07-30 13:54:45 +00:00
|
|
|
if (op == 0) m.Branch(m.Int32LessThan(p0, p1), &blocka, &blockb);
|
|
|
|
if (op == 1) m.Branch(m.Int32LessThanOrEqual(p0, p1), &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(eq_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(ne_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_INT32_INPUTS(b) {
|
2014-07-30 13:54:45 +00:00
|
|
|
int32_t expect = 0;
|
|
|
|
if (op == 0) expect = a < b ? eq_constant : ne_constant;
|
|
|
|
if (op == 1) expect = a <= b ? eq_constant : ne_constant;
|
|
|
|
CHECK_EQ(expect, m.Call(b));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Now come the sophisticated tests for many input shape combinations.
|
|
|
|
|
|
|
|
// Materializes a boolean (1 or 0) from a comparison.
|
|
|
|
class CmpMaterializeBoolGen : public BinopGen<int32_t> {
|
|
|
|
public:
|
|
|
|
CompareWrapper w;
|
|
|
|
bool invert;
|
|
|
|
|
|
|
|
CmpMaterializeBoolGen(IrOpcode::Value opcode, bool i)
|
|
|
|
: w(opcode), invert(i) {}
|
|
|
|
|
2018-09-14 15:41:32 +00:00
|
|
|
void gen(RawMachineAssemblerTester<int32_t>* m, Node* a, Node* b) override {
|
2014-07-30 13:54:45 +00:00
|
|
|
Node* cond = w.MakeNode(m, a, b);
|
|
|
|
if (invert) cond = m->Word32Equal(cond, m->Int32Constant(0));
|
|
|
|
m->Return(cond);
|
|
|
|
}
|
2018-09-14 15:41:32 +00:00
|
|
|
int32_t expected(int32_t a, int32_t b) override {
|
2014-07-30 13:54:45 +00:00
|
|
|
if (invert) return !w.Int32Compare(a, b) ? 1 : 0;
|
|
|
|
return w.Int32Compare(a, b) ? 1 : 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Generates a branch and return one of two values from a comparison.
|
|
|
|
class CmpBranchGen : public BinopGen<int32_t> {
|
|
|
|
public:
|
|
|
|
CompareWrapper w;
|
|
|
|
bool invert;
|
|
|
|
bool true_first;
|
|
|
|
int32_t eq_constant;
|
|
|
|
int32_t ne_constant;
|
|
|
|
|
|
|
|
CmpBranchGen(IrOpcode::Value opcode, bool i, bool t, int32_t eq, int32_t ne)
|
|
|
|
: w(opcode), invert(i), true_first(t), eq_constant(eq), ne_constant(ne) {}
|
|
|
|
|
2018-09-14 15:41:32 +00:00
|
|
|
void gen(RawMachineAssemblerTester<int32_t>* m, Node* a, Node* b) override {
|
2015-11-30 11:28:50 +00:00
|
|
|
RawMachineLabel blocka, blockb;
|
2014-07-30 13:54:45 +00:00
|
|
|
Node* cond = w.MakeNode(m, a, b);
|
|
|
|
if (invert) cond = m->Word32Equal(cond, m->Int32Constant(0));
|
|
|
|
m->Branch(cond, &blocka, &blockb);
|
|
|
|
if (true_first) {
|
|
|
|
m->Bind(&blocka);
|
|
|
|
m->Return(m->Int32Constant(eq_constant));
|
|
|
|
m->Bind(&blockb);
|
|
|
|
m->Return(m->Int32Constant(ne_constant));
|
|
|
|
} else {
|
|
|
|
m->Bind(&blockb);
|
|
|
|
m->Return(m->Int32Constant(ne_constant));
|
|
|
|
m->Bind(&blocka);
|
|
|
|
m->Return(m->Int32Constant(eq_constant));
|
|
|
|
}
|
|
|
|
}
|
2018-09-14 15:41:32 +00:00
|
|
|
int32_t expected(int32_t a, int32_t b) override {
|
2014-07-30 13:54:45 +00:00
|
|
|
if (invert) return !w.Int32Compare(a, b) ? eq_constant : ne_constant;
|
|
|
|
return w.Int32Compare(a, b) ? eq_constant : ne_constant;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TEST(BranchCombineInt32CmpAllInputShapes_materialized) {
|
2014-08-26 09:19:24 +00:00
|
|
|
for (size_t i = 0; i < arraysize(int32cmp_opcodes); i++) {
|
2014-07-30 13:54:45 +00:00
|
|
|
CmpMaterializeBoolGen gen(int32cmp_opcodes[i], false);
|
|
|
|
Int32BinopInputShapeTester tester(&gen);
|
|
|
|
tester.TestAllInputShapes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(BranchCombineInt32CmpAllInputShapes_inverted_materialized) {
|
2014-08-26 09:19:24 +00:00
|
|
|
for (size_t i = 0; i < arraysize(int32cmp_opcodes); i++) {
|
2014-07-30 13:54:45 +00:00
|
|
|
CmpMaterializeBoolGen gen(int32cmp_opcodes[i], true);
|
|
|
|
Int32BinopInputShapeTester tester(&gen);
|
|
|
|
tester.TestAllInputShapes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(BranchCombineInt32CmpAllInputShapes_branch_true) {
|
2014-08-26 09:19:24 +00:00
|
|
|
for (int i = 0; i < static_cast<int>(arraysize(int32cmp_opcodes)); i++) {
|
2014-07-30 13:54:45 +00:00
|
|
|
CmpBranchGen gen(int32cmp_opcodes[i], false, false, 995 + i, -1011 - i);
|
|
|
|
Int32BinopInputShapeTester tester(&gen);
|
|
|
|
tester.TestAllInputShapes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(BranchCombineInt32CmpAllInputShapes_branch_false) {
|
2014-08-26 09:19:24 +00:00
|
|
|
for (int i = 0; i < static_cast<int>(arraysize(int32cmp_opcodes)); i++) {
|
2014-07-30 13:54:45 +00:00
|
|
|
CmpBranchGen gen(int32cmp_opcodes[i], false, true, 795 + i, -2011 - i);
|
|
|
|
Int32BinopInputShapeTester tester(&gen);
|
|
|
|
tester.TestAllInputShapes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(BranchCombineInt32CmpAllInputShapes_inverse_branch_true) {
|
2014-08-26 09:19:24 +00:00
|
|
|
for (int i = 0; i < static_cast<int>(arraysize(int32cmp_opcodes)); i++) {
|
2014-07-30 13:54:45 +00:00
|
|
|
CmpBranchGen gen(int32cmp_opcodes[i], true, false, 695 + i, -3011 - i);
|
|
|
|
Int32BinopInputShapeTester tester(&gen);
|
|
|
|
tester.TestAllInputShapes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(BranchCombineInt32CmpAllInputShapes_inverse_branch_false) {
|
2014-08-26 09:19:24 +00:00
|
|
|
for (int i = 0; i < static_cast<int>(arraysize(int32cmp_opcodes)); i++) {
|
2014-07-30 13:54:45 +00:00
|
|
|
CmpBranchGen gen(int32cmp_opcodes[i], true, true, 595 + i, -4011 - i);
|
|
|
|
Int32BinopInputShapeTester tester(&gen);
|
|
|
|
tester.TestAllInputShapes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(BranchCombineFloat64Compares) {
|
2014-12-20 13:17:20 +00:00
|
|
|
double inf = V8_INFINITY;
|
2015-01-21 14:38:49 +00:00
|
|
|
double nan = std::numeric_limits<double>::quiet_NaN();
|
2014-07-30 13:54:45 +00:00
|
|
|
double inputs[] = {0.0, 1.0, -1.0, -inf, inf, nan};
|
|
|
|
|
|
|
|
int32_t eq_constant = -1733;
|
|
|
|
int32_t ne_constant = 915118;
|
|
|
|
|
|
|
|
double input_a = 0.0;
|
|
|
|
double input_b = 0.0;
|
|
|
|
|
|
|
|
CompareWrapper cmps[] = {CompareWrapper(IrOpcode::kFloat64Equal),
|
|
|
|
CompareWrapper(IrOpcode::kFloat64LessThan),
|
|
|
|
CompareWrapper(IrOpcode::kFloat64LessThanOrEqual)};
|
|
|
|
|
2014-08-26 09:19:24 +00:00
|
|
|
for (size_t c = 0; c < arraysize(cmps); c++) {
|
2014-07-30 13:54:45 +00:00
|
|
|
CompareWrapper cmp = cmps[c];
|
|
|
|
for (int invert = 0; invert < 2; invert++) {
|
|
|
|
RawMachineAssemblerTester<int32_t> m;
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* a = m.LoadFromPointer(&input_a, MachineType::Float64());
|
|
|
|
Node* b = m.LoadFromPointer(&input_b, MachineType::Float64());
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2015-11-30 11:28:50 +00:00
|
|
|
RawMachineLabel blocka, blockb;
|
2014-07-30 13:54:45 +00:00
|
|
|
Node* cond = cmp.MakeNode(&m, a, b);
|
|
|
|
if (invert) cond = m.Word32Equal(cond, m.Int32Constant(0));
|
|
|
|
m.Branch(cond, &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(eq_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(ne_constant));
|
|
|
|
|
2015-01-13 08:41:52 +00:00
|
|
|
for (size_t i = 0; i < arraysize(inputs); ++i) {
|
|
|
|
for (size_t j = 0; j < arraysize(inputs); ++j) {
|
2014-07-30 13:54:45 +00:00
|
|
|
input_a = inputs[i];
|
2015-01-13 08:41:52 +00:00
|
|
|
input_b = inputs[j];
|
2014-07-30 13:54:45 +00:00
|
|
|
int32_t expected =
|
|
|
|
invert ? (cmp.Float64Compare(input_a, input_b) ? ne_constant
|
|
|
|
: eq_constant)
|
|
|
|
: (cmp.Float64Compare(input_a, input_b) ? eq_constant
|
|
|
|
: ne_constant);
|
|
|
|
CHECK_EQ(expected, m.Call());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-30 09:16:26 +00:00
|
|
|
|
[x64/ia32] Deal with the non-transitivity of InstructionSelector::CanCover() when folding loads into branches.
Sequences like:
1: Load[kRepWord32|kTypeInt32](<address>, ...)
2: Word32And(1, <constant>)
3: Word32Equal(2, <another constant>)
4: Store[(kRepWord32 : NoWriteBarrier)](<address>, <value>)
5: Branch[None](3, ...) -> B1, B2
where #1 and #4 refer to the same memory location, are problematic because in VisitBranch we assume that 'InstructionSelector::CanCover()' is transitive.
What happens is that CanCover(5, 3) is true (3 is a pure op), and so are CanCover(3, 2), CanCover(2, 1), but the effect level of 5 and 3 never gets checked because 3 is a pure op. Upon VisitBranch, we ended up materializing:
mov [address], <value>
test [address], <another constant>
With this patch, it becomes:
mov reg, [address]
mov [address], <value>
test reg, <another constant>
BUG=chromium:611976
Review-Url: https://codereview.chromium.org/2008493002
Cr-Commit-Position: refs/heads/master@{#36482}
2016-05-24 16:10:24 +00:00
|
|
|
TEST(BranchCombineEffectLevel) {
|
|
|
|
// Test that the load doesn't get folded into the branch, as there's a store
|
|
|
|
// between them. See http://crbug.com/611976.
|
|
|
|
int32_t input = 0;
|
|
|
|
|
|
|
|
RawMachineAssemblerTester<int32_t> m;
|
|
|
|
Node* a = m.LoadFromPointer(&input, MachineType::Int32());
|
|
|
|
Node* compare = m.Word32And(a, m.Int32Constant(1));
|
|
|
|
Node* equal = m.Word32Equal(compare, m.Int32Constant(0));
|
|
|
|
m.StoreToPointer(&input, MachineRepresentation::kWord32, m.Int32Constant(1));
|
|
|
|
|
|
|
|
RawMachineLabel blocka, blockb;
|
|
|
|
m.Branch(equal, &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(42));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(0));
|
|
|
|
|
|
|
|
CHECK_EQ(42, m.Call());
|
|
|
|
}
|
|
|
|
|
[arm64] Generate adds/ands.
Perform the following transformation:
| Before | After |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp w2, #0x0 | b.<cond'> <addr> |
| b.<cond> <addr> | |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp #0x0, w2 | b.<cond'> <addr> |
| b.<cond> <addr> | |
and the same for and instructions instead of add. When the result of the
add/and is not used, generate cmn/tst instead. We need to take care with which
conditions we can handle and what new condition we map them to.
BUG=
Review-Url: https://codereview.chromium.org/2065243005
Cr-Commit-Position: refs/heads/master@{#37400}
2016-06-29 14:54:49 +00:00
|
|
|
TEST(BranchCombineInt32AddLessThanZero) {
|
|
|
|
int32_t t_constant = -1033;
|
|
|
|
int32_t f_constant = 825118;
|
|
|
|
|
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Int32(),
|
|
|
|
MachineType::Int32());
|
|
|
|
Node* a = m.Parameter(0);
|
|
|
|
Node* b = m.Parameter(1);
|
|
|
|
Node* add = m.Int32Add(a, b);
|
|
|
|
Node* compare = m.Int32LessThan(add, m.Int32Constant(0));
|
|
|
|
|
|
|
|
RawMachineLabel blocka, blockb;
|
|
|
|
m.Branch(compare, &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(t_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(f_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_INT32_INPUTS(a) {
|
|
|
|
FOR_INT32_INPUTS(b) {
|
2019-01-10 10:38:25 +00:00
|
|
|
int32_t expect =
|
|
|
|
(base::AddWithWraparound(a, b) < 0) ? t_constant : f_constant;
|
[arm64] Generate adds/ands.
Perform the following transformation:
| Before | After |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp w2, #0x0 | b.<cond'> <addr> |
| b.<cond> <addr> | |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp #0x0, w2 | b.<cond'> <addr> |
| b.<cond> <addr> | |
and the same for and instructions instead of add. When the result of the
add/and is not used, generate cmn/tst instead. We need to take care with which
conditions we can handle and what new condition we map them to.
BUG=
Review-Url: https://codereview.chromium.org/2065243005
Cr-Commit-Position: refs/heads/master@{#37400}
2016-06-29 14:54:49 +00:00
|
|
|
CHECK_EQ(expect, m.Call(a, b));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BranchCombineInt32AddGreaterThanOrEqualZero) {
|
|
|
|
int32_t t_constant = -1033;
|
|
|
|
int32_t f_constant = 825118;
|
|
|
|
|
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Int32(),
|
|
|
|
MachineType::Int32());
|
|
|
|
Node* a = m.Parameter(0);
|
|
|
|
Node* b = m.Parameter(1);
|
|
|
|
Node* add = m.Int32Add(a, b);
|
|
|
|
Node* compare = m.Int32GreaterThanOrEqual(add, m.Int32Constant(0));
|
|
|
|
|
|
|
|
RawMachineLabel blocka, blockb;
|
|
|
|
m.Branch(compare, &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(t_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(f_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_INT32_INPUTS(a) {
|
|
|
|
FOR_INT32_INPUTS(b) {
|
2019-01-10 10:38:25 +00:00
|
|
|
int32_t expect =
|
|
|
|
(base::AddWithWraparound(a, b) >= 0) ? t_constant : f_constant;
|
[arm64] Generate adds/ands.
Perform the following transformation:
| Before | After |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp w2, #0x0 | b.<cond'> <addr> |
| b.<cond> <addr> | |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp #0x0, w2 | b.<cond'> <addr> |
| b.<cond> <addr> | |
and the same for and instructions instead of add. When the result of the
add/and is not used, generate cmn/tst instead. We need to take care with which
conditions we can handle and what new condition we map them to.
BUG=
Review-Url: https://codereview.chromium.org/2065243005
Cr-Commit-Position: refs/heads/master@{#37400}
2016-06-29 14:54:49 +00:00
|
|
|
CHECK_EQ(expect, m.Call(a, b));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BranchCombineInt32ZeroGreaterThanAdd) {
|
|
|
|
int32_t t_constant = -1033;
|
|
|
|
int32_t f_constant = 825118;
|
|
|
|
|
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Int32(),
|
|
|
|
MachineType::Int32());
|
|
|
|
Node* a = m.Parameter(0);
|
|
|
|
Node* b = m.Parameter(1);
|
|
|
|
Node* add = m.Int32Add(a, b);
|
|
|
|
Node* compare = m.Int32GreaterThan(m.Int32Constant(0), add);
|
|
|
|
|
|
|
|
RawMachineLabel blocka, blockb;
|
|
|
|
m.Branch(compare, &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(t_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(f_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_INT32_INPUTS(a) {
|
|
|
|
FOR_INT32_INPUTS(b) {
|
2019-01-10 10:38:25 +00:00
|
|
|
int32_t expect =
|
|
|
|
(0 > base::AddWithWraparound(a, b)) ? t_constant : f_constant;
|
[arm64] Generate adds/ands.
Perform the following transformation:
| Before | After |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp w2, #0x0 | b.<cond'> <addr> |
| b.<cond> <addr> | |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp #0x0, w2 | b.<cond'> <addr> |
| b.<cond> <addr> | |
and the same for and instructions instead of add. When the result of the
add/and is not used, generate cmn/tst instead. We need to take care with which
conditions we can handle and what new condition we map them to.
BUG=
Review-Url: https://codereview.chromium.org/2065243005
Cr-Commit-Position: refs/heads/master@{#37400}
2016-06-29 14:54:49 +00:00
|
|
|
CHECK_EQ(expect, m.Call(a, b));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BranchCombineInt32ZeroLessThanOrEqualAdd) {
|
|
|
|
int32_t t_constant = -1033;
|
|
|
|
int32_t f_constant = 825118;
|
|
|
|
|
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Int32(),
|
|
|
|
MachineType::Int32());
|
|
|
|
Node* a = m.Parameter(0);
|
|
|
|
Node* b = m.Parameter(1);
|
|
|
|
Node* add = m.Int32Add(a, b);
|
|
|
|
Node* compare = m.Int32LessThanOrEqual(m.Int32Constant(0), add);
|
|
|
|
|
|
|
|
RawMachineLabel blocka, blockb;
|
|
|
|
m.Branch(compare, &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(t_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(f_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_INT32_INPUTS(a) {
|
|
|
|
FOR_INT32_INPUTS(b) {
|
2019-01-10 10:38:25 +00:00
|
|
|
int32_t expect =
|
|
|
|
(0 <= base::AddWithWraparound(a, b)) ? t_constant : f_constant;
|
[arm64] Generate adds/ands.
Perform the following transformation:
| Before | After |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp w2, #0x0 | b.<cond'> <addr> |
| b.<cond> <addr> | |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp #0x0, w2 | b.<cond'> <addr> |
| b.<cond> <addr> | |
and the same for and instructions instead of add. When the result of the
add/and is not used, generate cmn/tst instead. We need to take care with which
conditions we can handle and what new condition we map them to.
BUG=
Review-Url: https://codereview.chromium.org/2065243005
Cr-Commit-Position: refs/heads/master@{#37400}
2016-06-29 14:54:49 +00:00
|
|
|
CHECK_EQ(expect, m.Call(a, b));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BranchCombineUint32AddLessThanOrEqualZero) {
|
|
|
|
int32_t t_constant = -1033;
|
|
|
|
int32_t f_constant = 825118;
|
|
|
|
|
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Uint32(),
|
|
|
|
MachineType::Uint32());
|
|
|
|
Node* a = m.Parameter(0);
|
|
|
|
Node* b = m.Parameter(1);
|
|
|
|
Node* add = m.Int32Add(a, b);
|
|
|
|
Node* compare = m.Uint32LessThanOrEqual(add, m.Int32Constant(0));
|
|
|
|
|
|
|
|
RawMachineLabel blocka, blockb;
|
|
|
|
m.Branch(compare, &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(t_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(f_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_UINT32_INPUTS(a) {
|
|
|
|
FOR_UINT32_INPUTS(b) {
|
[arm64] Generate adds/ands.
Perform the following transformation:
| Before | After |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp w2, #0x0 | b.<cond'> <addr> |
| b.<cond> <addr> | |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp #0x0, w2 | b.<cond'> <addr> |
| b.<cond> <addr> | |
and the same for and instructions instead of add. When the result of the
add/and is not used, generate cmn/tst instead. We need to take care with which
conditions we can handle and what new condition we map them to.
BUG=
Review-Url: https://codereview.chromium.org/2065243005
Cr-Commit-Position: refs/heads/master@{#37400}
2016-06-29 14:54:49 +00:00
|
|
|
int32_t expect = (a + b <= 0) ? t_constant : f_constant;
|
|
|
|
CHECK_EQ(expect, m.Call(a, b));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BranchCombineUint32AddGreaterThanZero) {
|
|
|
|
int32_t t_constant = -1033;
|
|
|
|
int32_t f_constant = 825118;
|
|
|
|
|
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Uint32(),
|
|
|
|
MachineType::Uint32());
|
|
|
|
Node* a = m.Parameter(0);
|
|
|
|
Node* b = m.Parameter(1);
|
|
|
|
Node* add = m.Int32Add(a, b);
|
|
|
|
Node* compare = m.Uint32GreaterThan(add, m.Int32Constant(0));
|
|
|
|
|
|
|
|
RawMachineLabel blocka, blockb;
|
|
|
|
m.Branch(compare, &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(t_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(f_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_UINT32_INPUTS(a) {
|
|
|
|
FOR_UINT32_INPUTS(b) {
|
[arm64] Generate adds/ands.
Perform the following transformation:
| Before | After |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp w2, #0x0 | b.<cond'> <addr> |
| b.<cond> <addr> | |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp #0x0, w2 | b.<cond'> <addr> |
| b.<cond> <addr> | |
and the same for and instructions instead of add. When the result of the
add/and is not used, generate cmn/tst instead. We need to take care with which
conditions we can handle and what new condition we map them to.
BUG=
Review-Url: https://codereview.chromium.org/2065243005
Cr-Commit-Position: refs/heads/master@{#37400}
2016-06-29 14:54:49 +00:00
|
|
|
int32_t expect = (a + b > 0) ? t_constant : f_constant;
|
|
|
|
CHECK_EQ(expect, m.Call(a, b));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BranchCombineUint32ZeroGreaterThanOrEqualAdd) {
|
|
|
|
int32_t t_constant = -1033;
|
|
|
|
int32_t f_constant = 825118;
|
|
|
|
|
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Uint32(),
|
|
|
|
MachineType::Uint32());
|
|
|
|
Node* a = m.Parameter(0);
|
|
|
|
Node* b = m.Parameter(1);
|
|
|
|
Node* add = m.Int32Add(a, b);
|
|
|
|
Node* compare = m.Uint32GreaterThanOrEqual(m.Int32Constant(0), add);
|
|
|
|
|
|
|
|
RawMachineLabel blocka, blockb;
|
|
|
|
m.Branch(compare, &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(t_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(f_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_UINT32_INPUTS(a) {
|
|
|
|
FOR_UINT32_INPUTS(b) {
|
[arm64] Generate adds/ands.
Perform the following transformation:
| Before | After |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp w2, #0x0 | b.<cond'> <addr> |
| b.<cond> <addr> | |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp #0x0, w2 | b.<cond'> <addr> |
| b.<cond> <addr> | |
and the same for and instructions instead of add. When the result of the
add/and is not used, generate cmn/tst instead. We need to take care with which
conditions we can handle and what new condition we map them to.
BUG=
Review-Url: https://codereview.chromium.org/2065243005
Cr-Commit-Position: refs/heads/master@{#37400}
2016-06-29 14:54:49 +00:00
|
|
|
int32_t expect = (0 >= a + b) ? t_constant : f_constant;
|
|
|
|
CHECK_EQ(expect, m.Call(a, b));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BranchCombineUint32ZeroLessThanAdd) {
|
|
|
|
int32_t t_constant = -1033;
|
|
|
|
int32_t f_constant = 825118;
|
|
|
|
|
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Uint32(),
|
|
|
|
MachineType::Uint32());
|
|
|
|
Node* a = m.Parameter(0);
|
|
|
|
Node* b = m.Parameter(1);
|
|
|
|
Node* add = m.Int32Add(a, b);
|
|
|
|
Node* compare = m.Uint32LessThan(m.Int32Constant(0), add);
|
|
|
|
|
|
|
|
RawMachineLabel blocka, blockb;
|
|
|
|
m.Branch(compare, &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(t_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(f_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_UINT32_INPUTS(a) {
|
|
|
|
FOR_UINT32_INPUTS(b) {
|
[arm64] Generate adds/ands.
Perform the following transformation:
| Before | After |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp w2, #0x0 | b.<cond'> <addr> |
| b.<cond> <addr> | |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp #0x0, w2 | b.<cond'> <addr> |
| b.<cond> <addr> | |
and the same for and instructions instead of add. When the result of the
add/and is not used, generate cmn/tst instead. We need to take care with which
conditions we can handle and what new condition we map them to.
BUG=
Review-Url: https://codereview.chromium.org/2065243005
Cr-Commit-Position: refs/heads/master@{#37400}
2016-06-29 14:54:49 +00:00
|
|
|
int32_t expect = (0 < a + b) ? t_constant : f_constant;
|
|
|
|
CHECK_EQ(expect, m.Call(a, b));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BranchCombineWord32AndLessThanZero) {
|
|
|
|
int32_t t_constant = -1033;
|
|
|
|
int32_t f_constant = 825118;
|
|
|
|
|
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Int32(),
|
|
|
|
MachineType::Int32());
|
|
|
|
Node* a = m.Parameter(0);
|
|
|
|
Node* b = m.Parameter(1);
|
|
|
|
Node* add = m.Word32And(a, b);
|
|
|
|
Node* compare = m.Int32LessThan(add, m.Int32Constant(0));
|
|
|
|
|
|
|
|
RawMachineLabel blocka, blockb;
|
|
|
|
m.Branch(compare, &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(t_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(f_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_INT32_INPUTS(a) {
|
|
|
|
FOR_INT32_INPUTS(b) {
|
[arm64] Generate adds/ands.
Perform the following transformation:
| Before | After |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp w2, #0x0 | b.<cond'> <addr> |
| b.<cond> <addr> | |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp #0x0, w2 | b.<cond'> <addr> |
| b.<cond> <addr> | |
and the same for and instructions instead of add. When the result of the
add/and is not used, generate cmn/tst instead. We need to take care with which
conditions we can handle and what new condition we map them to.
BUG=
Review-Url: https://codereview.chromium.org/2065243005
Cr-Commit-Position: refs/heads/master@{#37400}
2016-06-29 14:54:49 +00:00
|
|
|
int32_t expect = ((a & b) < 0) ? t_constant : f_constant;
|
|
|
|
CHECK_EQ(expect, m.Call(a, b));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BranchCombineWord32AndGreaterThanOrEqualZero) {
|
|
|
|
int32_t t_constant = -1033;
|
|
|
|
int32_t f_constant = 825118;
|
|
|
|
|
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Int32(),
|
|
|
|
MachineType::Int32());
|
|
|
|
Node* a = m.Parameter(0);
|
|
|
|
Node* b = m.Parameter(1);
|
|
|
|
Node* add = m.Word32And(a, b);
|
|
|
|
Node* compare = m.Int32GreaterThanOrEqual(add, m.Int32Constant(0));
|
|
|
|
|
|
|
|
RawMachineLabel blocka, blockb;
|
|
|
|
m.Branch(compare, &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(t_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(f_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_INT32_INPUTS(a) {
|
|
|
|
FOR_INT32_INPUTS(b) {
|
[arm64] Generate adds/ands.
Perform the following transformation:
| Before | After |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp w2, #0x0 | b.<cond'> <addr> |
| b.<cond> <addr> | |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp #0x0, w2 | b.<cond'> <addr> |
| b.<cond> <addr> | |
and the same for and instructions instead of add. When the result of the
add/and is not used, generate cmn/tst instead. We need to take care with which
conditions we can handle and what new condition we map them to.
BUG=
Review-Url: https://codereview.chromium.org/2065243005
Cr-Commit-Position: refs/heads/master@{#37400}
2016-06-29 14:54:49 +00:00
|
|
|
int32_t expect = ((a & b) >= 0) ? t_constant : f_constant;
|
|
|
|
CHECK_EQ(expect, m.Call(a, b));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BranchCombineInt32ZeroGreaterThanAnd) {
|
|
|
|
int32_t t_constant = -1033;
|
|
|
|
int32_t f_constant = 825118;
|
|
|
|
|
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Int32(),
|
|
|
|
MachineType::Int32());
|
|
|
|
Node* a = m.Parameter(0);
|
|
|
|
Node* b = m.Parameter(1);
|
|
|
|
Node* add = m.Word32And(a, b);
|
|
|
|
Node* compare = m.Int32GreaterThan(m.Int32Constant(0), add);
|
|
|
|
|
|
|
|
RawMachineLabel blocka, blockb;
|
|
|
|
m.Branch(compare, &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(t_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(f_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_INT32_INPUTS(a) {
|
|
|
|
FOR_INT32_INPUTS(b) {
|
[arm64] Generate adds/ands.
Perform the following transformation:
| Before | After |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp w2, #0x0 | b.<cond'> <addr> |
| b.<cond> <addr> | |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp #0x0, w2 | b.<cond'> <addr> |
| b.<cond> <addr> | |
and the same for and instructions instead of add. When the result of the
add/and is not used, generate cmn/tst instead. We need to take care with which
conditions we can handle and what new condition we map them to.
BUG=
Review-Url: https://codereview.chromium.org/2065243005
Cr-Commit-Position: refs/heads/master@{#37400}
2016-06-29 14:54:49 +00:00
|
|
|
int32_t expect = (0 > (a & b)) ? t_constant : f_constant;
|
|
|
|
CHECK_EQ(expect, m.Call(a, b));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BranchCombineInt32ZeroLessThanOrEqualAnd) {
|
|
|
|
int32_t t_constant = -1033;
|
|
|
|
int32_t f_constant = 825118;
|
|
|
|
|
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Int32(),
|
|
|
|
MachineType::Int32());
|
|
|
|
Node* a = m.Parameter(0);
|
|
|
|
Node* b = m.Parameter(1);
|
|
|
|
Node* add = m.Word32And(a, b);
|
|
|
|
Node* compare = m.Int32LessThanOrEqual(m.Int32Constant(0), add);
|
|
|
|
|
|
|
|
RawMachineLabel blocka, blockb;
|
|
|
|
m.Branch(compare, &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(t_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(f_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_INT32_INPUTS(a) {
|
|
|
|
FOR_INT32_INPUTS(b) {
|
[arm64] Generate adds/ands.
Perform the following transformation:
| Before | After |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp w2, #0x0 | b.<cond'> <addr> |
| b.<cond> <addr> | |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp #0x0, w2 | b.<cond'> <addr> |
| b.<cond> <addr> | |
and the same for and instructions instead of add. When the result of the
add/and is not used, generate cmn/tst instead. We need to take care with which
conditions we can handle and what new condition we map them to.
BUG=
Review-Url: https://codereview.chromium.org/2065243005
Cr-Commit-Position: refs/heads/master@{#37400}
2016-06-29 14:54:49 +00:00
|
|
|
int32_t expect = (0 <= (a & b)) ? t_constant : f_constant;
|
|
|
|
CHECK_EQ(expect, m.Call(a, b));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BranchCombineUint32AndLessThanOrEqualZero) {
|
|
|
|
int32_t t_constant = -1033;
|
|
|
|
int32_t f_constant = 825118;
|
|
|
|
|
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Uint32(),
|
|
|
|
MachineType::Uint32());
|
|
|
|
Node* a = m.Parameter(0);
|
|
|
|
Node* b = m.Parameter(1);
|
|
|
|
Node* add = m.Word32And(a, b);
|
|
|
|
Node* compare = m.Uint32LessThanOrEqual(add, m.Int32Constant(0));
|
|
|
|
|
|
|
|
RawMachineLabel blocka, blockb;
|
|
|
|
m.Branch(compare, &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(t_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(f_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_UINT32_INPUTS(a) {
|
|
|
|
FOR_UINT32_INPUTS(b) {
|
[arm64] Generate adds/ands.
Perform the following transformation:
| Before | After |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp w2, #0x0 | b.<cond'> <addr> |
| b.<cond> <addr> | |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp #0x0, w2 | b.<cond'> <addr> |
| b.<cond> <addr> | |
and the same for and instructions instead of add. When the result of the
add/and is not used, generate cmn/tst instead. We need to take care with which
conditions we can handle and what new condition we map them to.
BUG=
Review-Url: https://codereview.chromium.org/2065243005
Cr-Commit-Position: refs/heads/master@{#37400}
2016-06-29 14:54:49 +00:00
|
|
|
int32_t expect = ((a & b) <= 0) ? t_constant : f_constant;
|
|
|
|
CHECK_EQ(expect, m.Call(a, b));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BranchCombineUint32AndGreaterThanZero) {
|
|
|
|
int32_t t_constant = -1033;
|
|
|
|
int32_t f_constant = 825118;
|
|
|
|
|
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Uint32(),
|
|
|
|
MachineType::Uint32());
|
|
|
|
Node* a = m.Parameter(0);
|
|
|
|
Node* b = m.Parameter(1);
|
|
|
|
Node* add = m.Word32And(a, b);
|
|
|
|
Node* compare = m.Uint32GreaterThan(add, m.Int32Constant(0));
|
|
|
|
|
|
|
|
RawMachineLabel blocka, blockb;
|
|
|
|
m.Branch(compare, &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(t_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(f_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_UINT32_INPUTS(a) {
|
|
|
|
FOR_UINT32_INPUTS(b) {
|
[arm64] Generate adds/ands.
Perform the following transformation:
| Before | After |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp w2, #0x0 | b.<cond'> <addr> |
| b.<cond> <addr> | |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp #0x0, w2 | b.<cond'> <addr> |
| b.<cond> <addr> | |
and the same for and instructions instead of add. When the result of the
add/and is not used, generate cmn/tst instead. We need to take care with which
conditions we can handle and what new condition we map them to.
BUG=
Review-Url: https://codereview.chromium.org/2065243005
Cr-Commit-Position: refs/heads/master@{#37400}
2016-06-29 14:54:49 +00:00
|
|
|
int32_t expect = ((a & b) > 0) ? t_constant : f_constant;
|
|
|
|
CHECK_EQ(expect, m.Call(a, b));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BranchCombineUint32ZeroGreaterThanOrEqualAnd) {
|
|
|
|
int32_t t_constant = -1033;
|
|
|
|
int32_t f_constant = 825118;
|
|
|
|
|
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Uint32(),
|
|
|
|
MachineType::Uint32());
|
|
|
|
Node* a = m.Parameter(0);
|
|
|
|
Node* b = m.Parameter(1);
|
|
|
|
Node* add = m.Word32And(a, b);
|
|
|
|
Node* compare = m.Uint32GreaterThanOrEqual(m.Int32Constant(0), add);
|
|
|
|
|
|
|
|
RawMachineLabel blocka, blockb;
|
|
|
|
m.Branch(compare, &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(t_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(f_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_UINT32_INPUTS(a) {
|
|
|
|
FOR_UINT32_INPUTS(b) {
|
[arm64] Generate adds/ands.
Perform the following transformation:
| Before | After |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp w2, #0x0 | b.<cond'> <addr> |
| b.<cond> <addr> | |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp #0x0, w2 | b.<cond'> <addr> |
| b.<cond> <addr> | |
and the same for and instructions instead of add. When the result of the
add/and is not used, generate cmn/tst instead. We need to take care with which
conditions we can handle and what new condition we map them to.
BUG=
Review-Url: https://codereview.chromium.org/2065243005
Cr-Commit-Position: refs/heads/master@{#37400}
2016-06-29 14:54:49 +00:00
|
|
|
int32_t expect = (0 >= (a & b)) ? t_constant : f_constant;
|
|
|
|
CHECK_EQ(expect, m.Call(a, b));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BranchCombineUint32ZeroLessThanAnd) {
|
|
|
|
int32_t t_constant = -1033;
|
|
|
|
int32_t f_constant = 825118;
|
|
|
|
|
|
|
|
RawMachineAssemblerTester<int32_t> m(MachineType::Uint32(),
|
|
|
|
MachineType::Uint32());
|
|
|
|
Node* a = m.Parameter(0);
|
|
|
|
Node* b = m.Parameter(1);
|
|
|
|
Node* add = m.Word32And(a, b);
|
|
|
|
Node* compare = m.Uint32LessThan(m.Int32Constant(0), add);
|
|
|
|
|
|
|
|
RawMachineLabel blocka, blockb;
|
|
|
|
m.Branch(compare, &blocka, &blockb);
|
|
|
|
m.Bind(&blocka);
|
|
|
|
m.Return(m.Int32Constant(t_constant));
|
|
|
|
m.Bind(&blockb);
|
|
|
|
m.Return(m.Int32Constant(f_constant));
|
|
|
|
|
2019-02-01 14:21:25 +00:00
|
|
|
FOR_UINT32_INPUTS(a) {
|
|
|
|
FOR_UINT32_INPUTS(b) {
|
[arm64] Generate adds/ands.
Perform the following transformation:
| Before | After |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp w2, #0x0 | b.<cond'> <addr> |
| b.<cond> <addr> | |
|------------------+---------------------|
| add w2, w0, w1 | adds w2, w0, w1 |
| cmp #0x0, w2 | b.<cond'> <addr> |
| b.<cond> <addr> | |
and the same for and instructions instead of add. When the result of the
add/and is not used, generate cmn/tst instead. We need to take care with which
conditions we can handle and what new condition we map them to.
BUG=
Review-Url: https://codereview.chromium.org/2065243005
Cr-Commit-Position: refs/heads/master@{#37400}
2016-06-29 14:54:49 +00:00
|
|
|
int32_t expect = (0 < (a & b)) ? t_constant : f_constant;
|
|
|
|
CHECK_EQ(expect, m.Call(a, b));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-30 09:16:26 +00:00
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|