diff --git a/hphp/runtime/vm/jit/hhbctranslator.cpp b/hphp/runtime/vm/jit/hhbctranslator.cpp index 5d1b88855..e46848983 100644 --- a/hphp/runtime/vm/jit/hhbctranslator.cpp +++ b/hphp/runtime/vm/jit/hhbctranslator.cpp @@ -2880,26 +2880,8 @@ void HhbcTranslator::emitCastDouble() { void HhbcTranslator::emitCastInt() { IRTrace* catchTrace = getCatchTrace(); SSATmp* src = popC(); - Type fromType = src->type(); - if (fromType.isInt()) { - push(src); - } else if (fromType.isNull()) { - push(cns(0)); - } else if (fromType.isArray()) { - push(gen(ConvArrToInt, src)); - gen(DecRef, src); - } else if (fromType.isBool()) { - push(gen(ConvBoolToInt, src)); - } else if (fromType.isDbl()) { - push(gen(ConvDblToInt, src)); - } else if (fromType.isString()) { - push(gen(ConvStrToInt, src)); - gen(DecRef, src); - } else if (fromType.isObj()) { - push(gen(ConvObjToInt, catchTrace, src)); - } else { - push(gen(ConvCellToInt, catchTrace, src)); - } + push(gen(ConvCellToInt, catchTrace, src)); + gen(DecRef, src); } void HhbcTranslator::emitCastObject() { diff --git a/hphp/runtime/vm/jit/ir.h b/hphp/runtime/vm/jit/ir.h index a498293be..3768dd9e2 100644 --- a/hphp/runtime/vm/jit/ir.h +++ b/hphp/runtime/vm/jit/ir.h @@ -242,9 +242,9 @@ O(ConvCellToDbl, D(Dbl), S(Cell), N|Er|CRc|K) \ O(ConvArrToInt, D(Int), S(Arr), C|N) \ O(ConvBoolToInt, D(Int), S(Bool), C) \ O(ConvDblToInt, D(Int), S(Dbl), C|N) \ -O(ConvObjToInt, D(Int), S(Obj), N|Er|CRc|K) \ +O(ConvObjToInt, D(Int), S(Obj), N|Er|K) \ O(ConvStrToInt, D(Int), S(Str), N) \ -O(ConvCellToInt, D(Int), S(Cell), N|Er|CRc|K) \ +O(ConvCellToInt, D(Int), S(Cell), N|Er|K) \ \ O(ConvCellToObj, D(Obj), S(Cell), N|CRc|K) \ \ diff --git a/hphp/runtime/vm/jit/simplifier.cpp b/hphp/runtime/vm/jit/simplifier.cpp index 1226a08e0..4abf6d305 100644 --- a/hphp/runtime/vm/jit/simplifier.cpp +++ b/hphp/runtime/vm/jit/simplifier.cpp @@ -305,6 +305,7 @@ SSATmp* Simplifier::simplify(IRInstruction* inst) { case ConvDblToStr: return simplifyConvDblToStr(inst); case ConvIntToStr: return simplifyConvIntToStr(inst); case ConvCellToBool:return simplifyConvCellToBool(inst); + case ConvCellToInt: return simplifyConvCellToInt(inst); case Unbox: return simplifyUnbox(inst); case UnboxPtr: return simplifyUnboxPtr(inst); case IsType: @@ -1446,6 +1447,21 @@ SSATmp* Simplifier::simplifyConvCellToBool(IRInstruction* inst) { return nullptr; } +SSATmp* Simplifier::simplifyConvCellToInt(IRInstruction* inst) { + auto const src = inst->src(0); + auto const srcType = src->type(); + + if (srcType.isInt()) return src; + if (srcType.isNull()) return cns(0); + if (srcType.isArray()) return gen(ConvArrToInt, src); + if (srcType.isBool()) return gen(ConvBoolToInt, src); + if (srcType.isDbl()) return gen(ConvDblToInt, src); + if (srcType.isString()) return gen(ConvStrToInt, src); + if (srcType.isObj()) return gen(ConvObjToInt, inst->taken(), src); + + return nullptr; +} + SSATmp* Simplifier::simplifyLdClsPropAddr(IRInstruction* inst) { SSATmp* propName = inst->src(1); if (!propName->isConst()) return nullptr; diff --git a/hphp/runtime/vm/jit/simplifier.h b/hphp/runtime/vm/jit/simplifier.h index 95df529af..b9fc140e5 100644 --- a/hphp/runtime/vm/jit/simplifier.h +++ b/hphp/runtime/vm/jit/simplifier.h @@ -101,6 +101,7 @@ private: SSATmp* simplifyConvDblToStr(IRInstruction*); SSATmp* simplifyConvIntToStr(IRInstruction*); SSATmp* simplifyConvCellToBool(IRInstruction*); + SSATmp* simplifyConvCellToInt(IRInstruction*); SSATmp* simplifyUnbox(IRInstruction*); SSATmp* simplifyUnboxPtr(IRInstruction*); SSATmp* simplifyCheckInit(IRInstruction* inst); diff --git a/hphp/runtime/vm/jit/translator-runtime.cpp b/hphp/runtime/vm/jit/translator-runtime.cpp index a028bdd81..87678fc9d 100644 --- a/hphp/runtime/vm/jit/translator-runtime.cpp +++ b/hphp/runtime/vm/jit/translator-runtime.cpp @@ -170,19 +170,7 @@ int64_t convStrToIntHelper(const StringData* s) { } int64_t convCellToIntHelper(TypedValue tv) { - try { - tvCastToInt64InPlace(&tv); // consumes a ref on counted values - // but not if an exception happens. (REVIEW) - return tv.m_data.num; - } catch (...) { - // spill tv back to stack. unwinder - // will take care of decreffing it. - VMRegAnchor _; - TypedValue* spillSlot = (TypedValue *)vmsp(); - spillSlot->m_data.num = tv.m_data.num; - spillSlot->m_type = tv.m_type; - throw; - } + return tvCastToInt64(&tv); } ObjectData* convCellToObjHelper(TypedValue tv) {