Reviewers: mvstanton,
Description:
Fixed constant folding in HMod.
We have to check for overflow before attempting to do a modulo operation,
otherwise Crankshaft itself segfaults on some platforms, e.g. ia32. Added
tests
even for division, where the problem doesn't show up, just to be sure...
Please review this at https://codereview.chromium.org/14617014/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/hydrogen-instructions.cc
M test/mjsunit/constant-folding-2.js
Index: src/hydrogen-instructions.cc
diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc
index
f38fb7d5e3d4312383c198cf23b25a7cf2f8f602..2b525159b0ba2be12d386e718c4c0377f33a5448
100644
--- a/src/hydrogen-instructions.cc
+++ b/src/hydrogen-instructions.cc
@@ -3341,6 +3341,9 @@ HInstruction* HMod::New(
if (c_left->HasInteger32Value() && c_right->HasInteger32Value()) {
int32_t dividend = c_left->Integer32Value();
int32_t divisor = c_right->Integer32Value();
+ if (dividend == kMinInt && divisor == -1) {
+ return H_CONSTANT_DOUBLE(-0.0);
+ }
if (divisor != 0) {
int32_t res = dividend % divisor;
if ((res == 0) && (dividend < 0)) {
Index: test/mjsunit/constant-folding-2.js
diff --git a/test/mjsunit/constant-folding-2.js
b/test/mjsunit/constant-folding-2.js
index
6dbb4abebf2fa9bcda716d3b7e263468e1d08ab1..284f0b3c76930be4b9ad4433ccf47307ad4cc365
100644
--- a/test/mjsunit/constant-folding-2.js
+++ b/test/mjsunit/constant-folding-2.js
@@ -256,3 +256,12 @@ test(function stringCharAt() {
assertEquals("b", "abc".charAt(1.1));
assertEquals("", "abc".charAt(4.1));
});
+
+
+test(function int32Mod() {
+ assertEquals(-0, -2147483648 % (-1));
+});
+
+test(function int32Div() {
+ assertEquals(2147483648, -2147483648 * (-1));
+});
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.