| Issue |
241471
|
| Summary |
[SLPVectorizer] Assertion `Expected and/shift in the bit pack.` with an `add x, 0` lane
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
arie2026
|
SLP recognises a byte-packing `or` reduction as a bit pack, but one lane is `add %za, 0` instead of `shl %za, 0`.
The interchangeable-opcode logic puts that lane into the `shl` node, but the bit-pack scalar-cost lambda
(`GetLaneCost` in `getEntryCost`) checks the original opcode and asserts. `sub x, 0` and `mul x, 1` lanes crash the same way.
Reproducer (`opt -passes=slp-vectorizer`, no target flags needed; also reproduces on 5e457cda8d5a and f2808fc79):
```llvm
define i32 @pack(i8 %a, i8 %b, i8 %c, i8 %d) {
%za = zext i8 %a to i32
%zb = zext i8 %b to i32
%zc = zext i8 %c to i32
%zd = zext i8 %d to i32
%sa = add i32 %za, 0
%sb = shl i32 %zb, 8
%sc = shl i32 %zc, 16
%sd = shl i32 %zd, 24
%o1 = or i32 %sa, %sb
%o2 = or i32 %o1, %sc
%o3 = or i32 %o2, %sd
ret i32 %o3
}
```
```
$ opt -passes=slp-vectorizer -disable-output test.ll
opt: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:17657: auto llvm::slpvectorizer::BoUpSLP::getEntryCost(...)::(anonymous class)::operator()(unsigned int) const: Assertion `is_contained( {Instruction::And, Instruction::LShr, Instruction::Shl}, I->getOpcode()) && "Expected and/shift in the bit pack."' failed.
2. Running pass "slp-vectorizer" on function "pack"
#11 <unsymbolized; presumably the GetLaneCost lambda>
#12 BoUpSLP::getEntryCost(...)::$_2::operator()(...) const
#13 BoUpSLP::getEntryCost(...)
#14 BoUpSLP::calculateTreeCostAndTrimNonProfitable(...)
#15 (anonymous namespace)::HorizontalReduction::tryToReduce(...)
#16 llvm::SLPVectorizerPass::vectorizeHorReduction(...)
#17 llvm::SLPVectorizerPass::vectorizeChainsInBlock(...)
#18 llvm::SLPVectorizerPass::runImpl(...)
#19 llvm::SLPVectorizerPass::run(...)
```
Expected: no crash. Either cost the `add %za, 0` lane as the `shl %za, 0` it stands for, or don't form the bit pack.
Notes: `-debug-_only_=SLP` shows the node `[add %za,0; shl %zb,8; shl %zc,16; shl %zd,24]` with MainOp=shl, State=Vectorize,
and no copyable lanes, so the copyable-element skip in `GetLaneCost` doesn't apply. The assertion was added in #232419.
Writing `shl i32 %za, 0` (or `or %za, 0`) instead does not crash. cc @alexey-bataev
Found with a mutation-based IR fuzzer. Triage, test-case minimization and parts of this write-up were assisted by an LLM; verified the reproducer on 9dce18f0e.
Assisted-by: Claude (Anthropic)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs