[turbofan] Fix ReduceWord64Xor
This CL fixes the bug where x ^ x is reduced to Int32Constant(0) for both word32 and word64. Bug: chromium:1383362, v8:9407 Change-Id: I8a2ed879f0626071f560cc5ba8c21ef2d4107e62 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4020424 Reviewed-by: Nico Hartmann <nicohartmann@chromium.org> Commit-Queue: Qifan Pan <panq@google.com> Cr-Commit-Position: refs/heads/main@{#84218}
This commit is contained in:
parent
9edf440151
commit
1113057e3e
@ -2128,7 +2128,7 @@ Reduction MachineOperatorReducer::ReduceWordNXor(Node* node) {
|
|||||||
if (m.IsFoldable()) { // K ^ K => K (K stands for arbitrary constants)
|
if (m.IsFoldable()) { // K ^ K => K (K stands for arbitrary constants)
|
||||||
return a.ReplaceIntN(m.left().ResolvedValue() ^ m.right().ResolvedValue());
|
return a.ReplaceIntN(m.left().ResolvedValue() ^ m.right().ResolvedValue());
|
||||||
}
|
}
|
||||||
if (m.LeftEqualsRight()) return ReplaceInt32(0); // x ^ x => 0
|
if (m.LeftEqualsRight()) return Replace(a.IntNConstant(0)); // x ^ x => 0
|
||||||
if (A::IsWordNXor(m.left()) && m.right().Is(-1)) {
|
if (A::IsWordNXor(m.left()) && m.right().Is(-1)) {
|
||||||
typename A::IntNBinopMatcher mleft(m.left().node());
|
typename A::IntNBinopMatcher mleft(m.left().node());
|
||||||
if (mleft.right().Is(-1)) { // (x ^ -1) ^ -1 => x
|
if (mleft.right().Is(-1)) { // (x ^ -1) ^ -1 => x
|
||||||
|
17
test/mjsunit/regress/regress-1383362.js
Normal file
17
test/mjsunit/regress/regress-1383362.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright 2022 the V8 project authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
// Flags: --allow-natives-syntax
|
||||||
|
|
||||||
|
function f(x) {
|
||||||
|
for (let i = 0; i < 1; ++i) {
|
||||||
|
x ^= x;
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
%PrepareFunctionForOptimization(f);
|
||||||
|
f(1n);
|
||||||
|
%OptimizeFunctionOnNextCall(f);
|
||||||
|
f(1n);
|
Loading…
Reference in New Issue
Block a user