| Issue |
242907
|
| Summary |
[SLPVectorizer] Assertion in cast<TruncInst> from isCommutative when an abs operand lane is an `or`
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
arie2026
|
SLP asserts while building operands for two `llvm.abs` calls whose operands are a `sub` and an `or`.
`slpvectorizer::isCommutative` (SLPUtils.cpp) checks whether the `sub` can be commuted for an `abs` user,
and calls `hasNoSignedWrap()` on the `dyn_cast<BinaryOperator>` of that use. For the `or` lane this is not an
`OverflowingBinaryOperator`, so `Instruction::hasNoSignedWrap()` falls through to `cast<TruncInst>`.
Reproducer (`opt -passes=slp-vectorizer`, also reproduces on bab211dec4a1 and 5e457cda8d5a):
```llvm
target triple = "x86_64-unknown-linux-gnu"
define i32 @f(i32 %x, i1 %b, ptr %p) {
%s0 = sub i32 0, %x
%a0 = call i32 @llvm.abs.i32(i32 %s0, i1 true)
store i32 %a0, ptr %p, align 4
%z = zext i1 %b to i32
%o = or i32 0, %z
%a1 = call i32 @llvm.abs.i32(i32 %o, i1 true)
ret i32 %a1
}
declare i32 @llvm.abs.i32(i32, i1 immarg)
```
```
$ opt -mattr=+avx2 -passes=slp-vectorizer -disable-output test.ll
opt: llvm/include/llvm/Support/Casting.h:572: decltype(auto) llvm::cast(From *) [To = llvm::TruncInst, From = const llvm::Instruction]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
#12 bool llvm::all_of<..., llvm::slpvectorizer::isCommutative(llvm::Instruction const*, llvm::Value const*, bool)::$_0>(...)
#13 llvm::slpvectorizer::isCommutative(llvm::Instruction const*, llvm::Value const*, bool)
#14 llvm::slpvectorizer::BoUpSLP::VLOperands::appendOperands(llvm::ArrayRef<llvm::Value*>, llvm::ArrayRef<llvm::SmallVector<llvm::Value*, 8u>>, llvm::slpvectorizer::InstructionsState const&)
#15 llvm::slpvectorizer::BoUpSLP::buildTreeRec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&, unsigned int)
#16 llvm::slpvectorizer::BoUpSLP::buildTreeRec(...)
#17 llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool, bool)
#18 ... SLPVectorizerPass::vectorizeSeeds(...) callback
#19 tryToVectorizeSequence<llvm::Value>(...)
#20 llvm::SLPVectorizerPass::vectorizeOnceUsedSeeds(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&)
#21 llvm::SLPVectorizerPass::runImpl(...)
```
Expected: no crash.
Notes: the `abs` poison flag does not matter (`i1 false` also crashes). `or i32 %z, 0` also crashes, but using `%z`
directly as the second abs operand does not. A possible fix is to use `dyn_cast<OverflowingBinaryOperator>` in the
`abs` check of the `Sub` branch of `isCommutative`.
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 b23814056.
Assisted-by: Claude (Anthropic)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs