[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:
Qifan Pan 2022-11-11 15:03:27 +01:00 committed by V8 LUCI CQ
parent 9edf440151
commit 1113057e3e
2 changed files with 18 additions and 1 deletions

View File

@ -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

View 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);