From 3d46a713bb1443699d1fb8afb2a413c5efe5431a Mon Sep 17 00:00:00 2001 From: Michael Achenbach Date: Tue, 20 Dec 2022 07:25:06 +0000 Subject: [PATCH] Revert "[turbofan] Simplifying (x+k1)==k2 into x==(k2-k1)" This reverts commit e9333ebd3cfbb27af8d6f61bdd32de5b242f4a35. Reason for revert: https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Linux64%20UBSan/24520/overview Original change's description: > [turbofan] Simplifying (x+k1)==k2 into x==(k2-k1) > > > Change-Id: I234da79e1f53fa0fc15494fe6d31742d4e6eea97 > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4055393 > Commit-Queue: Jianxiao Lu > Reviewed-by: Tobias Tebbi > Cr-Commit-Position: refs/heads/main@{#84947} Change-Id: I9e86f6f9653efff0fd0da439e270df5c7da29b20 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4111953 Auto-Submit: Michael Achenbach Bot-Commit: Rubber Stamper Owners-Override: Michael Achenbach Commit-Queue: Michael Achenbach Cr-Commit-Position: refs/heads/main@{#84948} --- src/compiler/machine-operator-reducer.cc | 26 ------- .../machine-operator-reducer-unittest.cc | 75 ------------------- 2 files changed, 101 deletions(-) diff --git a/src/compiler/machine-operator-reducer.cc b/src/compiler/machine-operator-reducer.cc index 66b3969974..5b21a1d652 100644 --- a/src/compiler/machine-operator-reducer.cc +++ b/src/compiler/machine-operator-reducer.cc @@ -2551,19 +2551,6 @@ Reduction MachineOperatorReducer::ReduceWord32Equal(Node* node) { node->ReplaceInput(1, Uint32Constant(replacements->second)); return Changed(node); } - - // Simplifying (x+k1)==k2 into x==k2-k1. - if (m.left().IsInt32Add() && m.right().IsInt32Constant()) { - Int32AddMatcher m_add(m.left().node()); - if (m_add.right().IsInt32Constant()) { - int32_t lte_right = m.right().ResolvedValue(); - int32_t add_right = m_add.right().ResolvedValue(); - // No need to consider overflow in this condition (==). - node->ReplaceInput(0, m_add.left().node()); - node->ReplaceInput(1, Int32Constant(lte_right - add_right)); - return Changed(node); - } - } } return NoChange(); @@ -2592,19 +2579,6 @@ Reduction MachineOperatorReducer::ReduceWord64Equal(Node* node) { return Changed(node); } - // Simplifying (x+k1)==k2 into x==k2-k1. - if (m.left().IsInt64Add() && m.right().IsInt64Constant()) { - Int64AddMatcher m_add(m.left().node()); - if (m_add.right().IsInt64Constant()) { - int64_t lte_right = m.right().ResolvedValue(); - int64_t add_right = m_add.right().ResolvedValue(); - // No need to consider overflow in this condition (==). - node->ReplaceInput(0, m_add.left().node()); - node->ReplaceInput(1, Int64Constant(lte_right - add_right)); - return Changed(node); - } - } - /* If Int64Constant(c) can be casted from an Int32Constant: ------------------------------------------------- diff --git a/test/unittests/compiler/machine-operator-reducer-unittest.cc b/test/unittests/compiler/machine-operator-reducer-unittest.cc index 669f941148..9fa005ff72 100644 --- a/test/unittests/compiler/machine-operator-reducer-unittest.cc +++ b/test/unittests/compiler/machine-operator-reducer-unittest.cc @@ -4,7 +4,6 @@ #include "src/compiler/machine-operator-reducer.h" -#include #include #include "src/base/bits.h" @@ -12,7 +11,6 @@ #include "src/base/ieee754.h" #include "src/base/overflowing-math.h" #include "src/builtins/builtins.h" -#include "src/common/globals.h" #include "src/compiler/js-graph.h" #include "src/compiler/machine-operator.h" #include "src/numbers/conversions-inl.h" @@ -1400,21 +1398,6 @@ TEST_F(MachineOperatorReducerTest, } } -TEST_F(MachineOperatorReducerTest, Word32EqualWithAddAndConstant) { - // (x+k1)==k2 => x==(k2-k1) - Node* const p0 = Parameter(0); - TRACED_FOREACH(int32_t, k1, kInt32Values) { - TRACED_FOREACH(int32_t, k2, kInt32Values) { - Node* node = graph()->NewNode( - machine()->Word32Equal(), - graph()->NewNode(machine()->Int32Add(), p0, Int32Constant(k1)), - Int32Constant(k2)); - Reduction r = Reduce(node); - ASSERT_TRUE(r.Changed()); - } - } -} - // ----------------------------------------------------------------------------- // Word64Equal @@ -1453,21 +1436,6 @@ TEST_F(MachineOperatorReducerTest, } } -TEST_F(MachineOperatorReducerTest, Word64EqualWithAddAndConstant) { - // (x+k1)==k2 => x==(k2-k1) - Node* const p0 = Parameter(0); - TRACED_FOREACH(int64_t, k1, kInt64Values) { - TRACED_FOREACH(int64_t, k2, kInt64Values) { - Node* node = graph()->NewNode( - machine()->Word64Equal(), - graph()->NewNode(machine()->Int64Add(), p0, Int64Constant(k1)), - Int64Constant(k2)); - Reduction r = Reduce(node); - ASSERT_TRUE(r.Changed()); - } - } -} - // ----------------------------------------------------------------------------- // Branch @@ -2616,49 +2584,6 @@ TEST_F(MachineOperatorReducerTest, Uint64LessThanWithUint32Reduction) { } } -TEST_F(MachineOperatorReducerTest, Uint64LessThanWithInt64AddDontReduce) { - Node* const p0 = Parameter(0); - - TRACED_FOREACH(uint64_t, k1, kUint64Values) { - TRACED_FOREACH(uint64_t, k2, kUint64Values) { - Node* node = graph()->NewNode( - machine()->Uint64LessThan(), - graph()->NewNode(machine()->Int64Add(), p0, Int64Constant(k1)), - Int64Constant(k2)); - Reduction r = Reduce(node); - // Don't reduce because of potential overflow - ASSERT_FALSE(r.Changed()); - } - } -} - -TEST_F(MachineOperatorReducerTest, - Uint64LessThanOrEqualWithInt64AddDontReduce) { - Node* const p0 = Parameter(0); - - TRACED_FOREACH(uint64_t, k1, kUint64Values) { - TRACED_FOREACH(uint64_t, k2, kUint64Values) { - uint64_t k1 = 0; - uint64_t k2 = 18446744073709551615u; - Node* node = graph()->NewNode( - machine()->Uint64LessThanOrEqual(), - graph()->NewNode(machine()->Int64Add(), p0, Int64Constant(k1)), - Int64Constant(k2)); - Reduction r = Reduce(node); - if (k2 == 0) { - // x <= 0 => x == 0 - ASSERT_TRUE(r.Changed()); - } else if (k2 == std::numeric_limits::max()) { - // x <= Max => true - ASSERT_TRUE(r.Changed()); - } else { - // Don't reduce because of potential overflow - ASSERT_FALSE(r.Changed()); - } - } - } -} - // ----------------------------------------------------------------------------- // Int64LessThan