| OLD | NEW | 
|    1 // Copyright 2014 the V8 project authors. All rights reserved. |    1 // Copyright 2014 the V8 project authors. All rights reserved. | 
|    2 // Use of this source code is governed by a BSD-style license that can be |    2 // Use of this source code is governed by a BSD-style license that can be | 
|    3 // found in the LICENSE file. |    3 // found in the LICENSE file. | 
|    4  |    4  | 
|    5 #include "src/base/bits.h" |    5 #include "src/base/bits.h" | 
|    6 #include "src/compiler/graph-unittest.h" |    6 #include "src/compiler/graph-unittest.h" | 
|    7 #include "src/compiler/js-graph.h" |    7 #include "src/compiler/js-graph.h" | 
|    8 #include "src/compiler/machine-operator-reducer.h" |    8 #include "src/compiler/machine-operator-reducer.h" | 
|    9 #include "src/compiler/typer.h" |    9 #include "src/compiler/typer.h" | 
|   10  |   10  | 
| (...skipping 28 matching lines...) Expand all  Loading... | 
|   39       public ::testing::WithParamInterface<T> { |   39       public ::testing::WithParamInterface<T> { | 
|   40  public: |   40  public: | 
|   41   explicit MachineOperatorReducerTestWithParam(int num_parameters = 2) |   41   explicit MachineOperatorReducerTestWithParam(int num_parameters = 2) | 
|   42       : MachineOperatorReducerTest(num_parameters) {} |   42       : MachineOperatorReducerTest(num_parameters) {} | 
|   43   virtual ~MachineOperatorReducerTestWithParam() {} |   43   virtual ~MachineOperatorReducerTestWithParam() {} | 
|   44 }; |   44 }; | 
|   45  |   45  | 
|   46  |   46  | 
|   47 namespace { |   47 namespace { | 
|   48  |   48  | 
 |   49 static const float kFloat32Values[] = { | 
 |   50     -V8_INFINITY,  -2.70497e+38f, -1.4698e+37f,  -1.22813e+35f, -1.20555e+35f, | 
 |   51     -1.34584e+34f, -1.0079e+32f,  -6.49364e+26f, -3.06077e+25f, -1.46821e+25f, | 
 |   52     -1.17658e+23f, -1.9617e+22f,  -2.7357e+20f,  -1.48708e+13f, -1.89633e+12f, | 
 |   53     -4.66622e+11f, -2.22581e+11f, -1.45381e+10f, -1.3956e+09f,  -1.32951e+09f, | 
 |   54     -1.30721e+09f, -1.19756e+09f, -9.26822e+08f, -6.35647e+08f, -4.00037e+08f, | 
 |   55     -1.81227e+08f, -5.09256e+07f, -964300.0f,    -192446.0f,    -28455.0f, | 
 |   56     -27194.0f,     -26401.0f,     -20575.0f,     -17069.0f,     -9167.0f, | 
 |   57     -960.178f,     -113.0f,       -62.0f,        -15.0f,        -7.0f, | 
 |   58     -0.0256635f,   -4.60374e-07f, -3.63759e-10f, -4.30175e-14f, -5.27385e-15f, | 
 |   59     -1.48084e-15f, -1.05755e-19f, -3.2995e-21f,  -1.67354e-23f, -1.11885e-23f, | 
 |   60     -1.78506e-30f, -5.07594e-31f, -3.65799e-31f, -1.43718e-34f, -1.27126e-38f, | 
 |   61     -0.0f,         0.0f,          1.17549e-38f,  1.56657e-37f,  4.08512e-29f, | 
 |   62     3.31357e-28f,  6.25073e-22f,  4.1723e-13f,   1.44343e-09f,  5.27004e-08f, | 
 |   63     9.48298e-08f,  5.57888e-07f,  4.89988e-05f,  0.244326f,     12.4895f, | 
 |   64     19.0f,         47.0f,         106.0f,        538.324f,      564.536f, | 
 |   65     819.124f,      7048.0f,       12611.0f,      19878.0f,      20309.0f, | 
 |   66     797056.0f,     1.77219e+09f,  1.51116e+11f,  4.18193e+13f,  3.59167e+16f, | 
 |   67     3.38211e+19f,  2.67488e+20f,  1.78831e+21f,  9.20914e+21f,  8.35654e+23f, | 
 |   68     1.4495e+24f,   5.94015e+25f,  4.43608e+30f,  2.44502e+33f,  2.61152e+33f, | 
 |   69     1.38178e+37f,  1.71306e+37f,  3.31899e+38f,  3.40282e+38f,  V8_INFINITY}; | 
 |   70  | 
 |   71  | 
|   49 static const double kFloat64Values[] = { |   72 static const double kFloat64Values[] = { | 
|   50     -V8_INFINITY,  -4.23878e+275, -5.82632e+265, -6.60355e+220, -6.26172e+212, |   73     -V8_INFINITY,  -4.23878e+275, -5.82632e+265, -6.60355e+220, -6.26172e+212, | 
|   51     -2.56222e+211, -4.82408e+201, -1.84106e+157, -1.63662e+127, -1.55772e+100, |   74     -2.56222e+211, -4.82408e+201, -1.84106e+157, -1.63662e+127, -1.55772e+100, | 
|   52     -1.67813e+72,  -2.3382e+55,   -3.179e+30,    -1.441e+09,    -1.0647e+09, |   75     -1.67813e+72,  -2.3382e+55,   -3.179e+30,    -1.441e+09,    -1.0647e+09, | 
|   53     -7.99361e+08,  -5.77375e+08,  -2.20984e+08,  -32757,        -13171, |   76     -7.99361e+08,  -5.77375e+08,  -2.20984e+08,  -32757,        -13171, | 
|   54     -9970,         -3984,         -107,          -105,          -92, |   77     -9970,         -3984,         -107,          -105,          -92, | 
|   55     -77,           -61,           -0.000208163,  -1.86685e-06,  -1.17296e-10, |   78     -77,           -61,           -0.000208163,  -1.86685e-06,  -1.17296e-10, | 
|   56     -9.26358e-11,  -5.08004e-60,  -1.74753e-65,  -1.06561e-71,  -5.67879e-79, |   79     -9.26358e-11,  -5.08004e-60,  -1.74753e-65,  -1.06561e-71,  -5.67879e-79, | 
|   57     -5.78459e-130, -2.90989e-171, -7.15489e-243, -3.76242e-252, -1.05639e-263, |   80     -5.78459e-130, -2.90989e-171, -7.15489e-243, -3.76242e-252, -1.05639e-263, | 
|   58     -4.40497e-267, -2.19666e-273, -4.9998e-276,  -5.59821e-278, -2.03855e-282, |   81     -4.40497e-267, -2.19666e-273, -4.9998e-276,  -5.59821e-278, -2.03855e-282, | 
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  199   EXPECT_FALSE(reduction.Changed()); |  222   EXPECT_FALSE(reduction.Changed()); | 
|  200 } |  223 } | 
|  201  |  224  | 
|  202  |  225  | 
|  203 INSTANTIATE_TEST_CASE_P(MachineOperatorReducerTest, |  226 INSTANTIATE_TEST_CASE_P(MachineOperatorReducerTest, | 
|  204                         MachineUnaryOperatorReducerTest, |  227                         MachineUnaryOperatorReducerTest, | 
|  205                         ::testing::ValuesIn(kUnaryOperators)); |  228                         ::testing::ValuesIn(kUnaryOperators)); | 
|  206  |  229  | 
|  207  |  230  | 
|  208 // ----------------------------------------------------------------------------- |  231 // ----------------------------------------------------------------------------- | 
 |  232 // ChangeFloat64ToFloat32 | 
 |  233  | 
 |  234  | 
 |  235 TEST_F(MachineOperatorReducerTest, ChangeFloat64ToFloat32WithConstant) { | 
 |  236   TRACED_FOREACH(float, x, kFloat32Values) { | 
 |  237     Reduction reduction = Reduce(graph()->NewNode( | 
 |  238         machine()->ChangeFloat32ToFloat64(), Float32Constant(x))); | 
 |  239     ASSERT_TRUE(reduction.Changed()); | 
 |  240     EXPECT_THAT(reduction.replacement(), IsFloat64Constant(x)); | 
 |  241   } | 
 |  242 } | 
 |  243  | 
 |  244  | 
 |  245 // ----------------------------------------------------------------------------- | 
|  209 // ChangeFloat64ToInt32 |  246 // ChangeFloat64ToInt32 | 
|  210  |  247  | 
|  211  |  248  | 
|  212 TEST_F(MachineOperatorReducerTest, |  249 TEST_F(MachineOperatorReducerTest, | 
|  213        ChangeFloat64ToInt32WithChangeInt32ToFloat64) { |  250        ChangeFloat64ToInt32WithChangeInt32ToFloat64) { | 
|  214   Node* value = Parameter(0); |  251   Node* value = Parameter(0); | 
|  215   Reduction reduction = Reduce(graph()->NewNode( |  252   Reduction reduction = Reduce(graph()->NewNode( | 
|  216       machine()->ChangeFloat64ToInt32(), |  253       machine()->ChangeFloat64ToInt32(), | 
|  217       graph()->NewNode(machine()->ChangeInt32ToFloat64(), value))); |  254       graph()->NewNode(machine()->ChangeInt32ToFloat64(), value))); | 
|  218   ASSERT_TRUE(reduction.Changed()); |  255   ASSERT_TRUE(reduction.Changed()); | 
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  308         Reduce(graph()->NewNode(machine()->ChangeUint32ToUint64(), |  345         Reduce(graph()->NewNode(machine()->ChangeUint32ToUint64(), | 
|  309                                 Int32Constant(bit_cast<int32_t>(x)))); |  346                                 Int32Constant(bit_cast<int32_t>(x)))); | 
|  310     ASSERT_TRUE(reduction.Changed()); |  347     ASSERT_TRUE(reduction.Changed()); | 
|  311     EXPECT_THAT(reduction.replacement(), |  348     EXPECT_THAT(reduction.replacement(), | 
|  312                 IsInt64Constant(bit_cast<int64_t>(static_cast<uint64_t>(x)))); |  349                 IsInt64Constant(bit_cast<int64_t>(static_cast<uint64_t>(x)))); | 
|  313   } |  350   } | 
|  314 } |  351 } | 
|  315  |  352  | 
|  316  |  353  | 
|  317 // ----------------------------------------------------------------------------- |  354 // ----------------------------------------------------------------------------- | 
 |  355 // TruncateFloat64ToFloat32 | 
 |  356  | 
 |  357  | 
 |  358 TEST_F(MachineOperatorReducerTest, | 
 |  359        TruncateFloat64ToFloat32WithChangeFloat32ToFloat64) { | 
 |  360   Node* value = Parameter(0); | 
 |  361   Reduction reduction = Reduce(graph()->NewNode( | 
 |  362       machine()->TruncateFloat64ToFloat32(), | 
 |  363       graph()->NewNode(machine()->ChangeFloat32ToFloat64(), value))); | 
 |  364   ASSERT_TRUE(reduction.Changed()); | 
 |  365   EXPECT_EQ(value, reduction.replacement()); | 
 |  366 } | 
 |  367  | 
 |  368  | 
 |  369 TEST_F(MachineOperatorReducerTest, TruncateFloat64ToFloat32WithConstant) { | 
 |  370   TRACED_FOREACH(double, x, kFloat64Values) { | 
 |  371     Reduction reduction = Reduce(graph()->NewNode( | 
 |  372         machine()->TruncateFloat64ToFloat32(), Float64Constant(x))); | 
 |  373     ASSERT_TRUE(reduction.Changed()); | 
 |  374     EXPECT_THAT(reduction.replacement(), IsFloat32Constant(DoubleToFloat32(x))); | 
 |  375   } | 
 |  376 } | 
 |  377  | 
 |  378  | 
 |  379 // ----------------------------------------------------------------------------- | 
