| Issue |
241481
|
| Summary |
[LoopVectorize] Assertion `must have been replicated by VF` in VPScalarIVStepsRecipe::execute
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
arie2026
|
In this tail-folded loop with a predicated `srem`, `zext i8 %iv` becomes a single-scalar `EMIT-SCALAR` cast that reads
only lane 0 of the SCALAR-STEPS, but its user `select` is widened. The lane-1 SCALAR-STEPS copy has no users and is
removed. `onlyFirstLaneUsed(steps)` looks through the `zext`, reaches the wide `select`, and returns false, so
`VPScalarIVStepsRecipe::execute` asserts.
Reproducer (`opt -force-vector-width=2 -force-vector-interleave=1 -passes=loop-vectorize`; also reproduces on 5e457cda8d5a and f2808fc79):
```llvm
define void @f(ptr %p) {
entry:
br label %loop
loop:
%iv = phi i8 [ 0, %entry ], [ %iv.next, %loop ]
%iv.next = add i8 %iv, 1
%c = icmp slt i8 %iv, 0
%z = zext i8 %iv to i32
%s = select i1 %c, i32 %z, i32 0
%t = trunc i32 %s to i8
%rem = srem i8 0, %t
%gep = getelementptr i32, ptr %p, i8 %rem
store i32 0, ptr %gep, align 4
%ec = icmp eq i8 %iv, 8
br i1 %ec, label %exit, label %loop
exit:
ret void
}
```
```
$ opt -force-vector-width=2 -force-vector-interleave=1 -passes=loop-vectorize -disable-output test.ll
opt: llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp:3479: virtual void llvm::VPScalarIVStepsRecipe::execute(VPTransformState &): Assertion `(vputils::onlyFirstLaneUsed(this) || State.VF.isScalar()) && "must have been replicated by VF"' failed.
#11 <unsymbolized; the asserting VPScalarIVStepsRecipe::execute>
#12 llvm::VPBasicBlock::executeRecipes(...)
#13 llvm::VPBasicBlock::execute(...)
#14 llvm::VPlan::execute(...)
#15 llvm::LoopVectorizationPlanner::executePlan(...)
#16 llvm::LoopVectorizePass::processLoop(...)
#17 llvm::LoopVectorizePass::runImpl(...)
#18 llvm::LoopVectorizePass::run(...)
```
Final plan (excerpt): `vp<%6> = SCALAR-STEPS vp<%5>, ir<1>, ir<2>` / `EMIT-SCALAR ir<%z> = zext vp<%6> to i32` /
`WIDEN ir<%s> = select ir<%c>, ir<%z>, ir<0>` / `EMIT-SCALAR ir<%t> = trunc ir<%s> to i8` / `EMIT vp<%8> = srem ir<0>, vp<%7>`.
Expected: no crash. The plan should be consistent: either `%z` provides all lanes to the widened `select`, or the `select` is narrowed too.
Notes: needs tail folding. Trip count 8 or 100, an unknown trip count, `udiv` instead of `srem`, or removing the `select`
avoids it; `sdiv` crashes too. The fuzzer's original test also crashes with `-mtriple=x86_64-unknown-linux-gnu -mattr=+avx2`
and no forced VF. The assertion was added in #224399. I haven't pinned down which transform widens the `select`.
cc @fhahn
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