[turbofan] Add new reduction to MachineOperatorReducer

This CL adds "(x + x) & 1 => 0" reduction to WordAnd, which helps to
eliminate the branch in below codes:

  5191: Int32Constant(1)
  1725: Int32Add(1724, 1724)
  1726: ChangeUint32ToUint64(1725)
  1729: TruncateInt64ToInt32(1726)
  1730: Word32And(1729, 5191)
  1732: Branch(1730, 1721)

Change-Id: I0dbcd97f8edf27b766a023116409d8ed1524e369
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3787318
Commit-Queue: Hao A Xu <hao.a.xu@intel.com>
Reviewed-by: Nico Hartmann <nicohartmann@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81964}
This commit is contained in:
Hao Xu 2022-07-26 19:45:56 +08:00 committed by V8 LUCI CQ
parent 1078ab7666
commit 0fe727c1ed

View File

@ -1664,6 +1664,20 @@ Reduction MachineOperatorReducer::ReduceWordNAnd(Node* node) {
typename A::IntNBinopMatcher m(node);
if (m.right().Is(0)) return Replace(m.right().node()); // x & 0 => 0
if (m.right().Is(-1)) return Replace(m.left().node()); // x & -1 => x
if (m.right().Is(1)) {
// (x + x) & 1 => 0
Node* left = m.left().node();
while (left->opcode() == IrOpcode::kTruncateInt64ToInt32 ||
left->opcode() == IrOpcode::kChangeInt32ToInt64 ||
left->opcode() == IrOpcode::kChangeUint32ToUint64) {
left = left->InputAt(0);
}
if ((left->opcode() == IrOpcode::kInt32Add ||
left->opcode() == IrOpcode::kInt64Add) &&
left->InputAt(0) == left->InputAt(1)) {
return a.ReplaceIntN(0);
}
}
if (m.left().IsComparison() && m.right().Is(1)) { // CMP & 1 => CMP
return Replace(m.left().node());
}