<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/87384>87384</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[SLP] Attempted invalid cast from `VectorType` to `FixedVectorType`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
patrick-rivos
</td>
</tr>
</table>
<pre>
Reduced LLVM-IR:
```llvm ir
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
target triple = "riscv64-unknown-linux-gnu"
define i32 @main() #0 {
entry:
%vector.recur.extract = extractelement <vscale x 4 x i8> zeroinitializer, i64 0
%0 = load i8, ptr getelementptr ([9 x i8], ptr null, i64 -2, i64 5), align 1
%tobool1.not = icmp ne i8 %0, 0
%conv2 = zext i1 %tobool1.not to i16
store i16 %conv2, ptr getelementptr ([0 x i16], ptr null, i64 0, i64 -14), align 2
%conv5 = sext i8 %vector.recur.extract to i32
store i32 %conv5, ptr getelementptr ([0 x i32], ptr null, i64 0, i64 -14), align 4
%1 = load i8, ptr getelementptr ([9 x i8], ptr null, i64 -2, i64 6), align 1
%tobool1.not.1 = icmp ne i8 %1, 0
%conv2.1 = zext i1 %tobool1.not.1 to i16
store i16 %conv2.1, ptr getelementptr ([0 x i16], ptr null, i64 0, i64 -13), align 2
%conv5.1 = sext i8 %0 to i32
store i32 %conv5.1, ptr getelementptr ([0 x i32], ptr null, i64 0, i64 -13), align 4
ret i32 0
}
; uselistorder directives
uselistorder i64 0, { 1, 2, 3, 4, 0 }
uselistorder ptr null, { 1, 3, 5, 0, 2, 4 }
attributes #0 = { "target-features"="+64bit,+v" }
```
Backtrace:
```
opt: /scratch/tc-testing/tc-apr-2/llvm/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::FixedVectorType; From = llvm::VectorType]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt reduced.ll --passes=slp-vectorizer
#0 0x000064cd745d5b60 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2d84b60)
#1 0x000064cd745d2f6f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2d81f6f)
#2 0x000064cd745d30c5 SignalHandler(int) Signals.cpp:0:0
#3 0x0000756def442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x0000756def4969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x0000756def4969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x0000756def4969fc pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x0000756def442476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
#8 0x0000756def4287f3 abort ./stdlib/abort.c:81:7
#9 0x0000756def42871b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x0000756def439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x000064cd7366f9f1 llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::computeExtractCost(llvm::ArrayRef<llvm::Value*>, llvm::ArrayRef<int>, llvm::ArrayRef<std::optional<llvm::TargetTransformInfo::ShuffleKind>>, unsigned int) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1e1e9f1)
#12 0x000064cd736a7e0d llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::adjustExtracts(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::MutableArrayRef<int>, llvm::ArrayRef<std::optional<llvm::TargetTransformInfo::ShuffleKind>>, unsigned int, bool&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1e56e0d)
#13 0x000064cd736e4d02 llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::processBuildVector<llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator, llvm::InstructionCost, llvm::TargetTransformInfo, llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP, llvm::SmallPtrSetImpl<llvm::Value*>>(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::TargetTransformInfo&, llvm::ArrayRef<llvm::Value*>&, llvm::slpvectorizer::BoUpSLP&, llvm::SmallPtrSetImpl<llvm::Value*>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1e93d02)
#14 0x000064cd736e7ed2 llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1e96ed2)
#15 0x000064cd736fd2a1 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1eac2a1)
#16 0x000064cd7370c015 llvm::SLPVectorizerPass::vectorizeStoreChain(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, unsigned int, unsigned int) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1ebb015)
#17 0x000064cd7370cf74 llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef<llvm::StoreInst*>, llvm::slpvectorizer::BoUpSLP&)::'lambda'(std::set<std::pair<unsigned int, int>, llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef<llvm::StoreInst*>, llvm::slpvectorizer::BoUpSLP&)::StoreDistCompare, std::allocator<std::pair<unsigned int, int>>> const&)::operator()(std::set<std::pair<unsigned int, int>, llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef<llvm::StoreInst*>, llvm::slpvectorizer::BoUpSLP&)::StoreDistCompare, std::allocator<std::pair<unsigned int, int>>> const&) const SLPVectorizer.cpp:0:0
#18 0x000064cd7370da80 llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef<llvm::StoreInst*>, llvm::slpvectorizer::BoUpSLP&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1ebca80)
#19 0x000064cd7370e147 llvm::SLPVectorizerPass::vectorizeStoreChains(llvm::slpvectorizer::BoUpSLP&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1ebd147)
#20 0x000064cd7370f2df llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0
#21 0x000064cd7370fceb llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1ebeceb)
#22 0x000064cd7255ab86 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0xd09b86)
#23 0x000064cd743fc141 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2bab141)
#24 0x000064cd72551bd6 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0xd00bd6)
#25 0x000064cd743fae3b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2ba9e3b)
#26 0x000064cd72559dc6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0xd08dc6)
#27 0x000064cd743f8cb1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2ba7cb1)
#28 0x000064cd71dd3ce5 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x582ce5)
#29 0x000064cd71dc6316 optMain (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x575316)
#30 0x0000756def429d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#31 0x0000756def429e40 call_init ./csu/../csu/libc-start.c:128:20
#32 0x0000756def429e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#33 0x000064cd71dbbf95 _start (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x56af95)
zsh: IOT instruction (core dumped) /scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt reduced.l
```
Godbolt: https://godbolt.org/z/h7oWvrqvf
Found via fuzzer.
@alexey-bataev
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWl9z4ygS_zTkhbILof8PebCd-G7qMrWpSW7u0YUA2ewgoQPkSfLpr0C2IymexMmOt-Zub8rjyAh-dPev6W4kiDFiXXN-CeI5iK8uSGs3Sl82xGpBv0202CpzUSj2ePmFs5ZyBm9uvn6efPoCwhlAVwDNQIK6j5TbCgrdtVqi19xCRiyR5FG1FoLwCgKM-aQC4YxPGhDOksh_TcThIsAZCGcBziZ1iLu2O9eG8QDWatFIvofUwtBtEk3a-lutvtcTKer2YbKu28Ow7pvxUtQcihBDEKGKiBo46BwCHCII0nnXjddWPx7UgwDHW06t0lPNaaun_MFqQjt9dtdc8orXrmmxNZRIDh9gBB-gyEB4DZ-4VqIWVhApnrgGeAFFEkG0w3cTII8mFWFuDF7Axmq45ntg98uJGs_zDjW-2neqWyn3iBO8v4oBzt01kWJdw6A3k1WFUjKY1qrTQNCqgc4omZfDDeoLRlW9xb7jE3-wUARjDKugCJL9CGOV5q7hMPY1ZZBTJkh-oA06qBVEA3XwSL7Yy2e8fNkP6XKChngkqPOEHcibgob4vYJGPUGDn8xwcgrD0-AIx8FRjnddj7M8Dd7keRr8FKbD15neSdnjGr1J7AmSnUJteJxaza2fbWdQkF71Iw4I57A1XAonFuMaMqE5tWLLTddhcPMwI0jn0Evt6Q7dV-RZgwf8wcC-2Iexfljckb2HiuBIQGKtFkVrudkFQRdR07mLql2onZSc2FZz42JpeOW-8TyJCmEBXgA83wKMe6D7XNCfY07oN7cG-cuU0f1UjQWhC7RLQzWxdAPw0tKJ5caKet39II12zr90Seb5j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