<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63585>63585</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[ImplicitNullChecks] Assertion `detail::isPresent(Va l) && "dyn_cast on a non-existent value"' failed.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dantrushin
</td>
</tr>
</table>
<pre>
[implicit_null_check_nonvalue_mmo.txt](https://github.com/llvm/llvm-project/files/11898078/implicit_null_check_nonvalue_mmo.txt)
Attached test (rename from .txt to .ll) demonstrates assertion failure in ImplicitNullChecks pass.
The reason is that this pass assumes MachineMemOperand must have a value, which is not always true.
For example, `@llvm.experimental.load.masked.gather` intrinsic is lowered in a way that resulting machine instruction(s) do not have meaningful MMO.
Full backtrace:
```
llc: LLVM/llvm/include/llvm/Support/Casting.h:662: decltype(auto) llvm::dyn_cast(From*) [with To = llvm::Instruction; From = const llvm::Value]: Assertion `detail::isPresent(Va
l) && "dyn_cast on a non-existent value"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: LLVM.BUILD/bin/llc -enable-implicit-null-checks -mcpu=skylake-avx512
1. Running pass 'Function Pass Manager' on module '<stdin>'.
2. Running pass 'Implicit null checks' on function '@test'
#0 0x0000000001a7d4cc llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) LLVM/llvm/lib/Support/Unix/Signals.inc:606:0
#1 0x0000000001a7b2e4 llvm::sys::RunSignalHandlers() LLVM/llvm/lib/Support/Signals.cpp:104:0
#2 0x0000000001a7bc03 SignalHandler(int) LLVM/llvm/lib/Support/Unix/Signals.inc:403:0
#3 0x00007fe93b108630 __restore_rt sigaction.c:0:0
#4 0x00007fe939c64387 raise (/lib64/libc.so.6+0x36387)
#5 0x00007fe939c65a78 abort (/lib64/libc.so.6+0x37a78)
#6 0x00007fe939c5d1a6 __assert_fail_base (/lib64/libc.so.6+0x2f1a6)
#7 0x00007fe939c5d252 (/lib64/libc.so.6+0x2f252)
#8 0x0000000000acddd6 (LLVM.BUILD/bin/llc+0xacddd6)
#9 0x0000000000acddf9 notDifferentParent(llvm::Value const*, llvm::Value const*) LLVM/llvm/lib/Analysis/BasicAliasAnalysis.cpp:838:0
#10 0x0000000000ad82d0 llvm::BasicAAResult::alias(llvm::MemoryLocation const&, llvm::MemoryLocation const&, llvm::AAQueryInfo&, llvm::Instruction const*) LLVM/llvm/lib/Analysis/BasicAliasAnalysis.cpp:845:0
#11 0x0000000000ac8c40 llvm::AAResults::alias(llvm::MemoryLocation const&, llvm::MemoryLocation const&, llvm::AAQueryInfo&, llvm::Instruction const*) LLVM/llvm/lib/Analysis/AliasAnalysis.cpp:125:0
#12 0x0000000000ac9167 llvm::SmallDenseMap<llvm::Value const*, bool, 8u, llvm::DenseMapInfo<llvm::Value const*, void>, llvm::detail::DenseMapPair<llvm::Value const*, bool>>::deallocateBuckets() LLVM/llvm/include/llvm/ADT/DenseMap.h:1201:0
#13 0x0000000000ac9167 llvm::SmallDenseMap<llvm::Value const*, bool, 8u, llvm::DenseMapInfo<llvm::Value const*, void>, llvm::detail::DenseMapPair<llvm::Value const*, bool>>::~SmallDenseMap() LLVM/llvm/include/llvm/ADT/DenseMap.h:961:0
#14 0x0000000000ac9167 llvm::SimpleCaptureInfo::~SimpleCaptureInfo() LLVM/llvm/include/llvm/Analysis/AliasAnalysis.h:162:0
#15 0x0000000000ac9167 llvm::SimpleAAQueryInfo::~SimpleAAQueryInfo() LLVM/llvm/include/llvm/Analysis/AliasAnalysis.h:293:0
#16 0x0000000000ac9167 llvm::AAResults::alias(llvm::MemoryLocation const&, llvm::MemoryLocation const&) LLVM/llvm/lib/Analysis/AliasAnalysis.cpp:107:0
#17 0x00000000006a01d2 (anonymous namespace)::ImplicitNullChecks::areMemoryOpsAliased(llvm::MachineInstr const&, llvm::MachineInstr const*) const (.isra.145) LLVM/llvm/lib/CodeGen/ImplicitNullChecks.cpp:354:0
#18 0x0000000000e05d93 isSuitableMemoryOp LLVM/llvm/lib/CodeGen/ImplicitNullChecks.cpp:471:0
#19 0x0000000000e05d93 analyzeBlockForNullChecks LLVM/llvm/lib/CodeGen/ImplicitNullChecks.cpp:683:0
#20 0x0000000000e05d93 (anonymous namespace)::ImplicitNullChecks::runOnMachineFunction(llvm::MachineFunction&) LLVM/llvm/lib/CodeGen/ImplicitNullChecks.cpp:310:0
#21 0x0000000000effd90 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.72) LLVM/llvm/lib/CodeGen/MachineFunctionPass.cpp:93:0
#22 0x00000000013f2ff6 llvm::FPPassManager::runOnFunction(llvm::Function&) LLVM/llvm/lib/IR/LegacyPassManager.cpp:1445:0
#23 0x00000000013f3219 llvm::ilist_node_impl<llvm::ilist_detail::node_options<llvm::Function, true, false, void>>::getNext() LLVM/llvm/include/llvm/ADT/ilist_node.h:67:0
#24 0x00000000013f3219 llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Function, true, false, void>, false, false>::operator++() LLVM/llvm/include/llvm/ADT/ilist_iterator.h:157:0
#25 0x00000000013f3219 llvm::FPPassManager::runOnModule(llvm::Module&) LLVM/llvm/lib/IR/LegacyPassManager.cpp:1480:0
#26 0x00000000013f3ea8 runOnModule LLVM/llvm/lib/IR/LegacyPassManager.cpp:1557:0
#27 0x00000000013f3ea8 llvm::legacy::PassManagerImpl::run(llvm::Module&) LLVM/llvm/lib/IR/LegacyPassManager.cpp:535:0
#28 0x00000000007374ef compileModule(char**, llvm::LLVMContext&) LLVM/llvm/tools/llc/llc.cpp:759:0
#29 0x00000000006d8ea7 main LLVM/llvm/tools/llc/llc.cpp:420:0
#30 0x00007fe939c50555 __libc_start_main (/lib64/libc.so.6+0x22555)
#31 0x000000000072ea76 _start (LLVM.BUILD/bin/llc+0x72ea76)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.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