g8r: prep projected positive-mask cones before gatify#848
g8r: prep projected positive-mask cones before gatify#848
Conversation
There was a problem hiding this comment.
💡 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".
| ir_utils::replace_node_payload( | ||
| f, | ||
| sle_nr, | ||
| NodePayload::BitSlice { |
There was a problem hiding this comment.
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 👍 / 👎.
Motivation
not(sle(x,0)), because there was no preparatory PIR rewrite to expose the simpler sign-bit test pattern.Description
rewrite_projected_positive_mask_to_sign_testtoxlsynth-g8r/src/gatify/prep_for_gatify.rswhich recognizes the patternbit_slice(and(bit_slice(x,0,w), sign_ext(not(sle(x,0)), w)), ...)and rewrites thesleinto a sign-bitbit_sliceso the mask becomes!sign(x)for the projected data bit.prep_for_gatifybefore dead-node cleanup to preserve SSA/textual ordering and enable safe node nil-ing afterwards.ir_utils::replace_node_payloadto perform an in-place transformation that keeps node ordering valid.projected_positive_mask_rewrite_collapses_to_sign_test_and_data_bitthat constructs the user-reported cone, asserts the optimized IR uses the sign-bit form (and no livesle), and exhaustively validates equivalence across allbits[13]inputs.Testing
cargo test -p xlsynth-g8r projected_positive_mask_rewrite_collapses_to_sign_test_and_data_bit -- --nocapture, which passed.cargo check --manifest-path xlsynth-g8r/fuzz/Cargo.toml --bins, which completed successfully (warnings only).pre-commit run --all-files, which completed and reportedrustfmt/hooks passing after formatting.cargo test --workspace, which completed with all tests passing for the workspace at the time of the change.Codex Task