[compiler][arm64] Add 64-bit UBFIZ and improve Turboshaft selection [v8/v8 : main]

0 views
Skip to first unread message

Marco Vitale (Gerrit)

unread,
Apr 1, 2026, 10:15:30 AM (5 days ago) Apr 1
to Darius Mercadier, Arash Kazemi, V8 LUCI CQ, chrom...@appspot.gserviceaccount.com, dmercadi...@chromium.org, v8-re...@googlegroups.com
Attention needed from Darius Mercadier

New activity on the change

Open in Gerrit

Related details

Attention is currently required from:
  • Darius Mercadier
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: v8/v8
Gerrit-Branch: main
Gerrit-Change-Id: Ieff7eb86d676ff2fc4619d1577b8532a48db6610
Gerrit-Change-Number: 7706001
Gerrit-PatchSet: 5
Gerrit-Owner: Marco Vitale <mrc...@chromium.org>
Gerrit-Reviewer: Darius Mercadier <dmerc...@chromium.org>
Gerrit-Reviewer: Marco Vitale <mrc...@chromium.org>
Gerrit-CC: Arash Kazemi <ara...@chromium.org>
Gerrit-Attention: Darius Mercadier <dmerc...@chromium.org>
Gerrit-Comment-Date: Wed, 01 Apr 2026 14:15:26 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
unsatisfied_requirement
open
diffy

Darius Mercadier (Gerrit)

unread,
Apr 1, 2026, 10:37:04 AM (5 days ago) Apr 1
to Marco Vitale, Arash Kazemi, V8 LUCI CQ, chrom...@appspot.gserviceaccount.com, dmercadi...@chromium.org, v8-re...@googlegroups.com
Attention needed from Marco Vitale

Darius Mercadier added 8 comments

Patchset-level comments
File-level comment, Patchset 5 (Latest):
Darius Mercadier . resolved

A few initial comments

CC @sam.p...@arm.com, FYI ;-)

File src/compiler/backend/arm64/instruction-selector-arm64.cc
Line 589, Patchset 5 (Latest): const Operation& lhs = selector->Get(shift->left());
if (uint64_t constant_left;
lhs.Is<Opmask::kWord64BitwiseAnd>() &&
selector->CanCover(index, shift->left()) &&
selector->MatchUnsignedIntegralConstant(shift->right(), &constant_left)) {
uint64_t shift_by = constant_left;
if (base::IsInRange(shift_by, 1, 63)) {
const WordBinopOp& bitwise_and = lhs.Cast<WordBinopOp>();
if (uint64_t constant_right; selector->MatchUnsignedIntegralConstant(
bitwise_and.right(), &constant_right)) {
uint64_t mask = constant_right;
uint32_t mask_width = base::bits::CountPopulation(mask);
uint32_t mask_msb = base::bits::CountLeadingZeros64(mask);
if ((mask_width != 0) && (mask_msb + mask_width == 64) &&
((shift_by + mask_width) < 64)) {
return false;
}
}
}
}
Darius Mercadier . unresolved

So... what's the point of this?

