Commit 4927d9b5 authored by Leszek Swirski's avatar Leszek Swirski Committed by V8 LUCI CQ

Revert "[compiler] Improve code generated for patterns like "x >> 1 == 0""

This reverts commit 2dc40370.

Reason for revert: Broke in UBSan: https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Linux64%20UBSan/20397/overview

Original change's description:
> [compiler] Improve code generated for patterns like "x >> 1 == 0"
>
> Change-Id: I79575ba61a3bdea93468f48d66a3cb3edd0e1442
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3506504
> Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
> Commit-Queue: Darius Mercadier <dmercadier@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#79419}

Change-Id: I489440d7cbd46763d496c6d22190240c5676e486
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3513893
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Owners-Override: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#79422}
parent 79dfd0eb
......@@ -1354,7 +1354,7 @@ Reduction MachineOperatorReducer::ReduceWord32Comparisons(Node* node) {
node->opcode() == IrOpcode::kUint32LessThan ||
node->opcode() == IrOpcode::kUint32LessThanOrEqual);
Int32BinopMatcher m(node);
// (x >> K) < (y >> K) => x < y if only zeros shifted out
// (x >>> K) < (y >>> K) => x < y if only zeros shifted out
if (m.left().op() == machine()->Word32SarShiftOutZeros() &&
m.right().op() == machine()->Word32SarShiftOutZeros()) {
Int32BinopMatcher mleft(m.left().node());
......@@ -1366,42 +1366,6 @@ Reduction MachineOperatorReducer::ReduceWord32Comparisons(Node* node) {
return Changed(node);
}
}
// Simplifying (x >> n) <= k into x <= (k << n), with "k << n" being
// computed here at compile time.
if (m.right().HasResolvedValue() &&
m.left().op() == machine()->Word32SarShiftOutZeros()) {
uint32_t right = m.right().ResolvedValue();
Int32BinopMatcher mleft(m.left().node());
if (mleft.right().HasResolvedValue()) {
auto shift = mleft.right().ResolvedValue();
// Making sure that no significant bits will be shifted away.
if (shift >= 0 && shift <= 32 &&
(static_cast<int32_t>(right) << shift >> shift ==
static_cast<int32_t>(right))) {
node->ReplaceInput(0, mleft.left().node());
node->ReplaceInput(1, Int32Constant(right << shift));
return Changed(node);
}
}
}
// Simplifying k <= (x >> n) into (k << n) <= x, with "k << n" being
// computed here at compile time.
if (m.left().HasResolvedValue() &&
m.right().op() == machine()->Word32SarShiftOutZeros()) {
uint32_t left = m.left().ResolvedValue();
Int32BinopMatcher mright(m.right().node());
if (mright.right().HasResolvedValue()) {
auto shift = mright.right().ResolvedValue();
// Making sure that no significant bits will be shifted away.
if (shift >= 0 && shift <= 32 &&
(static_cast<int32_t>(left) << shift >> shift ==
static_cast<int32_t>(left))) {
node->ReplaceInput(0, Int32Constant(left << shift));
node->ReplaceInput(1, mright.left().node());
return Changed(node);
}
}
}
return NoChange();
}
......@@ -1441,7 +1405,7 @@ Reduction MachineOperatorReducer::ReduceWord64Comparisons(Node* node) {
return Changed(node).FollowedBy(Reduce(node));
}
// (x >> K) < (y >> K) => x < y if only zeros shifted out
// (x >>> K) < (y >>> K) => x < y if only zeros shifted out
// This is useful for Smi untagging, which results in such a shift.
if (m.left().op() == machine()->Word64SarShiftOutZeros() &&
m.right().op() == machine()->Word64SarShiftOutZeros()) {
......@@ -2238,21 +2202,6 @@ MachineOperatorReducer::ReduceWord32EqualForConstantRhs(Node* lhs,
}
}
}
// Replaces (x >> n) == k with x == k << n, with "k << n" being computed
// here at compile time.
if (lhs->op() == machine()->Word32SarShiftOutZeros() &&
lhs->UseCount() == 1) {
typename WordNAdapter::UintNBinopMatcher mshift(lhs);
if (mshift.right().HasResolvedValue()) {
auto shift = mshift.right().ResolvedValue();
// Making sure that no significant bits will be shifted away.
if (shift > 0 && shift < 32 &&
(static_cast<int32_t>(rhs) << shift >> shift ==
static_cast<int32_t>(rhs))) {
return std::make_pair(mshift.left().node(), rhs << shift);
}
}
}
return {};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment