Commit 1d99ca6c authored by Darius M's avatar Darius M Committed by V8 LUCI CQ

[compiler] More optimal code generation for patterns like "x >> 1 == 0"

CL https://chromium-review.googlesource.com/c/v8/v8/+/3514072 tried to
improve code generation for patterns like "x >> n == k" when n and k
are constant, and to generate instead "x == k << n" (with "k << n"
being computed at compile time).

However, this was also done when "x >> n" was reused later, which
caused "x" to be kept alive longer that it could have, which could
increase register pressure.

This CL thus ensures that this optimization is done only if "x >> n"
has a single use.

Bug: chromium:1305389
Change-Id: I377e120c4825e2a0deb4a5478138da838bcebc77
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3528987Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Darius Mercadier <dmercadier@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79502}
parent 7633fbc9
......@@ -1389,7 +1389,8 @@ Reduction MachineOperatorReducer::ReduceWord32Comparisons(Node* 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()) {
m.left().op() == machine()->Word32SarShiftOutZeros() &&
m.left().node()->UseCount() == 1) {
uint32_t right = m.right().ResolvedValue();
Int32BinopMatcher mleft(m.left().node());
if (mleft.right().HasResolvedValue()) {
......@@ -1404,7 +1405,8 @@ Reduction MachineOperatorReducer::ReduceWord32Comparisons(Node* 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()) {
m.right().op() == machine()->Word32SarShiftOutZeros() &&
m.right().node()->UseCount() == 1) {
uint32_t left = m.left().ResolvedValue();
Int32BinopMatcher mright(m.right().node());
if (mright.right().HasResolvedValue()) {
......
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