Skip to content

Conversation

@cdleary
Copy link
Collaborator

@cdleary cdleary commented Jan 17, 2026

Rewrites via the observation that ~x and x+1 are "zero-equivalent".

  // Pattern:
  //   `(eq|ne)(sel(c, cases=[not(x), add(x, 1)]), 0)` =>
  //   `(eq|ne)(x, all_ones(width(x)))`
  //
  // Why this works (not/inc zero-equivalence):
  // - `(~x == 0)`  <=>  `(x == all_ones)`
  // - `(x+1 == 0)` <=>  `(x == all_ones)`   (note: given wraparound arithmetic)
  // Therefore for `y = sel(c, [~x, x+1])`, `(y != 0)` is exactly `(x !=
  // all_ones)`, independent of selector `c`.

@cdleary cdleary marked this pull request as ready for review January 17, 2026 22:13
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.

1 participant