<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/55096>55096</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang][LoopVectorizer] Assertion `I->getOpcode() == Instruction::GetElementPtr || I->getOpcode() == Instruction::PHI || (I->getOpcode() == Instruction::BitCast && I->getType()->isPointerTy()) || hasSingleCopyAfterVectorization(I, VF)' failed.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          max-quazan
      </td>
    </tr>
</table>

<pre>
    This bug was found by Azul FuzzGen fuzzer for CPP.

Godbolt link: https://godbolt.org/z/v1qY194oo

Run clang -O3 (x86_64) on the test ([test.cpp.txt](https://github.com/llvm/llvm-project/files/8560402/test.cpp.txt))

Failure looks like
```
                                                           ^~~
clang++: /root/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:6981: llvm::InstructionCost llvm::LoopVectorizationCostModel::getInstructionCost(llvm::Instruction*, llvm::ElementCount, llvm::Type*&): Assertion `I->getOpcode() == Instruction::GetElementPtr || I->getOpcode() == Instruction::PHI || (I->getOpcode() == Instruction::BitCast && I->getType()->isPointerTy()) || hasSingleCopyAfterVectorization(I, VF)' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -g -o /app/output.s -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O3 <source>
1.      <eof> parser at end of file
2.      Optimizer
 #0 0x000055c2134e8aaf PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x000055c2134e6814 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ae6814)
 #2 0x000055c21341be78 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f65a830a3c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x143c0)
 #4 0x00007f65a7dd703b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4303b)
 #5 0x00007f65a7db6859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007f65a7db6729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007f65a7dc8006 (/lib/x86_64-linux-gnu/libc.so.6+0x34006)
 #8 0x000055c21370b9be llvm::LoopVectorizationCostModel::getInstructionCost(llvm::Instruction*, llvm::ElementCount, llvm::Type*&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3d0b9be)
 #9 0x000055c21370ce3a llvm::LoopVectorizationCostModel::getInstructionCost(llvm::Instruction*, llvm::ElementCount) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3d0ce3a)
#10 0x000055c21370d46e llvm::LoopVectorizationCostModel::expectedCost(llvm::ElementCount, llvm::SmallVectorImpl<std::pair<llvm::Instruction*, llvm::ElementCount> >*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3d0d46e)
#11 0x000055c21370f2a0 llvm::LoopVectorizationCostModel::selectVectorizationFactor(llvm::SmallSet<llvm::ElementCount, 16u, llvm::ElementCountComparator> const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3d0f2a0)
#12 0x000055c2137209a5 llvm::LoopVectorizationPlanner::plan(llvm::ElementCount, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3d209a5)
#13 0x000055c213722e43 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3d22e43)
#14 0x000055c213724d41 llvm::LoopVectorizePass::runImpl(llvm::Function&, llvm::ScalarEvolution&, llvm::LoopInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::BlockFrequencyInfo&, llvm::TargetLibraryInfo*, llvm::DemandedBits&, llvm::AAResults&, llvm::AssumptionCache&, std::function<llvm::LoopAccessInfo const& (llvm::Loop&)>&, llvm::OptimizationRemarkEmitter&, llvm::ProfileSummaryInfo*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3d24d41)
#15 0x000055c2137252d9 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3d252d9)
#16 0x000055c21473e111 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4d3e111)
#17 0x000055c212c9b25c llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x329b25c)
#18 0x000055c2110fe6e1 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x16fe6e1)
#19 0x000055c212c9ac7a llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x329ac7a)
#20 0x000055c2110ff041 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x16ff041)
#21 0x000055c212c99434 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3299434)
#22 0x000055c21382c487 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile> >&) (.constprop.777) BackendUtil.cpp:0:0
#23 0x000055c21382f36a clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3e2f36a)
#24 0x000055c21455ea5b clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b5ea5b)
#25 0x000055c215512569 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5b12569)
#26 0x000055c21455d590 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b5d590)
#27 0x000055c213ee43a9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44e43a9)
#28 0x000055c213e7deca clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x447deca)
#29 0x000055c213fb1ed3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x45b1ed3)
#30 0x000055c210e33381 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x1433381)
#31 0x000055c210e2f219 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#32 0x000055c213d164b5 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#33 0x000055c21341c463 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a1c463)
#34 0x000055c213d18846 clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4318846)
#35 0x000055c213cea7da clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42ea7da)
#36 0x000055c213ceb46f clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42eb46f)
#37 0x000055c213cf3f6a clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42f3f6a)
#38 0x000055c210d7701c main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x137701c)
#39 0x00007f65a7db80b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b3)
#40 0x000055c210e2ed8a _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x142ed8a)
clang-15: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztWkt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