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

Side by Side Diff: src/compiler/machine-operator-reducer.cc

Issue 2347573002: [turbofan] Reduce some Float64 division to multiplication (Closed)
Patch Set: Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | test/unittests/compiler/machine-operator-reducer-unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/machine-operator-reducer.h" 5 #include "src/compiler/machine-operator-reducer.h"
6 6
7 #include "src/base/bits.h" 7 #include "src/base/bits.h"
8 #include "src/base/division-by-constant.h" 8 #include "src/base/division-by-constant.h"
9 #include "src/base/ieee754.h" 9 #include "src/base/ieee754.h"
10 #include "src/codegen.h" 10 #include "src/codegen.h"
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 } 405 }
406 case IrOpcode::kFloat64Mul: { 406 case IrOpcode::kFloat64Mul: {
407 Float64BinopMatcher m(node); 407 Float64BinopMatcher m(node);
408 if (m.right().Is(-1)) { // x * -1.0 => -0.0 - x 408 if (m.right().Is(-1)) { // x * -1.0 => -0.0 - x
409 node->ReplaceInput(0, Float64Constant(-0.0)); 409 node->ReplaceInput(0, Float64Constant(-0.0));
410 node->ReplaceInput(1, m.left().node()); 410 node->ReplaceInput(1, m.left().node());
411 NodeProperties::ChangeOp(node, machine()->Float64Sub()); 411 NodeProperties::ChangeOp(node, machine()->Float64Sub());
412 return Changed(node); 412 return Changed(node);
413 } 413 }
414 if (m.right().Is(1)) return Replace(m.left().node()); // x * 1.0 => x 414 if (m.right().Is(1)) return Replace(m.left().node()); // x * 1.0 => x
415 if (m.right().Is(2)) { // x * 2.0 => x + x
Benedikt Meurer 2016/09/15 17:20:52 This should come after the m.IsFoldable case below
416 node->ReplaceInput(1, m.left().node());
417 NodeProperties::ChangeOp(node, machine()->Float64Add());
418 return Changed(node);
419 }
415 if (m.right().IsNaN()) { // x * NaN => NaN 420 if (m.right().IsNaN()) { // x * NaN => NaN
416 return Replace(m.right().node()); 421 return Replace(m.right().node());
417 } 422 }
418 if (m.IsFoldable()) { // K * K => K 423 if (m.IsFoldable()) { // K * K => K
419 return ReplaceFloat64(m.left().Value() * m.right().Value()); 424 return ReplaceFloat64(m.left().Value() * m.right().Value());
420 } 425 }
421 break; 426 break;
422 } 427 }
423 case IrOpcode::kFloat64Div: { 428 case IrOpcode::kFloat64Div: {
424 Float64BinopMatcher m(node); 429 Float64BinopMatcher m(node);
425 if (m.right().Is(1)) return Replace(m.left().node()); // x / 1.0 => x 430 if (m.right().Is(1)) return Replace(m.left().node()); // x / 1.0 => x
431 if (m.right().Is(-1)) { // x / -1.0 => -x
Benedikt Meurer 2016/09/15 17:20:52 Move this below the m.IsFoldable case.
432 node->RemoveInput(1);
433 NodeProperties::ChangeOp(node, machine()->Float64Neg());
434 return Changed(node);
435 }
426 if (m.right().IsNaN()) { // x / NaN => NaN 436 if (m.right().IsNaN()) { // x / NaN => NaN
427 return Replace(m.right().node()); 437 return Replace(m.right().node());
428 } 438 }
429 if (m.left().IsNaN()) { // NaN / x => NaN 439 if (m.left().IsNaN()) { // NaN / x => NaN
430 return Replace(m.left().node()); 440 return Replace(m.left().node());
431 } 441 }
432 if (m.IsFoldable()) { // K / K => K 442 if (m.IsFoldable()) { // K / K => K
433 return ReplaceFloat64(m.left().Value() / m.right().Value()); 443 return ReplaceFloat64(m.left().Value() / m.right().Value());
434 } 444 }
445 if (m.right().HasValue()) {
446 Double k = Double(m.right().Value());
Benedikt Meurer 2016/09/15 17:20:52 Can you add this as a IsPowerOfTwo methd to the Fl
martyn.capewell 2016/09/15 17:41:19 The idea is that all reciprocals of non-denormal p
Benedikt Meurer 2016/09/15 18:20:05 Aye, thanks. Please add a comment.
447 if (!k.IsSpecial() && !k.IsDenormal() &&
448 ((k.AsUint64() & Double::kSignificandMask) == 0)) {
449 // x / K => x * (1 / K) for power-of-two K
450 node->ReplaceInput(1, Float64Constant(1.0 / k.value()));
451 NodeProperties::ChangeOp(node, machine()->Float64Mul());
452 return Changed(node);
453 }
454 }
435 break; 455 break;
436 } 456 }
437 case IrOpcode::kFloat64Mod: { 457 case IrOpcode::kFloat64Mod: {
438 Float64BinopMatcher m(node); 458 Float64BinopMatcher m(node);
439 if (m.right().Is(0)) { // x % 0 => NaN 459 if (m.right().Is(0)) { // x % 0 => NaN
440 return ReplaceFloat64(std::numeric_limits<double>::quiet_NaN()); 460 return ReplaceFloat64(std::numeric_limits<double>::quiet_NaN());
441 } 461 }
442 if (m.right().IsNaN()) { // x % NaN => NaN 462 if (m.right().IsNaN()) { // x % NaN => NaN
443 return Replace(m.right().node()); 463 return Replace(m.right().node());
444 } 464 }
(...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 MachineOperatorBuilder* MachineOperatorReducer::machine() const { 1391 MachineOperatorBuilder* MachineOperatorReducer::machine() const {
1372 return jsgraph()->machine(); 1392 return jsgraph()->machine();
1373 } 1393 }
1374 1394
1375 1395
1376 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } 1396 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); }
1377 1397
1378 } // namespace compiler 1398 } // namespace compiler
1379 } // namespace internal 1399 } // namespace internal
1380 } // namespace v8 1400 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/unittests/compiler/machine-operator-reducer-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698