[AIE] Fix instruction-select crash on unpack of a non-load value#1025
Open
hunhoffe wants to merge 3 commits into
Open
[AIE] Fix instruction-select crash on unpack of a non-load value#1025hunhoffe wants to merge 3 commits into
hunhoffe wants to merge 3 commits into
Conversation
selectG_AIE_LOAD_UNPACK assumes the def feeding an unpack intrinsic is a load, but it only checks mayLoad() before calling getLoadStoreSize(), which dereferences the instruction's first memory operand. The SRS narrowing intrinsic (the lowering of acc.to_vector<int8>()) reports mayLoad() yet carries no memory operand, so feeding its result directly into aie::unpack crashed instruction-select with a SIGSEGV. Guard the combine on memoperands_empty() in both the AIE2 and AIE2P selectors so a non-load producer falls back to normal VUNPACK selection. Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>
hunhoffe
marked this pull request as ready for review
June 11, 2026 19:02
hunhoffe
requested review from
F-Stuckmann,
SagarMaheshwari99,
abhinay-anubola,
abnikant,
andcarminati,
katerynamuts,
khallouh,
konstantinschwarz,
martien-de-jong,
mludevid,
niwinanto and
stephenneuendorffer
as code owners
June 11, 2026 19:02
| // memory access (e.g. the SRS narrowing intrinsic that lowers | ||
| // acc.to_vector<int8>()). Such ops carry no memory operand, so bail out | ||
| // before getLoadStoreSize() dereferences a non-existent one. | ||
| if (!MemOp.mayLoad() || MemOp.memoperands_empty()) |
Collaborator
There was a problem hiding this comment.
Have you tried AIE2PS? If it doesn't occur there, it may mean that the memory operand modeling/handling is better there.
Collaborator
Author
There was a problem hiding this comment.
@martien-de-jong Verified — AIE2P crashes identically before this fix. The guard logic in AIE2PInstructionSelector::getCombinedOpcodeUNPACKLoad was if (!MemOp.mayLoad()) return {}; with no memoperands_empty() check, so the same null-deref SIGSEGV occurs. I confirmed this by running the new inst-select-unpack-non-load.mir test against an unpatched build (exit 139 / SIGSEGV) and a patched build (exit 0, selects VUNPACK_mv_unpack_w_unpackSign1).
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.
Note: I'm just a peano user, not a dev -- agents helped copiously in this PR, so I'd appreciate a thorough review.
Problem
Feeding the result of
acc.to_vector<int8>()directly intoaie::unpackcrashes Peano with a SIGSEGV during instruction selection, on both AIE2 and AIE2P.Minimal C++ reproducer (
clang++ --target=aie2p-none-unknown-elf -O2):Backtrace:
AIE2PInstructionSelector::getCombinedOpcodeUNPACKLoadAIE2PInstructionSelector::canCombineUNPACKLoadAIEBaseInstructionSelector::selectG_AIE_LOAD_UNPACKllvm::InstructionSelect::selectMachineFunctionRoot cause
selectG_AIE_LOAD_UNPACKtries to fold a load directly into the unpack. It gates the fold onMemOp.mayLoad(), then callsgetLoadStoreSize(MemOp), which dereferences the instruction's first memory operand:The producer here is the SRS narrowing intrinsic (the lowering of
to_vector<int8>()), aG_INTRINSIC_W_SIDE_EFFECTSthat reportsmayLoad()but carries no memory operand.memoperands_begin() == memoperands_end(), so the dereference reads an invalid pointer → segfault.Fix
Bail out of the combine when the candidate has no memory operand, so a non-load producer falls back to normal
VUNPACKselection. Applied to both the AIE2 and AIE2P selectors (both had the identical latent crash).Testing
inst-select-unpack-non-load.mir); they SIGSEGV before this change and select cleanly after.VLDB_UNPACK(existinginst-select-*vldb_unpack.mirtests unchanged).llvm/test/CodeGen/AIE/{aie2,aie2p}/GlobalIS*elsuites pass locally (391/391).