Line 2135, Patchset 5 (Latest): if (uint32_t mask; lhs.Is<Opmask::kWord32ShiftLeft>() &&
Darius Mercadier . unresolved

Add a comment explaining what you're doing / what you're matching.

Line 2140, Patchset 5 (Latest): if ((mask_width != 0) && (mask_width != 32) &&
(base::bits::CountLeadingZeros32(mask) + mask_width +
mask_trailing_zeros ==
32)) {
Darius Mercadier . unresolved

Ok so if I understand correctly, this matches a integer that just has a "pack" of 1s, like `0b00001111100000`. Let's extract this to a helper, add a comment explaining what it does, and reuse if also in VisitWord64And.

Line 2145, Patchset 5 (Latest): if (int64_t shift_by;
Darius Mercadier . unresolved

The rhs of `ShiftOp` should always be a int32.

Line 2210, Patchset 5 (Latest): if (uint64_t mask;
lhs.Is<Opmask::kWord64ShiftLeft>() &&
CanCover(node, bitwise_and.left()) &&
MatchUnsignedIntegralConstant(bitwise_and.right(), &mask)) {
uint64_t mask_width = base::bits::CountPopulation(mask);
uint64_t mask_trailing_zeros = base::bits::CountTrailingZeros64(mask);
if ((mask_width != 0) && (mask_width != 64) &&
(base::bits::CountLeadingZeros64(mask) + mask_width +
mask_trailing_zeros ==
64)) {
const ShiftOp& shift = lhs.Cast<ShiftOp>();
if (int64_t shift_by;
MatchSignedIntegralConstant(shift.right(), &shift_by) &&
static_cast<uint64_t>(shift_by & 0x3F) == mask_trailing_zeros) {
if (mask_width + mask_trailing_zeros >= 64) {
Emit(kArm64Lsl, g.DefineAsRegister(node), g.UseRegister(shift.left()),
g.UseImmediate64(static_cast<int32_t>(mask_trailing_zeros)));
} else {
// Select Ubfiz for And(Lsl(x, imm), mask) where the mask is
// contiguous and its trailing zeros match the shift.
Emit(kArm64Ubfiz, g.DefineAsRegister(node),
g.UseRegister(shift.left()),
g.TempImmediate(static_cast<int32_t>(mask_trailing_zeros)),
g.TempImmediate(static_cast<int32_t>(mask_width)));
}
return;
}
}
}
Darius Mercadier . unresolved

Can we extract this to a helper and reuse it for both VisitWord64And and VisitWord32And? (if the result looks too ugly because of the small differences between the 2, feel free not to do it)

Line 2316, Patchset 5 (Latest):
Darius Mercadier . unresolved

Add a comment here as well.

Line 2320, Patchset 5 (Latest): if (base::IsInRange(shift_by, 1, 63)) {
Darius Mercadier . unresolved

I'd merge this into the `if` right above

Open in Gerrit

Related details

Attention is currently required from:
  • Marco Vitale
Submit Requirements:
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: v8/v8
    Gerrit-Branch: main
    Gerrit-Change-Id: Ieff7eb86d676ff2fc4619d1577b8532a48db6610
    Gerrit-Change-Number: 7706001
    Gerrit-PatchSet: 5
    Gerrit-Owner: Marco Vitale <mrc...@chromium.org>
    Gerrit-Reviewer: Darius Mercadier <dmerc...@chromium.org>
    Gerrit-Reviewer: Marco Vitale <mrc...@chromium.org>
    Gerrit-CC: Arash Kazemi <ara...@chromium.org>
    Gerrit-Attention: Marco Vitale <mrc...@chromium.org>
    Gerrit-Comment-Date: Wed, 01 Apr 2026 14:37:01 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Marco Vitale (Gerrit)

    unread,
    Apr 2, 2026, 7:24:33 AM (4 days ago) Apr 2
    to Sam Parker-Haynes, Darius Mercadier, Arash Kazemi, V8 LUCI CQ, chrom...@appspot.gserviceaccount.com, dmercadi...@chromium.org, v8-re...@googlegroups.com
    Attention needed from Darius Mercadier

    Marco Vitale added 7 comments

    File src/compiler/backend/arm64/instruction-selector-arm64.cc
    Line 589, Patchset 5: const Operation& lhs = selector->Get(shift->left());

    if (uint64_t constant_left;
    lhs.Is<Opmask::kWord64BitwiseAnd>() &&
    selector->CanCover(index, shift->left()) &&
    selector->MatchUnsignedIntegralConstant(shift->right(), &constant_left)) {
    uint64_t shift_by = constant_left;
    if (base::IsInRange(shift_by, 1, 63)) {
    const WordBinopOp& bitwise_and = lhs.Cast<WordBinopOp>();
    if (uint64_t constant_right; selector->MatchUnsignedIntegralConstant(
    bitwise_and.right(), &constant_right)) {
    uint64_t mask = constant_right;
    uint32_t mask_width = base::bits::CountPopulation(mask);
    uint32_t mask_msb = base::bits::CountLeadingZeros64(mask);
    if ((mask_width != 0) && (mask_msb + mask_width == 64) &&
    ((shift_by + mask_width) < 64)) {
    return false;
    }
    }
    }
    }
    Darius Mercadier . resolved

    So... what's the point of this?

    Marco Vitale

    Opsie, leftover, sorry! I was trying to force UBFIZ to see if i was doing something wrong in one of the previous iteration.

    Line 2135, Patchset 5: if (uint32_t mask; lhs.Is<Opmask::kWord32ShiftLeft>() &&
    Darius Mercadier . resolved

    Add a comment explaining what you're doing / what you're matching.

    Marco Vitale

    Commented the whole logic, both in here and in the 64 version. Thanks for the advice

    Line 2140, Patchset 5: if ((mask_width != 0) && (mask_width != 32) &&

    (base::bits::CountLeadingZeros32(mask) + mask_width +
    mask_trailing_zeros ==
    32)) {
    Darius Mercadier . unresolved

    Ok so if I understand correctly, this matches a integer that just has a "pack" of 1s, like `0b00001111100000`. Let's extract this to a helper, add a comment explaining what it does, and reuse if also in VisitWord64And.

    Marco Vitale

    Unfortunately the helper is overly verbose, and it needs to return width, msb, and trailing_zeros (or taking them by ref, that it is something that i usually don't like). I would stick to the current version, as is consistent, like line 2125. Wdyt?

    Line 2145, Patchset 5: if (int64_t shift_by;
    Darius Mercadier . resolved

    The rhs of `ShiftOp` should always be a int32.

    Marco Vitale

    Done

    Line 2210, Patchset 5: if (uint64_t mask;

    lhs.Is<Opmask::kWord64ShiftLeft>() &&
    CanCover(node, bitwise_and.left()) &&
    MatchUnsignedIntegralConstant(bitwise_and.right(), &mask)) {
    uint64_t mask_width = base::bits::CountPopulation(mask);
    uint64_t mask_trailing_zeros = base::bits::CountTrailingZeros64(mask);
    if ((mask_width != 0) && (mask_width != 64) &&
    (base::bits::CountLeadingZeros64(mask) + mask_width +
    mask_trailing_zeros ==
    64)) {
    const ShiftOp& shift = lhs.Cast<ShiftOp>();
    if (int64_t shift_by;
    MatchSignedIntegralConstant(shift.right(), &shift_by) &&
    static_cast<uint64_t>(shift_by & 0x3F) == mask_trailing_zeros) {
    if (mask_width + mask_trailing_zeros >= 64) {
    Emit(kArm64Lsl, g.DefineAsRegister(node), g.UseRegister(shift.left()),
    g.UseImmediate64(static_cast<int32_t>(mask_trailing_zeros)));
    } else {
    // Select Ubfiz for And(Lsl(x, imm), mask) where the mask is
    // contiguous and its trailing zeros match the shift.
    Emit(kArm64Ubfiz, g.DefineAsRegister(node),
    g.UseRegister(shift.left()),
    g.TempImmediate(static_cast<int32_t>(mask_trailing_zeros)),
    g.TempImmediate(static_cast<int32_t>(mask_width)));
    }
    return;
    }
    }
    }
    Darius Mercadier . resolved

    Can we extract this to a helper and reuse it for both VisitWord64And and VisitWord32And? (if the result looks too ugly because of the small differences between the 2, feel free not to do it)

    Marco Vitale

    Also here, the helper turn out to be comparable in size given the differences between the two. I would stick also here to keep it separate.

    Line 2316, Patchset 5:
    Darius Mercadier . resolved

    Add a comment here as well.

    Marco Vitale

    Done

    Line 2320, Patchset 5: if (base::IsInRange(shift_by, 1, 63)) {
    Darius Mercadier . resolved

    I'd merge this into the `if` right above

    Marco Vitale

    Done

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Darius Mercadier
    Submit Requirements:
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: v8/v8
    Gerrit-Branch: main
    Gerrit-Change-Id: Ieff7eb86d676ff2fc4619d1577b8532a48db6610
    Gerrit-Change-Number: 7706001
    Gerrit-PatchSet: 8
    Gerrit-Owner: Marco Vitale <mrc...@chromium.org>
    Gerrit-Reviewer: Darius Mercadier <dmerc...@chromium.org>
    Gerrit-Reviewer: Marco Vitale <mrc...@chromium.org>
    Gerrit-CC: Arash Kazemi <ara...@chromium.org>
    Gerrit-CC: Sam Parker-Haynes <sam.p...@arm.com>
    Gerrit-Attention: Darius Mercadier <dmerc...@chromium.org>
    Gerrit-Comment-Date: Thu, 02 Apr 2026 11:24:28 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Darius Mercadier <dmerc...@chromium.org>
    unsatisfied_requirement
    open
    diffy

    Darius Mercadier (Gerrit)

    unread,
    Apr 2, 2026, 8:40:17 AM (4 days ago) Apr 2
    to Marco Vitale, Sam Parker-Haynes, Arash Kazemi, V8 LUCI CQ, chrom...@appspot.gserviceaccount.com, dmercadi...@chromium.org, v8-re...@googlegroups.com
    Attention needed from Marco Vitale

    Darius Mercadier added 1 comment

    File src/compiler/backend/arm64/instruction-selector-arm64.cc
    Line 2140, Patchset 5: if ((mask_width != 0) && (mask_width != 32) &&
    (base::bits::CountLeadingZeros32(mask) + mask_width +
    mask_trailing_zeros ==
    32)) {
    Darius Mercadier . unresolved

    Ok so if I understand correctly, this matches a integer that just has a "pack" of 1s, like `0b00001111100000`. Let's extract this to a helper, add a comment explaining what it does, and reuse if also in VisitWord64And.

    Marco Vitale

    Unfortunately the helper is overly verbose, and it needs to return width, msb, and trailing_zeros (or taking them by ref, that it is something that i usually don't like). I would stick to the current version, as is consistent, like line 2125. Wdyt?

    Darius Mercadier
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Marco Vitale
    Submit Requirements:
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: v8/v8
    Gerrit-Branch: main
    Gerrit-Change-Id: Ieff7eb86d676ff2fc4619d1577b8532a48db6610
    Gerrit-Change-Number: 7706001
    Gerrit-PatchSet: 8
    Gerrit-Owner: Marco Vitale <mrc...@chromium.org>
    Gerrit-Reviewer: Darius Mercadier <dmerc...@chromium.org>
    Gerrit-Reviewer: Marco Vitale <mrc...@chromium.org>
    Gerrit-CC: Arash Kazemi <ara...@chromium.org>
    Gerrit-CC: Sam Parker-Haynes <sam.p...@arm.com>
    Gerrit-Attention: Marco Vitale <mrc...@chromium.org>
    Gerrit-Comment-Date: Thu, 02 Apr 2026 12:40:12 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Darius Mercadier <dmerc...@chromium.org>
    Comment-In-Reply-To: Marco Vitale <mrc...@chromium.org>
    unsatisfied_requirement
    open
    diffy

    Marco Vitale (Gerrit)

    unread,
    Apr 2, 2026, 9:23:13 AM (4 days ago) Apr 2
    to Sam Parker-Haynes, Darius Mercadier, Arash Kazemi, V8 LUCI CQ, chrom...@appspot.gserviceaccount.com, dmercadi...@chromium.org, v8-re...@googlegroups.com
    Attention needed from Darius Mercadier

    Marco Vitale added 1 comment

    File src/compiler/backend/arm64/instruction-selector-arm64.cc
    Line 2140, Patchset 5: if ((mask_width != 0) && (mask_width != 32) &&
    (base::bits::CountLeadingZeros32(mask) + mask_width +
    mask_trailing_zeros ==
    32)) {
    Darius Mercadier . unresolved

    Ok so if I understand correctly, this matches a integer that just has a "pack" of 1s, like `0b00001111100000`. Let's extract this to a helper, add a comment explaining what it does, and reuse if also in VisitWord64And.

    Marco Vitale

    Unfortunately the helper is overly verbose, and it needs to return width, msb, and trailing_zeros (or taking them by ref, that it is something that i usually don't like). I would stick to the current version, as is consistent, like line 2125. Wdyt?

    Darius Mercadier

    Wdyt of https://crrev.com/c/7726022 ?

    Marco Vitale
    My implementation was really similar, but still, we gain ~10 lines and we lose consistency with the rest of the file, for example, just above my code:
    ```if (int64_t constant_rhs;
    lhs.Is<Opmask::kWord32ShiftRightLogical>() &&
    CanCover(node, bitwise_and.left()) &&
    MatchSignedIntegralConstant(bitwise_and.right(), &constant_rhs)) {
    DCHECK(base::IsInRange(constant_rhs, std::numeric_limits<int32_t>::min(),
    std::numeric_limits<int32_t>::max()));
    uint32_t mask = static_cast<uint32_t>(constant_rhs);

    uint32_t mask_width = base::bits::CountPopulation(mask);
        uint32_t mask_msb = base::bits::CountLeadingZeros32(mask);

    if ((mask_width != 0) && (mask_width != 32) &&
            (mask_msb + mask_width == 32)) {
    ...
    ```

    At least, this is my opinion, if you strongly prefer the helper we can proceed to your solution 😊
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Darius Mercadier
    Submit Requirements:
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: v8/v8
    Gerrit-Branch: main
    Gerrit-Change-Id: Ieff7eb86d676ff2fc4619d1577b8532a48db6610
    Gerrit-Change-Number: 7706001
    Gerrit-PatchSet: 8
    Gerrit-Owner: Marco Vitale <mrc...@chromium.org>
    Gerrit-Reviewer: Darius Mercadier <dmerc...@chromium.org>
    Gerrit-Reviewer: Marco Vitale <mrc...@chromium.org>
    Gerrit-CC: Arash Kazemi <ara...@chromium.org>
    Gerrit-CC: Sam Parker-Haynes <sam.p...@arm.com>
    Gerrit-Attention: Darius Mercadier <dmerc...@chromium.org>
    Gerrit-Comment-Date: Thu, 02 Apr 2026 13:23:09 +0000
    unsatisfied_requirement
    open
    diffy

    Darius Mercadier (Gerrit)

    unread,
    Apr 2, 2026, 9:27:59 AM (4 days ago) Apr 2
    to Marco Vitale, Sam Parker-Haynes, Arash Kazemi, V8 LUCI CQ, chrom...@appspot.gserviceaccount.com, dmercadi...@chromium.org, v8-re...@googlegroups.com
    Attention needed from Marco Vitale

    Darius Mercadier added 1 comment

    File src/compiler/backend/arm64/instruction-selector-arm64.cc
    Darius Mercadier

    In my opinion, the goal is not to reduce code size, but rather to avoid duplicating the same optimizations. What happens the day we realize that there is a bug in the 32-bit version and whoever fixes it doesn't realize that this also needs to be fixed in the 64-bit version?

    Having duplicated code is not a feature of this file, it's an unfortunate situation. If the optimization above your code can easily be extracted to a helper, then we should do so (not necessarily you, and definitely not in this CL of course).

    Let's go with the approach that doesn't duplicate code. Feel free to reuse my code or use your own ;-)

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Marco Vitale
    Submit Requirements:
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: v8/v8
    Gerrit-Branch: main
    Gerrit-Change-Id: Ieff7eb86d676ff2fc4619d1577b8532a48db6610
    Gerrit-Change-Number: 7706001
    Gerrit-PatchSet: 8
    Gerrit-Owner: Marco Vitale <mrc...@chromium.org>
    Gerrit-Reviewer: Darius Mercadier <dmerc...@chromium.org>
    Gerrit-Reviewer: Marco Vitale <mrc...@chromium.org>
    Gerrit-CC: Arash Kazemi <ara...@chromium.org>
    Gerrit-CC: Sam Parker-Haynes <sam.p...@arm.com>
    Gerrit-Attention: Marco Vitale <mrc...@chromium.org>
    Gerrit-Comment-Date: Thu, 02 Apr 2026 13:27:53 +0000
    unsatisfied_requirement
    open
    diffy

    Marco Vitale (Gerrit)

    unread,
    Apr 2, 2026, 10:29:38 AM (4 days ago) Apr 2
    to Sam Parker-Haynes, Darius Mercadier, Arash Kazemi, V8 LUCI CQ, chrom...@appspot.gserviceaccount.com, dmercadi...@chromium.org, v8-re...@googlegroups.com
    Attention needed from Darius Mercadier

    Marco Vitale added 1 comment

    File src/compiler/backend/arm64/instruction-selector-arm64.cc
    Marco Vitale

    I'm always a bit reluctant when the usages are just two, and usually we pay a price in clarity with the helper (given the machinery needed to get the helper works). Also the TryEmit pattern is not helping IMO, as the duplicate logic is in the `Try` phase and in the and we are emitting different instructions. I also spent a bit of time to try to see if at least the emission could have be split, but it is still not great. Let's go with your solution! Maybe in the future, when i'll be more used to the code i can think about something better, and will ask you again for review. Thanks for the discussion!

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Darius Mercadier
    Submit Requirements:
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: v8/v8
    Gerrit-Branch: main
    Gerrit-Change-Id: Ieff7eb86d676ff2fc4619d1577b8532a48db6610
    Gerrit-Change-Number: 7706001
    Gerrit-PatchSet: 9
    Gerrit-Owner: Marco Vitale <mrc...@chromium.org>
    Gerrit-Reviewer: Darius Mercadier <dmerc...@chromium.org>
    Gerrit-Reviewer: Marco Vitale <mrc...@chromium.org>
    Gerrit-CC: Arash Kazemi <ara...@chromium.org>
    Gerrit-CC: Sam Parker-Haynes <sam.p...@arm.com>
    Gerrit-Attention: Darius Mercadier <dmerc...@chromium.org>
    Gerrit-Comment-Date: Thu, 02 Apr 2026 14:29:34 +0000
    unsatisfied_requirement
    open
    diffy

    Darius Mercadier (Gerrit)

    unread,
    Apr 2, 2026, 10:45:59 AM (4 days ago) Apr 2
    to Marco Vitale, Sam Parker-Haynes, Arash Kazemi, V8 LUCI CQ, chrom...@appspot.gserviceaccount.com, dmercadi...@chromium.org, v8-re...@googlegroups.com
    Attention needed from Marco Vitale

    Darius Mercadier added 6 comments

    File src/compiler/backend/arm64/instruction-selector-arm64.cc
    Line 2099, Patchset 9 (Latest): // Deduce the correct unsigned integer type based on bit length.
    Darius Mercadier . unresolved

    Not a particularly useful comment, imo.

    Line 2115, Patchset 9 (Latest): // Base::bits relies on C++ function overloading, so passing the deduced
    // 'Int' automatically routes to the 32-bit or 64-bit implementations.
    Darius Mercadier . resolved

    Not convinced that this is a useful comment. It's also the case of `MatchUnsignedIntegralConstant` above btw.
    But feel free to keep it if you think it's useful.

    Line 2140, Patchset 5: if ((mask_width != 0) && (mask_width != 32) &&
    (base::bits::CountLeadingZeros32(mask) + mask_width +
    mask_trailing_zeros ==
    32)) {
    Darius Mercadier . resolved
    Darius Mercadier

    In that case, I think that we gained in clarity by using the helper: we now have `bit_length` and `kBitLengthMask` instead of magic numbers `64` (ok this one is easy to understand) and `0x3f` (this one on the other hand, I can't tell by just looking at it that it's actually 63, and with a named variable its meaning is also clearer).
    Yes, those things could have been fixed without the helper, but overall in that specific case, the helper doesn't feel harder to read to me.

    Line 2145, Patchset 9 (Latest): g.TempImmediate(static_cast<int32_t>(mask_trailing_zeros)),
    Darius Mercadier . unresolved

    Any reason for using TempImmediate instead of UseImmediate?

    (looks to me like TempImmediate should actually be globally remove and UseImmediate always used instead, but maybe I'm missing something)

    Line 2146, Patchset 9 (Latest): g.TempImmediate(static_cast<int32_t>(mask_width)));
    Darius Mercadier . unresolved

    same

    Line 2330, Patchset 9 (Latest): if (uint64_t shift_by;
    lhs.Is<Opmask::kWord64BitwiseAnd>() && CanCover(node, shift_op.left()) &&
    MatchUnsignedIntegralConstant(shift_op.right(), &shift_by) &&

    base::IsInRange(shift_by, 1, 63)) {
    const WordBinopOp& bitwise_and = lhs.Cast<WordBinopOp>();
    if (uint64_t mask;
    MatchUnsignedIntegralConstant(bitwise_and.right(), &mask)) {
    uint64_t mask_width = base::bits::CountPopulation(mask);
    uint64_t mask_msb = base::bits::CountLeadingZeros64(mask);
    if ((mask_width != 0) && (mask_msb + mask_width == 64)) {
    // The mask must be contiguous and starting from the least-significant
    // bit.
    DCHECK_EQ(0u, base::bits::CountTrailingZeros64(mask));
    if ((shift_by + mask_width) >= 64) {
    // If the mask is contiguous and reaches or extends beyond the top
    // bit, only the shift is needed.
    Emit(kArm64Lsl, g.DefineAsRegister(node),
    g.UseRegister(bitwise_and.left()), g.UseImmediate64(shift_by));
    return;
    } else {
    // Select Ubfiz for Shl(And(x, mask), imm) where the mask is
    // contiguous, and the shift immediate non-zero.
    Emit(kArm64Ubfiz, g.DefineAsRegister(node),
    g.UseRegister(bitwise_and.left()), g.UseImmediate64(shift_by),
    g.TempImmediate(static_cast<int32_t>(mask_width)));
    return;
    }
    }
    }
    }
    Darius Mercadier . unresolved

    I'd also move this to a helper (as far as I can see this is basically the same code as in Word32Shl).

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Marco Vitale
    Submit Requirements:
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: v8/v8
    Gerrit-Branch: main
    Gerrit-Change-Id: Ieff7eb86d676ff2fc4619d1577b8532a48db6610
    Gerrit-Change-Number: 7706001
    Gerrit-PatchSet: 9
    Gerrit-Owner: Marco Vitale <mrc...@chromium.org>
    Gerrit-Reviewer: Darius Mercadier <dmerc...@chromium.org>
    Gerrit-Reviewer: Marco Vitale <mrc...@chromium.org>
    Gerrit-CC: Arash Kazemi <ara...@chromium.org>
    Gerrit-CC: Sam Parker-Haynes <sam.p...@arm.com>
    Gerrit-Attention: Marco Vitale <mrc...@chromium.org>
    Gerrit-Comment-Date: Thu, 02 Apr 2026 14:45:55 +0000
    unsatisfied_requirement
    open
    diffy

    Marco Vitale (Gerrit)

    unread,
    Apr 2, 2026, 12:28:01 PM (4 days ago) Apr 2
    to Sam Parker-Haynes, Darius Mercadier, Arash Kazemi, V8 LUCI CQ, chrom...@appspot.gserviceaccount.com, dmercadi...@chromium.org, v8-re...@googlegroups.com
    Attention needed from Darius Mercadier

    Marco Vitale added 4 comments

    File src/compiler/backend/arm64/instruction-selector-arm64.cc
    Line 2099, Patchset 9: // Deduce the correct unsigned integer type based on bit length.
    Darius Mercadier . resolved

    Not a particularly useful comment, imo.

    Marco Vitale

    Done

    Line 2145, Patchset 9: g.TempImmediate(static_cast<int32_t>(mask_trailing_zeros)),
    Darius Mercadier . resolved

    Any reason for using TempImmediate instead of UseImmediate?

    (looks to me like TempImmediate should actually be globally remove and UseImmediate always used instead, but maybe I'm missing something)

    Marco Vitale

    Done

    Line 2146, Patchset 9: g.TempImmediate(static_cast<int32_t>(mask_width)));
    Darius Mercadier . resolved

    same

    Marco Vitale

    Done

    Line 2330, Patchset 9: if (uint64_t shift_by;
    Darius Mercadier . resolved

    I'd also move this to a helper (as far as I can see this is basically the same code as in Word32Shl).

    Marco Vitale

    Done

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Darius Mercadier
    Submit Requirements:
      • requirement is not satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: v8/v8
      Gerrit-Branch: main
      Gerrit-Change-Id: Ieff7eb86d676ff2fc4619d1577b8532a48db6610
      Gerrit-Change-Number: 7706001
      Gerrit-PatchSet: 10
      Gerrit-Owner: Marco Vitale <mrc...@chromium.org>
      Gerrit-Reviewer: Darius Mercadier <dmerc...@chromium.org>
      Gerrit-Reviewer: Marco Vitale <mrc...@chromium.org>
      Gerrit-CC: Arash Kazemi <ara...@chromium.org>
      Gerrit-CC: Sam Parker-Haynes <sam.p...@arm.com>
      Gerrit-Attention: Darius Mercadier <dmerc...@chromium.org>
      Gerrit-Comment-Date: Thu, 02 Apr 2026 16:27:56 +0000
      unsatisfied_requirement
      open
      diffy
      Reply all
      Reply to author
      Forward
      0 new messages