Files
palemoon27/js/src/jsapi-tests/testJitDCEinGVN.cpp
T
roytam1 e753cbebb0 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1249482 - OdinMonkey: Remove the needsBoundsCheck flag from the frontend. r=luke (5004e664a0)
- Bug 1249513 - OdinMonkey: MIPS: Clean up long jump patching in asm.js. r=luke (18c7f026f5)
- fix misspatch of 1234985 (0713b005b4)
- Bug 1248598 part 1 - Some code changes required for the i64.const instruction. r=luke (7bb3eaa57f)
- Bug 1247855: Resolve named functions and locals (r=luke) (e06d418fd1)
- Bug 1249524 - Baldr: add the other (param) declaration form to the text format (r=mbx) (9492f57377)
- Bug 1249523 - Baldr: add return (r=mbx) (36a4eca6a3)
- Bug 1249316 - Baldr: move testing functions back into TestingFunctions.cpp (r=jandem) (7daf99a017)
- Bug 1249531 - Baldr: add text format and encoding support for control operators (r=mbx) (6dee433349)
- Bug 1248598 part 2 - Reject wasm i64 imports/exports as JS doesn't have an int64 type. r=luke (72603cdb3d)
- Bug 1246658 part 4 - Replace MConstant's js::Value with a custom union. r=luke (1c78b526d2)
- Bug 1246658 part 5 - Support int64 constants, add MIRType_Int64. r=luk (db94c230c6)
- Bug 1246658 part 1 followup - Fix a bug introduced by the refactoring. (ec3d444596)
- Bug 1248859 - OdinMonkey: MIPS: Fix replace retargetWithOffset. r=arai (dd117fcbf5)
- Bug 1249525 - Baldr: accept - and $ in text names (r=sunfish) (64e4e1ddf8)
- Bug 1249525 - Baldr: accept integer cases in float constants (r=sunfish) (90a8fbb5d5)
- Bug 1248859 - OdinMonkey: MIPS: Implement thunkWithPatch and re/patchThunk. r=luke (722240c9b7)
- Bug 1248859 - OdinMonkey: MIPS: Refactor callWithPatch via reative branch. r=luke (0684904686)
- Bug 1248503 - Improve log output for MSimdBox and MSimdUnbox. r=nbp (6b65608504)
- Bug 1248503 - Fix initial heap assertion. r=nbp (bcf704df34)
- Bug 1249525 - Baldr: change order of load/store immediates/subexpressions (r=sunfish) (c2ec5329e2)
- Bug 1240055: IonMonkey: When spewing info about range analysis, also spew truncation info, r=nbp (cf477cffce)
- fix misspatch in symbol visibility (039e111b31)
2023-09-21 17:30:19 +08:00

144 lines
4.2 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: set ts=8 sts=4 et sw=4 tw=99:
*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "jit/IonAnalysis.h"
#include "jit/MIRGenerator.h"
#include "jit/MIRGraph.h"
#include "jit/ValueNumbering.h"
#include "jsapi-tests/testJitMinimalFunc.h"
#include "jsapi-tests/tests.h"
using namespace js;
using namespace js::jit;
BEGIN_TEST(testJitDCEinGVN_ins)
{
MinimalFunc func;
MBasicBlock* block = func.createEntryBlock();
// mul0 = p * p
// mul1 = mul0 * mul0
// return p
MParameter* p = func.createParameter();
block->add(p);
MMul* mul0 = MMul::New(func.alloc, p, p, MIRType_Double);
block->add(mul0);
if (!mul0->typePolicy()->adjustInputs(func.alloc, mul0))
return false;
MMul* mul1 = MMul::New(func.alloc, mul0, mul0, MIRType_Double);
block->add(mul1);
if (!mul1->typePolicy()->adjustInputs(func.alloc, mul1))
return false;
MReturn* ret = MReturn::New(func.alloc, p);
block->end(ret);
if (!func.runGVN())
return false;
// mul0 and mul1 should be deleted.
for (MInstructionIterator ins = block->begin(); ins != block->end(); ins++) {
CHECK(!ins->isMul() || (ins->getOperand(0) != p && ins->getOperand(1) != p));
CHECK(!ins->isMul() || (ins->getOperand(0) != mul0 && ins->getOperand(1) != mul0));
}
return true;
}
END_TEST(testJitDCEinGVN_ins)
BEGIN_TEST(testJitDCEinGVN_phi)
{
MinimalFunc func;
MBasicBlock* block = func.createEntryBlock();
MBasicBlock* thenBlock1 = func.createBlock(block);
MBasicBlock* thenBlock2 = func.createBlock(block);
MBasicBlock* elifBlock = func.createBlock(block);
MBasicBlock* elseBlock = func.createBlock(block);
MBasicBlock* joinBlock = func.createBlock(block);
// if (p) {
// x = 1.0;
// y = 3.0;
// } else if (q) {
// x = 2.0;
// y = 4.0;
// } else {
// x = 1.0;
// y = 5.0;
// }
// x = phi(1.0, 2.0, 1.0);
// y = phi(3.0, 4.0, 5.0);
// z = x * y;
// return y;
MConstant* c1 = MConstant::New(func.alloc, DoubleValue(1.0));
block->add(c1);
MPhi* x = MPhi::New(func.alloc);
MPhi* y = MPhi::New(func.alloc);
// if (p) {
MParameter* p = func.createParameter();
block->add(p);
block->end(MTest::New(func.alloc, p, thenBlock1, elifBlock));
// x = 1.0
// y = 3.0;
x->addInputSlow(c1);
MConstant* c3 = MConstant::New(func.alloc, DoubleValue(3.0));
thenBlock1->add(c3);
y->addInputSlow(c3);
thenBlock1->end(MGoto::New(func.alloc, joinBlock));
joinBlock->addPredecessor(func.alloc, thenBlock1);
// } else if (q) {
MParameter* q = func.createParameter();
elifBlock->add(q);
elifBlock->end(MTest::New(func.alloc, q, thenBlock2, elseBlock));
// x = 2.0
// y = 4.0;
MConstant* c2 = MConstant::New(func.alloc, DoubleValue(2.0));
thenBlock2->add(c2);
x->addInputSlow(c2);
MConstant* c4 = MConstant::New(func.alloc, DoubleValue(4.0));
thenBlock2->add(c4);
y->addInputSlow(c4);
thenBlock2->end(MGoto::New(func.alloc, joinBlock));
joinBlock->addPredecessor(func.alloc, thenBlock2);
// } else {
// x = 1.0
// y = 5.0;
// }
x->addInputSlow(c1);
MConstant* c5 = MConstant::New(func.alloc, DoubleValue(5.0));
elseBlock->add(c5);
y->addInputSlow(c5);
elseBlock->end(MGoto::New(func.alloc, joinBlock));
joinBlock->addPredecessor(func.alloc, elseBlock);
// x = phi(1.0, 2.0, 1.0)
// y = phi(3.0, 4.0, 5.0)
// z = x * y
// return y
joinBlock->addPhi(x);
joinBlock->addPhi(y);
MMul* z = MMul::New(func.alloc, x, y, MIRType_Double);
joinBlock->add(z);
MReturn* ret = MReturn::New(func.alloc, y);
joinBlock->end(ret);
if (!func.runGVN())
return false;
// c1 should be deleted.
for (MInstructionIterator ins = block->begin(); ins != block->end(); ins++) {
CHECK(!ins->isConstant() || (ins->toConstant()->numberToDouble() != 1.0));
}
return true;
}
END_TEST(testJitDCEinGVN_phi)