Bug 1410429 - Odin: Fold base pointer into offsets whenever possible; r=luke

MozReview-Commit-ID: ERmQ9YKDzFH

--HG--
extra : rebase_source : 90bd2b039bd7b3af333067b20a26b820c8903235
This commit is contained in:
Benjamin Bouvier 2017-10-19 16:52:09 +02:00
parent ceb60c8001
commit cd6edeac02
2 changed files with 19 additions and 0 deletions

View File

@ -756,6 +756,7 @@ class MemoryAccessDesc
bool isPlainAsmJS() const { return !hasTrap(); } bool isPlainAsmJS() const { return !hasTrap(); }
void clearOffset() { offset_ = 0; } void clearOffset() { offset_ = 0; }
void setOffset(uint32_t offset) { offset_ = offset; }
}; };
// Summarizes a global access for a mutable (in asm.js) or immutable value (in // Summarizes a global access for a mutable (in asm.js) or immutable value (in

View File

@ -777,6 +777,24 @@ class FunctionCompiler
void checkOffsetAndBounds(MemoryAccessDesc* access, MDefinition** base) void checkOffsetAndBounds(MemoryAccessDesc* access, MDefinition** base)
{ {
// Fold a constant base into the offset (so the base is 0 in which case
// the codegen is optimized), if it doesn't wrap or trigger an
// MWasmAddOffset.
if ((*base)->isConstant()) {
uint32_t basePtr = (*base)->toConstant()->toInt32();
uint32_t offset = access->offset();
static_assert(OffsetGuardLimit < UINT32_MAX,
"checking for overflow against OffsetGuardLimit is enough.");
if (offset < OffsetGuardLimit && basePtr < OffsetGuardLimit - offset) {
auto* ins = MConstant::New(alloc(), Int32Value(0), MIRType::Int32);
curBlock_->add(ins);
*base = ins;
access->setOffset(access->offset() + basePtr);
}
}
// If the offset is bigger than the guard region, a separate instruction // If the offset is bigger than the guard region, a separate instruction
// is necessary to add the offset to the base and check for overflow. // is necessary to add the offset to the base and check for overflow.
if (access->offset() >= OffsetGuardLimit || !JitOptions.wasmFoldOffsets) { if (access->offset() >= OffsetGuardLimit || !JitOptions.wasmFoldOffsets) {