 Chromium Code Reviews
 Chromium Code Reviews Issue 2141953002:
  [Turbofan]: Add integer multiplication with overflow to typed lowering.  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@multiply
    
  
    Issue 2141953002:
  [Turbofan]: Add integer multiplication with overflow to typed lowering.  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@multiply| 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/compiler/simplified-lowering.h" | 5 #include "src/compiler/simplified-lowering.h" | 
| 6 | 6 | 
| 7 #include <limits> | 7 #include <limits> | 
| 8 | 8 | 
| 9 #include "src/address-map.h" | 9 #include "src/address-map.h" | 
| 10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" | 
| (...skipping 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1306 // => signed Int32Add/Sub (truncated) | 1306 // => signed Int32Add/Sub (truncated) | 
| 1307 VisitWord32TruncatingBinop(node); | 1307 VisitWord32TruncatingBinop(node); | 
| 1308 if (lower()) NodeProperties::ChangeOp(node, Int32Op(node)); | 1308 if (lower()) NodeProperties::ChangeOp(node, Int32Op(node)); | 
| 1309 } else { | 1309 } else { | 
| 1310 // => Float64Add/Sub | 1310 // => Float64Add/Sub | 
| 1311 VisitFloat64Binop(node); | 1311 VisitFloat64Binop(node); | 
| 1312 if (lower()) NodeProperties::ChangeOp(node, Float64Op(node)); | 1312 if (lower()) NodeProperties::ChangeOp(node, Float64Op(node)); | 
| 1313 } | 1313 } | 
| 1314 return; | 1314 return; | 
| 1315 } | 1315 } | 
| 1316 case IrOpcode::kSpeculativeNumberMultiply: | 1316 case IrOpcode::kSpeculativeNumberMultiply: { | 
| 1317 case IrOpcode::kNumberMultiply: { | |
| 1318 if (BothInputsAre(node, Type::Integral32()) && | 1317 if (BothInputsAre(node, Type::Integral32()) && | 
| 1319 (NodeProperties::GetType(node)->Is(Type::Signed32()) || | 1318 (NodeProperties::GetType(node)->Is(Type::Signed32()) || | 
| 1320 NodeProperties::GetType(node)->Is(Type::Unsigned32()) || | 1319 NodeProperties::GetType(node)->Is(Type::Unsigned32()) || | 
| 1321 (truncation.TruncatesToWord32() && | 1320 (truncation.TruncatesToWord32() && | 
| 1322 NodeProperties::GetType(node)->Is( | 1321 NodeProperties::GetType(node)->Is( | 
| 1323 type_cache_.kSafeIntegerOrMinusZero)))) { | 1322 type_cache_.kSafeIntegerOrMinusZero)))) { | 
| 1324 // Multiply reduces to Int32Mul if the inputs are integers, and | 1323 // Multiply reduces to Int32Mul if the inputs are integers, and | 
| 1325 // (a) the output is either known to be Signed32, or | 1324 // (a) the output is either known to be Signed32, or | 
| 1326 // (b) the output is known to be Unsigned32, or | 1325 // (b) the output is known to be Unsigned32, or | 
| 1327 // (c) the uses are truncating and the result is in the safe | 1326 // (c) the uses are truncating and the result is in the safe | 
| 1328 // integer range. | 1327 // integer range. | 
| 1329 VisitWord32TruncatingBinop(node); | 1328 VisitWord32TruncatingBinop(node); | 
| 1330 if (lower()) ChangeToPureOp(node, Int32Op(node)); | 1329 if (lower()) ChangeToPureOp(node, Int32Op(node)); | 
| 1331 return; | 1330 return; | 
| 1332 } | 1331 } | 
| 1332 // Try to use type feedback. | |
| 1333 BinaryOperationHints::Hint hint = BinaryOperationHintOf(node->op()); | |
| 1334 | |
| 1335 // Handle the case when no int32 checks on inputs are necessary | |
| 1336 // (but an overflow check is needed on the output). | |
| 1337 if (BothInputsAre(node, Type::Signed32())) { | |
| 1338 // If both the inputs the feedback are int32, use the overflow op. | |
| 1339 if (hint == BinaryOperationHints::kSignedSmall || | |
| 1340 hint == BinaryOperationHints::kSigned32) { | |
| 1341 VisitBinop(node, UseInfo::TruncatingWord32(), | |
| 1342 MachineRepresentation::kWord32, Type::Signed32()); | |
| 1343 if (lower()) ChangeToInt32OverflowOp(node); | |
| 1344 return; | |
| 1345 } | |
| 1346 } | |
| 1347 | |
| 1348 if (hint == BinaryOperationHints::kSignedSmall || | |
| 1349 hint == BinaryOperationHints::kSigned32) { | |
| 1350 // If the result is truncated, we only need to check the inputs. | |
| 
Benedikt Meurer
2016/07/14 12:08:22
Also as discussed offline, this code is wrong, ple
 | |
| 1351 if (truncation.TruncatesToWord32()) { | |
| 1352 VisitBinop(node, UseInfo::CheckedSigned32AsWord32(), | |
| 1353 MachineRepresentation::kWord32); | |
| 1354 if (lower()) ChangeToPureOp(node, Int32Op(node)); | |
| 1355 } else { | |
| 1356 VisitBinop(node, UseInfo::CheckedSigned32AsWord32(), | |
| 1357 MachineRepresentation::kWord32, Type::Signed32()); | |
| 1358 if (lower()) ChangeToInt32OverflowOp(node); | |
| 1359 } | |
| 1360 return; | |
| 1361 } | |
| 1362 | |
| 1333 // Number x Number => Float64Mul | 1363 // Number x Number => Float64Mul | 
| 1334 if (BothInputsAre(node, Type::NumberOrUndefined())) { | 1364 if (BothInputsAre(node, Type::Number())) { | 
| 
Benedikt Meurer
2016/07/14 11:43:00
This whole if block is redundant. Drop it as well.
 | |
| 1335 VisitFloat64Binop(node); | 1365 VisitFloat64Binop(node); | 
| 1336 if (lower()) ChangeToPureOp(node, Float64Op(node)); | 1366 if (lower()) ChangeToPureOp(node, Float64Op(node)); | 
| 1337 return; | 1367 return; | 
| 1338 } | 1368 } | 
| 1339 // Checked float64 x float64 => float64 | 1369 // Checked float64 x float64 => float64 | 
| 1340 DCHECK_EQ(IrOpcode::kSpeculativeNumberMultiply, node->opcode()); | |
| 1341 VisitBinop(node, UseInfo::CheckedNumberOrOddballAsFloat64(), | 1370 VisitBinop(node, UseInfo::CheckedNumberOrOddballAsFloat64(), | 
| 1342 MachineRepresentation::kFloat64, Type::Number()); | 1371 MachineRepresentation::kFloat64, Type::Number()); | 
| 1343 if (lower()) ChangeToPureOp(node, Float64Op(node)); | 1372 if (lower()) ChangeToPureOp(node, Float64Op(node)); | 
| 1344 return; | 1373 return; | 
| 1345 } | 1374 } | 
| 1375 case IrOpcode::kNumberMultiply: { | |
| 1376 if (BothInputsAre(node, Type::Integral32()) && | |
| 1377 (NodeProperties::GetType(node)->Is(Type::Signed32()) || | |
| 1378 NodeProperties::GetType(node)->Is(Type::Unsigned32()) || | |
| 1379 (truncation.TruncatesToWord32() && | |
| 1380 NodeProperties::GetType(node)->Is( | |
| 1381 type_cache_.kSafeIntegerOrMinusZero)))) { | |
| 1382 // Multiply reduces to Int32Mul if the inputs are integers, and | |
| 1383 // (a) the output is either known to be Signed32, or | |
| 1384 // (b) the output is known to be Unsigned32, or | |
| 1385 // (c) the uses are truncating and the result is in the safe | |
| 1386 // integer range. | |
| 1387 VisitWord32TruncatingBinop(node); | |
| 1388 if (lower()) ChangeToPureOp(node, Int32Op(node)); | |
| 1389 return; | |
| 1390 } | |
| 1391 // Number x Number => Float64Mul | |
| 1392 VisitFloat64Binop(node); | |
| 1393 if (lower()) ChangeToPureOp(node, Float64Op(node)); | |
| 1394 return; | |
| 1395 } | |
| 1346 case IrOpcode::kSpeculativeNumberDivide: { | 1396 case IrOpcode::kSpeculativeNumberDivide: { | 
| 1347 if (BothInputsAreUnsigned32(node) && truncation.TruncatesToWord32()) { | 1397 if (BothInputsAreUnsigned32(node) && truncation.TruncatesToWord32()) { | 
| 1348 // => unsigned Uint32Div | 1398 // => unsigned Uint32Div | 
| 1349 VisitWord32TruncatingBinop(node); | 1399 VisitWord32TruncatingBinop(node); | 
| 1350 if (lower()) DeferReplacement(node, lowering->Uint32Div(node)); | 1400 if (lower()) DeferReplacement(node, lowering->Uint32Div(node)); | 
| 1351 return; | 1401 return; | 
| 1352 } | 1402 } | 
| 1353 if (BothInputsAreSigned32(node)) { | 1403 if (BothInputsAreSigned32(node)) { | 
| 1354 if (NodeProperties::GetType(node)->Is(Type::Signed32())) { | 1404 if (NodeProperties::GetType(node)->Is(Type::Signed32())) { | 
| 1355 // => signed Int32Div | 1405 // => signed Int32Div | 
| (...skipping 1913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3269 isolate(), graph()->zone(), callable.descriptor(), 0, flags, | 3319 isolate(), graph()->zone(), callable.descriptor(), 0, flags, | 
| 3270 Operator::kNoProperties); | 3320 Operator::kNoProperties); | 
| 3271 to_number_operator_.set(common()->Call(desc)); | 3321 to_number_operator_.set(common()->Call(desc)); | 
| 3272 } | 3322 } | 
| 3273 return to_number_operator_.get(); | 3323 return to_number_operator_.get(); | 
| 3274 } | 3324 } | 
| 3275 | 3325 | 
| 3276 } // namespace compiler | 3326 } // namespace compiler | 
| 3277 } // namespace internal | 3327 } // namespace internal | 
| 3278 } // namespace v8 | 3328 } // namespace v8 | 
| OLD | NEW |