Reviewers: William Hesse, Message: We should really make CodeGenerator::Comparison take a Token::Value instead of a Condition---there is no reason to pre-convert the token to a cc flag in the constant-folding case, and it makes the function artificially platform-specific.
That will have to wait for a future change. Description: Streamline CodeGenerator::Comparison in the IA32 code generator. When doing constant folding, handle only the cases that actually arise. This avoids some complicated logic, some extra comparisons, and fixes issue 247: http://code.google.com/p/v8/issues/detail?id=247 Please review this at http://codereview.chromium.org/40023 SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/ Affected files: M src/codegen-ia32.cc Index: src/codegen-ia32.cc =================================================================== --- src/codegen-ia32.cc (revision 1407) +++ src/codegen-ia32.cc (working copy) @@ -1306,6 +1306,8 @@ right_side = frame_->Pop(); left_side = frame_->Pop(); } + ASSERT(cc == less || cc == equal || cc == greater_equal); + // If either side is a constant smi, optimize the comparison. bool left_side_constant_smi = left_side.is_constant() && left_side.handle()->IsSmi(); @@ -1321,17 +1323,18 @@ // Trivial case, comparing two constants. int left_value = Smi::cast(*left_side.handle())->value(); int right_value = Smi::cast(*right_side.handle())->value(); - if (left_value < right_value && - (cc == less || cc == less_equal || cc == not_equal) || - left_value == right_value && - (cc == less_equal || cc == equal || cc == greater_equal) || - left_value > right_value && - (cc == greater || cc == greater_equal || cc == not_equal)) { - // The comparison is unconditionally true. - dest->Goto(true); - } else { - // The comparison is unconditionally false. - dest->Goto(false); + switch (cc) { + case less: + dest->Goto(left_value < right_value); + break; + case equal: + dest->Goto(left_value == right_value); + break; + case greater_equal: + dest->Goto(left_value >= right_value); + break; + default: + UNREACHABLE(); } } else { // Only one side is a constant Smi. // If left side is a constant Smi, reverse the operands. --~--~---------~--~----~------------~-------~--~----~ v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev -~----------~----~----~----~------~----~------~--~---
