bool ion::ExtractLinearInequality(MTest *test, BranchDirection direction, LinearSum *plhs, MDefinition **prhs, bool *plessEqual) { if (!test->getOperand(0)->isCompare()) return false; MCompare *compare = test->getOperand(0)->toCompare(); MDefinition *lhs = compare->getOperand(0); MDefinition *rhs = compare->getOperand(1); if (compare->specialization() != MIRType_Int32) return false; JS_ASSERT(lhs->type() == MIRType_Int32); JS_ASSERT(rhs->type() == MIRType_Int32); JSOp jsop = compare->jsop(); if (direction == FALSE_BRANCH) jsop = analyze::NegateCompareOp(jsop); LinearSum lsum = ExtractLinearSum(lhs); LinearSum rsum = ExtractLinearSum(rhs); if (!SafeSub(lsum.constant, rsum.constant, &lsum.constant)) return false; // Normalize operations to use <= or >=. switch (jsop) { case JSOP_LE: *plessEqual = true; break; case JSOP_LT: /* x < y ==> x + 1 <= y */ if (!SafeAdd(lsum.constant, 1, &lsum.constant)) return false; *plessEqual = true; break; case JSOP_GE: *plessEqual = false; break; case JSOP_GT: /* x > y ==> x - 1 >= y */ if (!SafeSub(lsum.constant, 1, &lsum.constant)) return false; *plessEqual = false; break; default: return false; } *plhs = lsum; *prhs = rsum.term; return true; }