Skip to content

Commit

Permalink
[compiler] Fix a bug in MachineOperatorReducer's BitfieldCheck
Browse files Browse the repository at this point in the history
Bug: chromium:1234770
Change-Id: I7368c4bcebc9b4ae78291e9e7bfc860328a742ae
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3068941
Reviewed-by: Seth Brenith <seth.brenith@microsoft.com>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#76062}
  • Loading branch information
GeorgNeis authored and V8 LUCI CQ committed Aug 3, 2021
1 parent 27a517b commit 574ca6b
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/compiler/machine-operator-reducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1718,11 +1718,21 @@ Reduction MachineOperatorReducer::ReduceWordNAnd(Node* node) {
namespace {

// Represents an operation of the form `(source & mask) == masked_value`.
// where each bit set in masked_value also has to be set in mask.
struct BitfieldCheck {
Node* source;
uint32_t mask;
uint32_t masked_value;
bool truncate_from_64_bit;
Node* const source;
uint32_t const mask;
uint32_t const masked_value;
bool const truncate_from_64_bit;

BitfieldCheck(Node* source, uint32_t mask, uint32_t masked_value,
bool truncate_from_64_bit)
: source(source),
mask(mask),
masked_value(masked_value),
truncate_from_64_bit(truncate_from_64_bit) {
CHECK_EQ(masked_value & ~mask, 0);
}

static base::Optional<BitfieldCheck> Detect(Node* node) {
// There are two patterns to check for here:
Expand All @@ -1737,14 +1747,16 @@ struct BitfieldCheck {
if (eq.left().IsWord32And()) {
Uint32BinopMatcher mand(eq.left().node());
if (mand.right().HasResolvedValue() && eq.right().HasResolvedValue()) {
BitfieldCheck result{mand.left().node(), mand.right().ResolvedValue(),
eq.right().ResolvedValue(), false};
uint32_t mask = mand.right().ResolvedValue();
uint32_t masked_value = eq.right().ResolvedValue();
if ((masked_value & ~mask) != 0) return {};
if (mand.left().IsTruncateInt64ToInt32()) {
result.truncate_from_64_bit = true;
result.source =
NodeProperties::GetValueInput(mand.left().node(), 0);
return BitfieldCheck(
NodeProperties::GetValueInput(mand.left().node(), 0), mask,
masked_value, true);
} else {
return BitfieldCheck(mand.left().node(), mask, masked_value, false);
}
return result;
}
}
} else {
Expand Down

0 comments on commit 574ca6b

Please sign in to comment.