Skip to content

Conversation

@cdleary
Copy link
Collaborator

@cdleary cdleary commented Jan 12, 2026

Uses a "View" extractor similarly to what we did for BinarySelect in the recent PR to consolidate two forms for "one bit is set" (concat and bit shifted by constant literal).

@cdleary cdleary marked this pull request as ready for review January 12, 2026 01:21
Node* divisor = n->operand(1);
const int64_t bit_count = x->BitCountOrDie();

auto replace_with_select = [&](Node* b, int64_t k) -> absl::StatusOr<bool> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only ever returns true

m::Concat(m::Literal(UBits(0, 32 - k)), narrowed_and);
auto concat_form_flipped =
m::Concat(m::Literal(UBits(0, 32 - k)), narrowed_and_flipped);
EXPECT_THAT(f->return_value(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any convenient way to restrict the pass pipeline such that we don't need to assert over all these possible forms?


} // namespace

std::optional<ShiftedBitView> IsOneShiftedBit(Node* node) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This strikes me as a specialized form of querying bit_provenance_analysis for the source of a node's bits and then asking if all bits are literal 0 except for 1 bit. Can you look into using that analysis instead of implementing pattern matchers for these two cases?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants