1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "jit/IonAnalysis.h"
9 #include "jit/MIRGenerator.h"
10 #include "jit/MIRGraph.h"
11 #include "jit/ValueNumbering.h"
13 #include "jsapi-tests/testJitMinimalFunc.h"
14 #include "jsapi-tests/tests.h"
17 using namespace js::jit
;
19 BEGIN_TEST(testJitDCEinGVN_ins
) {
21 MBasicBlock
* block
= func
.createEntryBlock();
26 MParameter
* p
= func
.createParameter();
28 MMul
* mul0
= MMul::New(func
.alloc
, p
, p
, MIRType::Double
);
30 if (!mul0
->typePolicy()->adjustInputs(func
.alloc
, mul0
)) {
33 MMul
* mul1
= MMul::New(func
.alloc
, mul0
, mul0
, MIRType::Double
);
35 if (!mul1
->typePolicy()->adjustInputs(func
.alloc
, mul1
)) {
38 MReturn
* ret
= MReturn::New(func
.alloc
, p
);
45 // mul0 and mul1 should be deleted.
46 for (MInstructionIterator ins
= block
->begin(); ins
!= block
->end(); ins
++) {
47 CHECK(!ins
->isMul() ||
48 (ins
->getOperand(0) != p
&& ins
->getOperand(1) != p
));
49 CHECK(!ins
->isMul() ||
50 (ins
->getOperand(0) != mul0
&& ins
->getOperand(1) != mul0
));
54 END_TEST(testJitDCEinGVN_ins
)
56 BEGIN_TEST(testJitDCEinGVN_phi
) {
58 MBasicBlock
* block
= func
.createEntryBlock();
59 MBasicBlock
* thenBlock1
= func
.createBlock(block
);
60 MBasicBlock
* thenBlock2
= func
.createBlock(block
);
61 MBasicBlock
* elifBlock
= func
.createBlock(block
);
62 MBasicBlock
* elseBlock
= func
.createBlock(block
);
63 MBasicBlock
* joinBlock
= func
.createBlock(block
);
75 // x = phi(1.0, 2.0, 1.0);
76 // y = phi(3.0, 4.0, 5.0);
80 MConstant
* c1
= MConstant::New(func
.alloc
, DoubleValue(1.0));
82 MPhi
* x
= MPhi::New(func
.alloc
);
83 MPhi
* y
= MPhi::New(func
.alloc
);
86 MParameter
* p
= func
.createParameter();
88 block
->end(MTest::New(func
.alloc
, p
, thenBlock1
, elifBlock
));
92 MOZ_RELEASE_ASSERT(x
->addInputSlow(c1
));
93 MConstant
* c3
= MConstant::New(func
.alloc
, DoubleValue(3.0));
95 MOZ_RELEASE_ASSERT(y
->addInputSlow(c3
));
96 thenBlock1
->end(MGoto::New(func
.alloc
, joinBlock
));
97 MOZ_ALWAYS_TRUE(joinBlock
->addPredecessor(func
.alloc
, thenBlock1
));
100 MParameter
* q
= func
.createParameter();
102 elifBlock
->end(MTest::New(func
.alloc
, q
, thenBlock2
, elseBlock
));
106 MConstant
* c2
= MConstant::New(func
.alloc
, DoubleValue(2.0));
108 MOZ_RELEASE_ASSERT(x
->addInputSlow(c2
));
109 MConstant
* c4
= MConstant::New(func
.alloc
, DoubleValue(4.0));
111 MOZ_RELEASE_ASSERT(y
->addInputSlow(c4
));
112 thenBlock2
->end(MGoto::New(func
.alloc
, joinBlock
));
113 MOZ_ALWAYS_TRUE(joinBlock
->addPredecessor(func
.alloc
, thenBlock2
));
119 MOZ_RELEASE_ASSERT(x
->addInputSlow(c1
));
120 MConstant
* c5
= MConstant::New(func
.alloc
, DoubleValue(5.0));
122 MOZ_RELEASE_ASSERT(y
->addInputSlow(c5
));
123 elseBlock
->end(MGoto::New(func
.alloc
, joinBlock
));
124 MOZ_ALWAYS_TRUE(joinBlock
->addPredecessor(func
.alloc
, elseBlock
));
126 // x = phi(1.0, 2.0, 1.0)
127 // y = phi(3.0, 4.0, 5.0)
130 joinBlock
->addPhi(x
);
131 joinBlock
->addPhi(y
);
132 MMul
* z
= MMul::New(func
.alloc
, x
, y
, MIRType::Double
);
134 MReturn
* ret
= MReturn::New(func
.alloc
, y
);
137 if (!func
.runGVN()) {
141 // c1 should be deleted.
142 for (MInstructionIterator ins
= block
->begin(); ins
!= block
->end(); ins
++) {
143 CHECK(!ins
->isConstant() || (ins
->toConstant()->numberToDouble() != 1.0));
147 END_TEST(testJitDCEinGVN_phi
)