Skip to content

g8r: prep projected positive-mask cones before gatify#848

Open
cdleary wants to merge 1 commit intomainfrom
codex/determine-missing-g8r-mapping-or-prep-optimization
Open

g8r: prep projected positive-mask cones before gatify#848
cdleary wants to merge 1 commit intomainfrom
codex/determine-missing-g8r-mapping-or-prep-optimization

Conversation

@cdleary
Copy link
Contributor

@cdleary cdleary commented Feb 27, 2026

Motivation

  • Gatify was producing suboptimal gate graphs for a common cone shape that masks a data bit with not(sle(x,0)), because there was no preparatory PIR rewrite to expose the simpler sign-bit test pattern.
  • Introducing a prep-for-gatify canonicalization improves downstream gatification/QoR by collapsing the cone to a simple sign/data-bit conjunction that tools like ABC can reduce far more compactly.

Description

  • Add rewrite_projected_positive_mask_to_sign_test to xlsynth-g8r/src/gatify/prep_for_gatify.rs which recognizes the pattern bit_slice(and(bit_slice(x,0,w), sign_ext(not(sle(x,0)), w)), ...) and rewrites the sle into a sign-bit bit_slice so the mask becomes !sign(x) for the projected data bit.
  • Invoke the new rewrite inside prep_for_gatify before dead-node cleanup to preserve SSA/textual ordering and enable safe node nil-ing afterwards.
  • The rewrite performs pattern checks (operand shapes, widths, literal rhs checks) and uses ir_utils::replace_node_payload to perform an in-place transformation that keeps node ordering valid.
  • Add a focused unit test projected_positive_mask_rewrite_collapses_to_sign_test_and_data_bit that constructs the user-reported cone, asserts the optimized IR uses the sign-bit form (and no live sle), and exhaustively validates equivalence across all bits[13] inputs.

Testing

  • Ran the focused unit test with cargo test -p xlsynth-g8r projected_positive_mask_rewrite_collapses_to_sign_test_and_data_bit -- --nocapture, which passed.
  • Built fuzz bins with cargo check --manifest-path xlsynth-g8r/fuzz/Cargo.toml --bins, which completed successfully (warnings only).
  • Ran repository checks pre-commit run --all-files, which completed and reported rustfmt/hooks passing after formatting.
  • Executed full test suite with cargo test --workspace, which completed with all tests passing for the workspace at the time of the change.

Codex Task

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7beb0fabc9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +293 to +296
ir_utils::replace_node_payload(
f,
sle_nr,
NodePayload::BitSlice {

Choose a reason for hiding this comment

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

P1 Badge Require unique use before mutating sle into sign bit

This rewrite replaces sle_nr in place with a sign-bit bit_slice, but there is no use-count guard that the matched sle/not chain is only used by this cone. If sle(x,0) is also consumed elsewhere, those users now see sign(x) instead of x <= 0, causing incorrect behavior. Add single-use checks (like other rewrites in this file) before mutating shared nodes.

Useful? React with 👍 / 👎.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant