diff --git a/js/src/jit-test/tests/asm.js/testGlobals.js b/js/src/jit-test/tests/asm.js/testGlobals.js index 2a75d938b27..e596d582368 100644 --- a/js/src/jit-test/tests/asm.js/testGlobals.js +++ b/js/src/jit-test/tests/asm.js/testGlobals.js @@ -104,3 +104,8 @@ var p = new Proxy(global, getOwnPropertyDescriptor:function(name) { return {value:Int32Array}}}); new Int32Array(ab)[4] = 42; assertEq(f1(p, null, ab)(), 42); + +// GVN checks +assertEq(asmLink(asmCompile(USE_ASM + "var g=0; function f() { var x = 0; g = 1; x = g; return (x+g)|0 } return f"))(), 2); +assertEq(asmLink(asmCompile(USE_ASM + "var g=0; function f() { var x = 0; g = 1; x = g; g = 2; return (x+g)|0 } return f"))(), 3); +assertEq(asmLink(asmCompile(USE_ASM + "var g=0; var h=0; function f() { var x = 0; g = 1; x = g; h = 3; return (x+g)|0 } return f"))(), 2); diff --git a/js/src/jit/MIR.cpp b/js/src/jit/MIR.cpp index 28e5c4d0d15..9aa8d5dbda4 100644 --- a/js/src/jit/MIR.cpp +++ b/js/src/jit/MIR.cpp @@ -2432,6 +2432,26 @@ MLoadFixedSlot::mightAlias(MDefinition *store) return true; } +bool +MAsmJSLoadGlobalVar::mightAlias(MDefinition *def) +{ + if (def->isAsmJSStoreGlobalVar()) { + MAsmJSStoreGlobalVar *store = def->toAsmJSStoreGlobalVar(); + return store->globalDataOffset() == globalDataOffset_; + } + return true; +} + +bool +MAsmJSLoadGlobalVar::congruentTo(MDefinition *ins) const +{ + if (ins->isAsmJSLoadGlobalVar()) { + MAsmJSLoadGlobalVar *load = ins->toAsmJSLoadGlobalVar(); + return globalDataOffset_ == load->globalDataOffset_; + } + return false; +} + bool MLoadSlot::mightAlias(MDefinition *store) { diff --git a/js/src/jit/MIR.h b/js/src/jit/MIR.h index ac41db67fb4..e1e60fe74bc 100644 --- a/js/src/jit/MIR.h +++ b/js/src/jit/MIR.h @@ -217,10 +217,11 @@ class AliasSet { FixedSlot = 1 << 3, // A member of obj->fixedSlots(). TypedArrayElement = 1 << 4, // A typed array element. DOMProperty = 1 << 5, // A DOM property - Last = DOMProperty, + AsmJSGlobalVar = 1 << 6, // An asm.js global var + Last = AsmJSGlobalVar, Any = Last | (Last - 1), - NumCategories = 6, + NumCategories = 7, // Indicates load or store. Store_ = 1 << 31 @@ -8446,8 +8447,7 @@ class MAsmJSLoadGlobalVar : public MNullaryInstruction { JS_ASSERT(type == MIRType_Int32 || type == MIRType_Double); setResultType(type); - if (isConstant) - setMovable(); + setMovable(); } unsigned globalDataOffset_; @@ -8462,12 +8462,13 @@ class MAsmJSLoadGlobalVar : public MNullaryInstruction unsigned globalDataOffset() const { return globalDataOffset_; } + bool congruentTo(MDefinition *ins) const; + AliasSet getAliasSet() const { - if (isConstant_) - return AliasSet::None(); - else - return AliasSet::Store(AliasSet::Any); + return AliasSet::Load(AliasSet::AsmJSGlobalVar); } + + bool mightAlias(MDefinition *def); }; class MAsmJSStoreGlobalVar : public MUnaryInstruction @@ -8487,6 +8488,10 @@ class MAsmJSStoreGlobalVar : public MUnaryInstruction unsigned globalDataOffset() const { return globalDataOffset_; } MDefinition *value() const { return getOperand(0); } + + AliasSet getAliasSet() const { + return AliasSet::Store(AliasSet::AsmJSGlobalVar); + } }; class MAsmJSLoadFuncPtr : public MUnaryInstruction