Commit 574ca6b7 authored by Georg Neis's avatar Georg Neis Committed by V8 LUCI CQ

[compiler] Fix a bug in MachineOperatorReducer's BitfieldCheck

Bug: chromium:1234770
Change-Id: I7368c4bcebc9b4ae78291e9e7bfc860328a742ae
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3068941Reviewed-by: 's avatarSeth Brenith <seth.brenith@microsoft.com>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#76062}
parent 27a517b8
...@@ -1718,11 +1718,21 @@ Reduction MachineOperatorReducer::ReduceWordNAnd(Node* node) { ...@@ -1718,11 +1718,21 @@ Reduction MachineOperatorReducer::ReduceWordNAnd(Node* node) {
namespace { namespace {
// Represents an operation of the form `(source & mask) == masked_value`. // 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 { struct BitfieldCheck {
Node* source; Node* const source;
uint32_t mask; uint32_t const mask;
uint32_t masked_value; uint32_t const masked_value;
bool truncate_from_64_bit; 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) { static base::Optional<BitfieldCheck> Detect(Node* node) {
// There are two patterns to check for here: // There are two patterns to check for here:
...@@ -1737,14 +1747,16 @@ struct BitfieldCheck { ...@@ -1737,14 +1747,16 @@ struct BitfieldCheck {
if (eq.left().IsWord32And()) { if (eq.left().IsWord32And()) {
Uint32BinopMatcher mand(eq.left().node()); Uint32BinopMatcher mand(eq.left().node());
if (mand.right().HasResolvedValue() && eq.right().HasResolvedValue()) { if (mand.right().HasResolvedValue() && eq.right().HasResolvedValue()) {
BitfieldCheck result{mand.left().node(), mand.right().ResolvedValue(), uint32_t mask = mand.right().ResolvedValue();
eq.right().ResolvedValue(), false}; uint32_t masked_value = eq.right().ResolvedValue();
if ((masked_value & ~mask) != 0) return {};
if (mand.left().IsTruncateInt64ToInt32()) { if (mand.left().IsTruncateInt64ToInt32()) {
result.truncate_from_64_bit = true; return BitfieldCheck(
result.source = NodeProperties::GetValueInput(mand.left().node(), 0), mask,
NodeProperties::GetValueInput(mand.left().node(), 0); masked_value, true);
} else {
return BitfieldCheck(mand.left().node(), mask, masked_value, false);
} }
return result;
} }
} }
} else { } else {
......
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