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

Unified Diff: runtime/vm/intermediate_language.cc

Issue 938783003: Don't constant fold operation if result is incompatible with it. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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
« no previous file with comments | « runtime/vm/compiler.cc ('k') | tests/corelib/corelib.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/intermediate_language.cc
diff --git a/runtime/vm/intermediate_language.cc b/runtime/vm/intermediate_language.cc
index 4d1eb876fb8f7bcfc9d3fa4127571abd85ecbcf1..865976f991f88bf3061fbdda71a0fc38630899d7 100644
--- a/runtime/vm/intermediate_language.cc
+++ b/runtime/vm/intermediate_language.cc
@@ -1566,6 +1566,29 @@ BinaryIntegerOpInstr* BinaryIntegerOpInstr::Make(Representation representation,
}
+static bool IsRepresentable(const Integer& value, Representation rep) {
+ switch (rep) {
+ case kTagged: // Smi case.
+ return value.IsSmi();
+
+ case kUnboxedInt32:
+ if (value.IsSmi() || value.IsMint()) {
+ return Utils::IsInt(32, value.AsInt64Value());
+ }
+ return false;
+
+ case kUnboxedMint:
+ return value.IsSmi() || value.IsMint();
+
+ case kUnboxedUint32: // Only truncating Uint32 arithmetic is supported.
+ default:
+ UNREACHABLE();
+ }
+
+ return false;
+}
+
+
RawInteger* BinaryIntegerOpInstr::Evaluate(const Integer& left,
const Integer& right) const {
Integer& result = Integer::Handle();
@@ -1607,6 +1630,13 @@ RawInteger* BinaryIntegerOpInstr::Evaluate(const Integer& left,
int64_t truncated = result.AsTruncatedInt64Value();
truncated &= RepresentationMask(representation());
result = Integer::New(truncated);
+ ASSERT(IsRepresentable(result, representation()));
+ } else if (!IsRepresentable(result, representation())) {
+ // If this operation is not truncating it would deoptimize on overflow.
+ // Check that we match this behavior and don't produce a value that is
+ // larger than something this operation can produce. We could have
+ // specialized instructions that use this value under this assumption.
+ return Integer::null();
}
result ^= result.CheckAndCanonicalize(NULL);
}
« no previous file with comments | « runtime/vm/compiler.cc ('k') | tests/corelib/corelib.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698