Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Unified Diff: runtime/vm/intermediate_language_ia32.cc

Issue 13884009: Support IfThenElse instruction pattern for arbitrary smi constants. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/vm/intermediate_language_ia32.cc
diff --git a/runtime/vm/intermediate_language_ia32.cc b/runtime/vm/intermediate_language_ia32.cc
index 96e14fa0757e55d3357d39f2c14c7508c2758acc..689f965d55ebccbdc62c85076b7393f045b6224b 100644
--- a/runtime/vm/intermediate_language_ia32.cc
+++ b/runtime/vm/intermediate_language_ia32.cc
@@ -3724,12 +3724,6 @@ static bool IsPowerOfTwoKind(intptr_t v1, intptr_t v2) {
}
-// Detect pattern when one value is increment of another.
-static bool IsIncrementKind(intptr_t v1, intptr_t v2) {
- return ((v1 == v2 + 1) || (v1 + 1 == v2));
-}
-
-
bool IfThenElseInstr::IsSupported() {
return true;
}
@@ -3752,12 +3746,7 @@ bool IfThenElseInstr::Supports(ComparisonInstr* comparison,
return false;
}
- if (IsPowerOfTwoKind(v1_value, v2_value) ||
- IsIncrementKind(v1_value, v2_value)) {
- return true;
- }
-
- return false;
+ return true;
}
@@ -3803,22 +3792,38 @@ void IfThenElseInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
const bool is_power_of_two_kind = IsPowerOfTwoKind(if_true_, if_false_);
- const intptr_t base = Utils::Minimum(if_true_, if_false_);
+ intptr_t true_value = if_true_;
+ intptr_t false_value = if_false_;
- if (if_true_ == base) {
- // We need to have zero in EDX on true_condition.
- true_condition = NegateCondition(true_condition);
+ if (is_power_of_two_kind) {
+ if (true_value == 0) {
+ // We need to have zero in EDX on true_condition.
+ true_condition = NegateCondition(true_condition);
+ }
+ } else {
+ if (true_value == 0) {
+ // Swap values so that false_value is zero.
+ intptr_t temp = true_value;
+ true_value = false_value;
+ false_value = temp;
+ } else {
+ true_condition = NegateCondition(true_condition);
+ }
}
__ setcc(true_condition, DL);
if (is_power_of_two_kind) {
const intptr_t shift =
- Utils::ShiftForPowerOfTwo(Utils::Maximum(if_true_, if_false_));
+ Utils::ShiftForPowerOfTwo(Utils::Maximum(true_value, false_value));
__ shll(EDX, Immediate(shift + kSmiTagSize));
} else {
- ASSERT(kSmiTagSize == 1);
- __ leal(EDX, Address(EDX, TIMES_2, base << kSmiTagSize));
+ __ subl(EDX, Immediate(1));
+ __ andl(EDX, Immediate(
+ Smi::RawValue(true_value) - Smi::RawValue(false_value)));
+ if (false_value != 0) {
+ __ addl(EDX, Immediate(Smi::RawValue(false_value)));
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698