U2-B Add swar sub and shift masks - #25
Conversation
There was a problem hiding this comment.
Pull request overview
Implements missing carrier-path lowerings in Nybbler for narrow-field vector sub and variable shl/lshr, and re-enables associated shape/differential tests that were previously XFAILed.
Changes:
- Add SWAR
sublowering fori2/i4and remapi1 subtoxorbefore dispatch. - Replace shift scaffolding with per-field bit-serial conditional shift lowering for
shl/lshroni2/i4and an identity fast-path fori1. - Update shape tests’ CHECK patterns and remove XFAILs from
sub/shl/lshrshape + diff tests.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/Nybbler.cpp | Adds lowerSub, extends dispatch remaps for i1 sub, and implements per-field conditional shl/lshr lowering. |
| test/shape/sub_i4.ll | Updates shape CHECKs for the new borrow-confining SWAR sub sequence; removes XFAIL. |
| test/shape/sub_i2.ll | Updates shape CHECKs for the new borrow-confining SWAR sub sequence; removes XFAIL. |
| test/shape/sub_i1.ll | Updates shape CHECKs to validate i1 sub remaps to xor; removes XFAIL. |
| test/shape/shl_i4.ll | Updates shape CHECKs for the new bit-serial per-field shift sequence; removes placeholder assumptions. |
| test/shape/shl_i2.ll | Updates shape CHECKs for the new bit-serial per-field shift sequence; removes placeholder assumptions. |
| test/shape/shl_i1.ll | Updates shape CHECKs to validate i1 shl lowers to an identity carrier path (no shl). |
| test/shape/lshr_i4.ll | Updates shape CHECKs for the new bit-serial per-field shift sequence; removes placeholder assumptions. |
| test/shape/lshr_i2.ll | Updates shape CHECKs for the new bit-serial per-field shift sequence; removes placeholder assumptions. |
| test/shape/lshr_i1.ll | Updates shape CHECKs to validate i1 lshr lowers to an identity carrier path (no lshr). |
| test/diff/shl.ll | Removes XFAIL now that shl lowering is expected to match the scalar reference. |
| test/diff/lshr.ll | Removes XFAIL now that lshr lowering is expected to match the scalar reference. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CI is red on 4 tests — two real correctness bugs in
|
Summary
Completes the arithmetic and shift lowerings on the carrier dispatch path.
Sub (i4 / i2) uses a borrow-absorber approach, the dual of
lowerAdd:ain every field (OR hmask) so borrow has somewhere to go without escaping the field boundaryb(AND lmask) and subtractXOR hmask), then XOR in the correcta_top ^ b_topi1 sub remaps to
xorbefore dispatch, mirroring the existing i1 add remap.Shl / LShr (i4 / i2) replaces the U2-A identity-mask placeholder with a real per-field bit-serial conditional shift. For each power-of-two step
s:ssetswith the correct boundary mask (topN-sbits for shl, bottomN-sbits for lshr)Shift amounts are masked to
[0, N-1]per field inside the handler so out-of-range values produce defined output consistent with the scalar reference in the differential harness.i1 shl / lshr return the input unchanged — the only in-range amount is 0 (identity), any nonzero is poison.
Tests
XFAIL: *fromtest/shape/sub_i1.ll,sub_i2.ll,sub_i4.llor/and/sub/xor/xor) and the i1 xor remapXFAIL: *fromtest/shape/shl_i1/i2/i4.llandlshr_i1/i2/i4.lland/lshr/and/sub/shl-or-lshr/and) and the i1 identity pathXFAIL: *fromtest/diff/shl.llandtest/diff/lshr.ll