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

    <tr>
        <th>Summary</th>
        <td>
            loop-vectorize pass fails with “Don't know how to legalize this scalable vector type” when targeting neoverse-v1 and v2
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          ashermancinelli
      </td>
    </tr>
</table>

<pre>
    Test case: 
```llvm
; opt -passes=loop-vectorize -mcpu=neoverse-v2
; ModuleID = 'bugpoint-reduced-simplified.bc'
source_filename = "foo.ll"
target triple = "arm64-linux"
@string = internal unnamed_addr constant [5 x i8] c"abcd\00", align 1
define dso_local i32 @test(ptr %z) local_unnamed_addr {
L.entry:
  %0 = load ptr, ptr %z, align 8
  %1 = getelementptr i8, ptr %0, i64 16
  %2 = load i128, ptr %1, align 16
  %3 = icmp slt i128 %2, 1
  br i1 %3, label %return, label %loopbody.preheader
loopbody.preheader: ; preds = %L.entry
  %4 = load ptr, ptr %0, align 8
  br label %loopbody
loopbody: ; preds = %loopbody.preheader, %loopbody
  %a = phi ptr [ %5, %loopbody ], [ %4, %loopbody.preheader ]
  %b = phi ptr [ %6, %loopbody ], [ @string, %loopbody.preheader ]
  %len_input = phi i128 [ %len, %loopbody ], [ %2, %loopbody.preheader ]
  %len = add nsw i128 %len_input, -1
  %5 = getelementptr i8, ptr %a, i64 1
  %6 = getelementptr i8, ptr %b, i64 1
  %7 = load i8, ptr %b, align 1
  store i8 %7, ptr %a, align 4
  %.not = icmp eq i128 %len, 0
  br i1 %.not, label %return, label %loopbody
return: ; preds = %loopexit, %L.entry
  ret i32 undef
}
```

<summary>Stack trace:</summary>

```
LLVM ERROR: Don't know how to legalize this scalable vector type
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: llvm-install/bin/opt -passes=loop-vectorize t.ll -mcpu=neoverse-v1 -S -o t2.ll
#0 0x0000aaaac548c9d0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (llvm-install/bin/opt+0x19cc9d0)
#1 0x0000aaaac548ab98 llvm::sys::RunSignalHandlers() (llvm-install/bin/opt+0x19cab98)
#2 0x0000aaaac548d218 SignalHandler(int) (llvm-install/bin/opt+0x19cd218)
#3 0x0000ffff9587e860 (linux-vdso.so.1+0x860)
#4 0x0000ffff95585530 raise (/lib64/libc.so.6+0x32530)
#5 0x0000ffff95586d74 abort (/lib64/libc.so.6+0x33d74)
#6 0x0000aaaac541ea54 llvm::report_fatal_error(llvm::Twine const&, bool) (llvm-install/bin/opt+0x195ea54)
#7 0x0000aaaac541e87c llvm::report_fatal_error(llvm::Twine const&, bool) (llvm-install/bin/opt+0x195e87c)
#8 0x0000aaaac4bfcb14 llvm::TargetLoweringBase::getVectorTypeBreakdown(llvm::LLVMContext&, llvm::EVT, llvm::EVT&, unsigned int&, llvm::MVT&) const (llvm-install/bin/opt+0x113cb14)
#9 0x0000aaaac423c754 llvm::TargetLoweringBase::getNumRegisters(llvm::LLVMContext&, llvm::EVT, std::optional<llvm::MVT>) const (llvm-install/bin/opt+0x77c754)
#10 0x0000aaaac55fa950 llvm::LoopVectorizationCostModel::calculateRegisterUsage(llvm::ArrayRef<llvm::ElementCount>) (llvm-install/bin/opt+0x1b3a950)
#11 0x0000aaaac55fd6e4 llvm::LoopVectorizationCostModel::selectInterleaveCount(llvm::ElementCount, llvm::InstructionCost) (llvm-install/bin/opt+0x1b3d6e4)
#12 0x0000aaaac56166b0 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (llvm-install/bin/opt+0x1b566b0)
#13 0x0000aaaac561aee4 llvm::LoopVectorizePass::runImpl(llvm::Function&, llvm::ScalarEvolution&, llvm::LoopInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::BlockFrequencyInfo&, llvm::TargetLibraryInfo*, llvm::DemandedBits&, llvm::AssumptionCache&, llvm::LoopAccessInfoManager&, llvm::OptimizationRemarkEmitter&, llvm::ProfileSummaryInfo*) (llvm-install/bin/opt+0x1b5aee4)
#14 0x0000aaaac561b348 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (llvm-install/bin/opt+0x1b5b348)
#15 0x0000aaaac4eb465c llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (llvm-install/bin/opt+0x13f465c)
#16 0x0000aaaac4eb75dc llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (llvm-install/bin/opt+0x13f75dc)
#17 0x0000aaaac4eb3a5c llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (llvm-install/bin/opt+0x13f3a5c)
#18 0x0000aaaac40ee9d4 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool) (llvm-install/bin/opt+0x62e9d4)
#19 0x0000aaaac40fc5bc main (llvm-install/bin/opt+0x63c5bc)
#20 0x0000ffff95572da4 __libc_start_main (/lib64/libc.so.6+0x1fda4)
#21 0x0000aaaac40e861c _start (llvm-install/bin/opt+0x62861c)
Aborted
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEWVtz4yoS_jXkhbJLQjf7IQ--xLVTm9mTSrLz6kLQstkg0AGUy_n1WyBfJMdJnNmqs1NT5Vh0f_193dAgTK0VGwVwjbI5ypZXtHVbba6p3YKpqWJCgZTiqtT87foRrMOMWkDJDKNoiaIZyqPuv5T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