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

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

Issue 986073003: [TurboFan] Calculate precise ranges for bitwise-or with positive input ranges. Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Split the bitwise-or type derivation into a separate function. 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..4d0dedb6d5459c3e33a982bea718d8f5cfcdeda9 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) {
@@ -263,6 +290,22 @@ TEST_F(TyperTest, TypeJSModulus) {
TEST_F(TyperTest, TypeJSBitwiseOr) {
TestBinaryBitOp(javascript_.BitwiseOr(LanguageMode::SLOPPY), bit_or);
TestBinaryBitOp(javascript_.BitwiseOr(LanguageMode::STRONG), bit_or);
+ // The derivation algorithm works one bit at a time and scales to
+ // any bit width so verify on practical bit widths.
+ TestPreciseBinaryArithOp<bit_or>(JSBitwiseOrIntType,
+ -16, 15, 1, -16, 15, 1);
+ TestPreciseBinaryArithOp<bit_or>(JSBitwiseOrIntType,
+ kMaxInt - 32, kMaxInt, 1,
+ kMaxInt - 32, kMaxInt, 1);
+ TestPreciseBinaryArithOp<bit_or>(JSBitwiseOrIntType,
+ kMinInt, kMinInt + 32, 1,
+ kMinInt, kMinInt + 32, 1);
+ TestPreciseBinaryArithOp<bit_or>(JSBitwiseOrIntType,
+ kMaxInt - 32 * 2, kMaxInt, 2,
+ kMaxInt - 32 * 2, kMaxInt, 2);
+ TestPreciseBinaryArithOp<bit_or>(JSBitwiseOrIntType,
+ kMinInt, kMinInt + 32 * 2, 2,
+ kMinInt, kMinInt + 32 * 2, 2);
}
« 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