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

Unified Diff: test/unittests/compiler/typer-unittest.cc

Issue 1121573004: Precise shift right result type derivation for all int32 input ranges. Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Split out the shift-right integer result type derivation. Created 5 years, 7 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 | « src/compiler/typer.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/compiler/typer-unittest.cc
diff --git a/test/unittests/compiler/typer-unittest.cc b/test/unittests/compiler/typer-unittest.cc
index f977c6fddd4d26a7d6928cee22ce734e5b9fb67e..169ef8b3b31ef0bca08a36a8d249309c8de347e4 100644
--- a/test/unittests/compiler/typer-unittest.cc
+++ b/test/unittests/compiler/typer-unittest.cc
@@ -146,6 +146,33 @@ class TyperTest : public TypedGraphTest {
}
}
+ // Careful, this function scales poorly.
+ template <int32_t op(int32_t, int32_t), class DeriveFunction>
+ void TestPreciseBinaryArithOp(DeriveFunction derive,
+ int32_t llow, int32_t lhigh, int32_t linc,
+ int32_t rlow, int32_t rhigh, int32_t rinc) {
+ for (int64_t lmin = llow; lmin <= lhigh; lmin += linc) {
+ for (int64_t lmax = lmin; lmax <= lhigh; lmax += linc) {
+ for (int64_t rmin = rlow; rmin <= rhigh; rmin += rinc) {
+ for (int64_t rmax = rmin; rmax <= rhigh; rmax += rinc) {
+ IntType r1 = IntType(int32_t(lmin), int32_t(lmax));
+ IntType r2 = IntType(int32_t(rmin), int32_t(rmax));
+ IntType derived_type = derive(r1, r2);
+ int32_t min = kMaxInt, max = kMinInt;
+ for (int32_t x1 = int32_t(lmin); x1 <= int32_t(lmax); x1++) {
+ for (int32_t x2 = int32_t(rmin); x2 <= int32_t(rmax); x2++) {
+ int32_t result_value = op(x1, x2);
+ min = std::min(result_value, min);
+ max = std::max(result_value, max);
+ }
+ }
+ EXPECT_TRUE(derived_type.min == min && derived_type.max == max);
+ }
+ }
+ }
+ }
+ }
+
template <class BinaryFunction>
void TestBinaryCompareOp(const Operator* op, BinaryFunction opfun) {
for (int i = 0; i < 100; ++i) {
@@ -287,6 +314,18 @@ TEST_F(TyperTest, TypeJSShiftLeft) {
TEST_F(TyperTest, TypeJSShiftRight) {
TestBinaryBitOp(javascript_.ShiftRight(LanguageMode::SLOPPY), shift_right);
TestBinaryBitOp(javascript_.ShiftRight(LanguageMode::STRONG), shift_right);
+ TestPreciseBinaryArithOp<shift_right>(JSShiftRightIntType,
+ -16, 15, 1, -64, 63, 1);
+ TestPreciseBinaryArithOp<shift_right>(JSShiftRightIntType,
+ kMaxInt - 16, kMaxInt, 1, -64, 63, 1);
+ TestPreciseBinaryArithOp<shift_right>(JSShiftRightIntType,
+ kMinInt, kMinInt + 16, 1, -64, 63, 1);
+ TestPreciseBinaryArithOp<shift_right>(JSShiftRightIntType,
+ kMaxInt - 16 * 2,
+ kMaxInt, 2, -64, 63, 1);
+ TestPreciseBinaryArithOp<shift_right>(JSShiftRightIntType,
+ kMinInt, kMinInt + 16 * 2,
+ 2, -64, 63, 1);
}
« no previous file with comments | « src/compiler/typer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698