|  318 // TruncateFloat64ToInt32 |  380 // TruncateFloat64ToInt32 | 
|  319  |  381  | 
|  320  |  382  | 
|  321 TEST_F(MachineOperatorReducerTest, |  383 TEST_F(MachineOperatorReducerTest, | 
|  322        TruncateFloat64ToInt32WithChangeInt32ToFloat64) { |  384        TruncateFloat64ToInt32WithChangeInt32ToFloat64) { | 
|  323   Node* value = Parameter(0); |  385   Node* value = Parameter(0); | 
|  324   Reduction reduction = Reduce(graph()->NewNode( |  386   Reduction reduction = Reduce(graph()->NewNode( | 
|  325       machine()->TruncateFloat64ToInt32(), |  387       machine()->TruncateFloat64ToInt32(), | 
|  326       graph()->NewNode(machine()->ChangeInt32ToFloat64(), value))); |  388       graph()->NewNode(machine()->ChangeInt32ToFloat64(), value))); | 
|  327   ASSERT_TRUE(reduction.Changed()); |  389   ASSERT_TRUE(reduction.Changed()); | 
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  531       r = Reduce(graph()->NewNode(common()->Projection(0), add)); |  593       r = Reduce(graph()->NewNode(common()->Projection(0), add)); | 
|  532       ASSERT_TRUE(r.Changed()); |  594       ASSERT_TRUE(r.Changed()); | 
|  533       EXPECT_THAT(r.replacement(), IsInt32Constant(z)); |  595       EXPECT_THAT(r.replacement(), IsInt32Constant(z)); | 
|  534     } |  596     } | 
|  535   } |  597   } | 
|  536 } |  598 } | 
|  537  |  599  | 
|  538 }  // namespace compiler |  600 }  // namespace compiler | 
|  539 }  // namespace internal |  601 }  // namespace internal | 
|  540 }  // namespace v8 |  602 }  // namespace v8 | 
| OLD | NEW |