diff --git a/runtime/vm/compiler/backend/il_dbc.cc b/runtime/vm/compiler/backend/il_dbc.cc index 634b9dcb2a0..42beb69f97f 100644 --- a/runtime/vm/compiler/backend/il_dbc.cc +++ b/runtime/vm/compiler/backend/il_dbc.cc @@ -1850,26 +1850,6 @@ EMIT_NATIVE_CODE(MathMinMax, 2, Location::RequiresRegister()) { } } -static Token::Kind FlipCondition(Token::Kind kind) { - switch (kind) { - case Token::kEQ: - return Token::kNE; - case Token::kNE: - return Token::kEQ; - case Token::kLT: - return Token::kGTE; - case Token::kGT: - return Token::kLTE; - case Token::kLTE: - return Token::kGT; - case Token::kGTE: - return Token::kLT; - default: - UNREACHABLE(); - return Token::kNE; - } -} - static SimulatorBytecode::Opcode OpcodeForSmiCondition(Token::Kind kind) { switch (kind) { case Token::kEQ: @@ -1919,11 +1899,11 @@ static Condition EmitSmiComparisonOp(FlowGraphCompiler* compiler, if (labels.fall_through != labels.false_label) { // If we aren't falling through to the false label, we can save a Jump // instruction in the case that the true case is the fall through by - // flipping the sense of the test such that the instruction following the + // negating the sense of the test such that the instruction following the // test is the Jump to the false label. In the case where both labels are - // null we don't flip the sense of the test. + // null we don't negate the sense of the test. condition = NEXT_IS_FALSE; - comparison = FlipCondition(kind); + comparison = Token::NegateComparison(kind); } if (compiler->is_optimizing()) { const Register left = locs->in(0).reg(); diff --git a/runtime/vm/compiler/backend/range_analysis.cc b/runtime/vm/compiler/backend/range_analysis.cc index 554d61b8de7..7fa08c04929 100644 --- a/runtime/vm/compiler/backend/range_analysis.cc +++ b/runtime/vm/compiler/backend/range_analysis.cc @@ -114,28 +114,6 @@ void RangeAnalysis::CollectValues() { } } -// For a comparison operation return an operation for the equivalent flipped -// comparison: a (op) b === b (op') a. -static Token::Kind FlipComparison(Token::Kind op) { - switch (op) { - case Token::kEQ: - return Token::kEQ; - case Token::kNE: - return Token::kNE; - case Token::kLT: - return Token::kGT; - case Token::kGT: - return Token::kLT; - case Token::kLTE: - return Token::kGTE; - case Token::kGTE: - return Token::kLTE; - default: - UNREACHABLE(); - return Token::kILLEGAL; - } -} - // Given a boundary (right operand) and a comparison operation return // a symbolic range constraint for the left operand of the comparison assuming // that it evaluated to true. @@ -208,7 +186,7 @@ bool RangeAnalysis::ConstrainValueAfterBranch(Value* use, Definition* defn) { boundary = rel_op->InputAt(0)->definition(); // InsertConstraintFor assumes that defn is left operand of a // comparison if it is right operand flip the comparison. - op_kind = FlipComparison(rel_op->kind()); + op_kind = Token::FlipComparison(rel_op->kind()); } // Constrain definition at the true successor. diff --git a/runtime/vm/token.h b/runtime/vm/token.h index adb0fba7582..ff8c6824fb4 100644 --- a/runtime/vm/token.h +++ b/runtime/vm/token.h @@ -322,6 +322,32 @@ class Token { } } + // For a comparison operation return an operation for the equivalent flipped + // comparison: a (op) b === b (op') a. + static Token::Kind FlipComparison(Token::Kind op) { + switch (op) { + case Token::kEQ: + return Token::kEQ; + case Token::kNE: + return Token::kNE; + case Token::kLT: + return Token::kGT; + case Token::kGT: + return Token::kLT; + case Token::kLTE: + return Token::kGTE; + case Token::kGTE: + return Token::kLTE; + case Token::kEQ_STRICT: + return Token::kEQ_STRICT; + case Token::kNE_STRICT: + return Token::kNE_STRICT; + default: + UNREACHABLE(); + return Token::kILLEGAL; + } + } + private: static const char* name_[]; static const char* tok_str_[];