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/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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 case IrOpcode::kUint32LessThanOrEqual: { | 307 case IrOpcode::kUint32LessThanOrEqual: { |
308 Uint32BinopMatcher m(node); | 308 Uint32BinopMatcher m(node); |
309 if (m.left().Is(0)) return ReplaceBool(true); // 0 <= x => true | 309 if (m.left().Is(0)) return ReplaceBool(true); // 0 <= x => true |
310 if (m.right().Is(kMaxUInt32)) return ReplaceBool(true); // x <= M => true | 310 if (m.right().Is(kMaxUInt32)) return ReplaceBool(true); // x <= M => true |
311 if (m.IsFoldable()) { // K <= K => K | 311 if (m.IsFoldable()) { // K <= K => K |
312 return ReplaceBool(m.left().Value() <= m.right().Value()); | 312 return ReplaceBool(m.left().Value() <= m.right().Value()); |
313 } | 313 } |
314 if (m.LeftEqualsRight()) return ReplaceBool(true); // x <= x => true | 314 if (m.LeftEqualsRight()) return ReplaceBool(true); // x <= x => true |
315 break; | 315 break; |
316 } | 316 } |
| 317 case IrOpcode::kFloat32Sub: { |
| 318 Float32BinopMatcher m(node); |
| 319 if (m.right().Is(0) && (copysign(1.0, m.right().Value()) > 0)) { |
| 320 return Replace(m.left().node()); // x - 0 => x |
| 321 } |
| 322 if (m.right().IsNaN()) { // x - NaN => NaN |
| 323 return Replace(m.right().node()); |
| 324 } |
| 325 if (m.left().IsNaN()) { // NaN - x => NaN |
| 326 return Replace(m.left().node()); |
| 327 } |
| 328 if (m.IsFoldable()) { // L - R => (L - R) |
| 329 return ReplaceFloat32(m.left().Value() - m.right().Value()); |
| 330 } |
| 331 if (m.left().IsMinusZero()) { |
| 332 // -0.0 - round_down(-0.0 - R) => round_up(R) |
| 333 if (machine()->Float32RoundUp().IsSupported() && |
| 334 m.right().IsFloat32RoundDown()) { |
| 335 if (m.right().InputAt(0)->opcode() == IrOpcode::kFloat32Sub) { |
| 336 Float32BinopMatcher mright0(m.right().InputAt(0)); |
| 337 if (mright0.left().IsMinusZero()) { |
| 338 return Replace(graph()->NewNode(machine()->Float32RoundUp().op(), |
| 339 mright0.right().node())); |
| 340 } |
| 341 } |
| 342 } |
| 343 // -0.0 - R => -R |
| 344 node->RemoveInput(0); |
| 345 NodeProperties::ChangeOp(node, machine()->Float32Neg()); |
| 346 return Changed(node); |
| 347 } |
| 348 break; |
| 349 } |
317 case IrOpcode::kFloat64Add: { | 350 case IrOpcode::kFloat64Add: { |
318 Float64BinopMatcher m(node); | 351 Float64BinopMatcher m(node); |
319 if (m.right().IsNaN()) { // x + NaN => NaN | 352 if (m.right().IsNaN()) { // x + NaN => NaN |
320 return Replace(m.right().node()); | 353 return Replace(m.right().node()); |
321 } | 354 } |
322 if (m.IsFoldable()) { // K + K => K | 355 if (m.IsFoldable()) { // K + K => K |
323 return ReplaceFloat64(m.left().Value() + m.right().Value()); | 356 return ReplaceFloat64(m.left().Value() + m.right().Value()); |
324 } | 357 } |
325 break; | 358 break; |
326 } | 359 } |
327 case IrOpcode::kFloat64Sub: { | 360 case IrOpcode::kFloat64Sub: { |
328 Float64BinopMatcher m(node); | 361 Float64BinopMatcher m(node); |
329 if (m.right().Is(0) && (Double(m.right().Value()).Sign() > 0)) { | 362 if (m.right().Is(0) && (Double(m.right().Value()).Sign() > 0)) { |
330 return Replace(m.left().node()); // x - 0 => x | 363 return Replace(m.left().node()); // x - 0 => x |
331 } | 364 } |
332 if (m.right().IsNaN()) { // x - NaN => NaN | 365 if (m.right().IsNaN()) { // x - NaN => NaN |
333 return Replace(m.right().node()); | 366 return Replace(m.right().node()); |
334 } | 367 } |
335 if (m.left().IsNaN()) { // NaN - x => NaN | 368 if (m.left().IsNaN()) { // NaN - x => NaN |
336 return Replace(m.left().node()); | 369 return Replace(m.left().node()); |
337 } | 370 } |
338 if (m.IsFoldable()) { // K - K => K | 371 if (m.IsFoldable()) { // L - R => (L - R) |
339 return ReplaceFloat64(m.left().Value() - m.right().Value()); | 372 return ReplaceFloat64(m.left().Value() - m.right().Value()); |
340 } | 373 } |
| 374 if (m.left().IsMinusZero()) { |
| 375 // -0.0 - round_down(-0.0 - R) => round_up(R) |
| 376 if (machine()->Float64RoundUp().IsSupported() && |
| 377 m.right().IsFloat64RoundDown()) { |
| 378 if (m.right().InputAt(0)->opcode() == IrOpcode::kFloat64Sub) { |
| 379 Float64BinopMatcher mright0(m.right().InputAt(0)); |
| 380 if (mright0.left().IsMinusZero()) { |
| 381 return Replace(graph()->NewNode(machine()->Float64RoundUp().op(), |
| 382 mright0.right().node())); |
| 383 } |
| 384 } |
| 385 } |
| 386 // -0.0 - R => -R |
| 387 node->RemoveInput(0); |
| 388 NodeProperties::ChangeOp(node, machine()->Float64Neg()); |
| 389 return Changed(node); |
| 390 } |
341 break; | 391 break; |
342 } | 392 } |
343 case IrOpcode::kFloat64Mul: { | 393 case IrOpcode::kFloat64Mul: { |
344 Float64BinopMatcher m(node); | 394 Float64BinopMatcher m(node); |
345 if (m.right().Is(-1)) { // x * -1.0 => -0.0 - x | 395 if (m.right().Is(-1)) { // x * -1.0 => -0.0 - x |
346 node->ReplaceInput(0, Float64Constant(-0.0)); | 396 node->ReplaceInput(0, Float64Constant(-0.0)); |
347 node->ReplaceInput(1, m.left().node()); | 397 node->ReplaceInput(1, m.left().node()); |
348 NodeProperties::ChangeOp(node, machine()->Float64Sub()); | 398 NodeProperties::ChangeOp(node, machine()->Float64Sub()); |
349 return Changed(node); | 399 return Changed(node); |
350 } | 400 } |
(...skipping 981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1332 MachineOperatorBuilder* MachineOperatorReducer::machine() const { | 1382 MachineOperatorBuilder* MachineOperatorReducer::machine() const { |
1333 return jsgraph()->machine(); | 1383 return jsgraph()->machine(); |
1334 } | 1384 } |
1335 | 1385 |
1336 | 1386 |
1337 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } | 1387 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } |
1338 | 1388 |
1339 } // namespace compiler | 1389 } // namespace compiler |
1340 } // namespace internal | 1390 } // namespace internal |
1341 } // namespace v8 | 1391 } // namespace v8 |
OLD | NEW |