[AIE2P][AIE2PS] Legalize the 64-bit bfp16 block-exponent G_BUILD_VECTOR (fixes #995)#1184
Open
atassis wants to merge 1 commit into
Open
[AIE2P][AIE2PS] Legalize the 64-bit bfp16 block-exponent G_BUILD_VECTOR (fixes #995)#1184atassis wants to merge 1 commit into
atassis wants to merge 1 commit into
Conversation
atassis
requested review from
F-Stuckmann,
SagarMaheshwari99,
abhinay-anubola,
abnikant,
andcarminati,
katerynamuts,
khallouh,
konstantinschwarz,
martien-de-jong,
mludevid,
niwinanto and
stephenneuendorffer
as code owners
July 21, 2026 22:57
atassis
force-pushed
the
aie2p-bfp16-exp-buildvec-995
branch
from
July 21, 2026 23:05
a9d563a to
d2e41cb
Compare
Contributor
Author
|
@hunhoffe one 1.4-relevant note on this. It fixes the |
atassis
force-pushed
the
aie2p-bfp16-exp-buildvec-995
branch
from
July 22, 2026 14:46
d2e41cb to
80e24e7
Compare
Fixes Xilinx#995. Compiling the block_datatypes bfp16 matmul kernel (matmul_vectorized_bfp16) for AIE2P aborts the legalizer: unable to legalize instruction: %..:_(<8 x s8>) = G_BUILD_VECTOR ... The <8 x s8> is the bfp16 block-exponent vector (a splat feeding the BFP...mul.conf MAC). It is a valid register type (EXPVEC64, produced by the bfp16 intrinsics), but there was no way to build one: isValidVectorAIEP treats a vector as valid only if its size is 32 or greater than 64, so 64-bit vectors hit unsupportedIf, and legalizeG_BUILD_VECTOR also asserts on 64-bit. Route 64-bit vectors to custom legalization and pack the elements into a same-sized scalar (zext/shl/or), then bitcast to the vector. The scalar-to-vector move (for the exponent, GPR to EXPVEC64) is already a legal register copy, so this selects without a native build. On the failing kernel the exponent splat of 127 now materializes as 0x7F7F7F7F7F7F7F7F moved into the exponent register. Applied to both AIE2P and AIE2PS (identical rule; shared helper). Adds a legalizer test that runs on both.
atassis
force-pushed
the
aie2p-bfp16-exp-buildvec-995
branch
from
July 24, 2026 18:07
80e24e7 to
ab46e23
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #995.
Compiling the
block_datatypesbfp16 matmul kernel (matmul_vectorized_bfp16) for AIE2P aborts the legalizer:The
<8 x s8>is the bfp16 block-exponent vector (a splat feeding theBFP...mul.confMAC). It is a valid register type (EXPVEC64, produced by the bfp16 intrinsics), but there was no way to build one:isValidVectorAIEPtreats a vector as valid only if its size is 32 or greater than 64, so 64-bit vectors hit.unsupportedIf, andlegalizeG_BUILD_VECTORalso asserts on 64-bit.This routes 64-bit vectors to custom legalization and packs the elements into a same-sized scalar (
zext/shl/or), then bitcasts to the vector. The scalar-to-vector move (for the exponent, GPR toEXPVEC64) is already a legal register copy, so this selects without a native build. On the failing kernel the exponent splat of 127 now materializes as0x7F7F7F7F7F7F7F7Fmoved into the exponent register.Applied to both AIE2P and AIE2PS (identical rule; shared helper).
Testing
aie_kernels/aie2p/mm_bfp.cc(matmul_vectorized_bfp16) compiled foraie2p-none-unknown-elf -O2, both to assembly and to an object (-filetype=obj); it aborted the legalizer before this change.movxm r6, #0x7F7F7F7F+mov el0, r6/mov eh0, r7, i.e. the exponent register holds0x7F7F7F7F7F7F7F7F= 127 in all 8 blocks, which is the intended block exponent.legalize-build-vector.mir,-run-pass=legalizer, runs on bothaie2pandaie2ps) for the<8 x s8>build. Existinglegalize-build-vector.mirandinst-select-scl2vec-bfp16.mirstill pass on both triples.iis packed at bits[i*EltSize, (i+1)*EltSize)and bitcasts back to lanei. A 64-bit element (a 1-element vector) is used as-is rather than zero-extended to its own size (which would be invalid).Not covered: an end-to-end on-device numerical run (the only stock design that reaches this kernel is Chess-tuned), so verification here is at the compile/codegen level, which is what the crash fix requires.