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

    <tr>
        <th>Summary</th>
        <td>
            [RISC-V] Error in backend: Invalid size request on a scalable vector.
        </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>
    Testcase:
```c
int a, c;
char b;
_Bool d[1];
int main() {
  for (short e = 0; e < c; e += 4) {
 a = d[e] ? 0 : 20;
    b &= d[e];
  }
}
```

Flags: `-march=rv64gcv_zvl256b -O3 -mrvv-vector-bits=zvl`

Backtrace (from godbolt since mine didn't have the full backtrace):
```
fatal error: error in backend: Invalid size request on a scalable vector.
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-trunk/bin/clang -g -o /app/output.s -S -target riscv64-unknown-linux-gnu -march=rv64gc -mabi=lp64d --gcc-toolchain=/opt/compiler-explorer/riscv64/gcc-8.2.0/riscv64-unknown-linux-gnu --sysroot=/opt/compiler-explorer/riscv64/gcc-8.2.0/riscv64-unknown-linux-gnu/riscv64-unknown-linux-gnu/sysroot -fcolor-diagnostics -fno-crash-diagnostics -march=rv64gcv_zvl256b -O2 -mrvv-vector-bits=zvl <source>
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module '<source>'.
4.      Running pass 'RISC-V DAG->DAG Pattern Instruction Selection' on function '@main'
 #0 0x00000000036ad1a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+0x36ad1a8)
 #1 0x00000000036ab2f4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+0x36ab2f4)
 #2 0x00000000035f4373 llvm::CrashRecoveryContext::HandleExit(int) (/opt/compiler-explorer/clang-trunk/bin/clang+0x35f4373)
 #3 0x00000000036a28de llvm::sys::Process::Exit(int, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+0x36a28de)
 #4 0x0000000000c4de16 (/opt/compiler-explorer/clang-trunk/bin/clang+0xc4de16)
 #5 0x00000000035fd3c3 llvm::report_fatal_error(llvm::Twine const&, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+0x35fd3c3)
 #6 0x00000000035fd528 (/opt/compiler-explorer/clang-trunk/bin/clang+0x35fd528)
 #7 0x000000000365129d (/opt/compiler-explorer/clang-trunk/bin/clang+0x365129d)
 #8 0x00000000036512bc llvm::TypeSize::operator unsigned long() const (/opt/compiler-explorer/clang-trunk/bin/clang+0x36512bc)
 #9 0x000000000487e9d8 llvm::DAGTypeLegalizer::SplitVecRes_BITCAST(llvm::SDNode*, llvm::SDValue&, llvm::SDValue&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x487e9d8)
#10 0x000000000489d59d llvm::DAGTypeLegalizer::SplitVectorResult(llvm::SDNode*, unsigned int) (/opt/compiler-explorer/clang-trunk/bin/clang+0x489d59d)
#11 0x00000000048642ba llvm::DAGTypeLegalizer::run() (/opt/compiler-explorer/clang-trunk/bin/clang+0x48642ba)
#12 0x0000000004864971 llvm::SelectionDAG::LegalizeTypes() (/opt/compiler-explorer/clang-trunk/bin/clang+0x4864971)
#13 0x00000000047e6281 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/compiler-explorer/clang-trunk/bin/clang+0x47e6281)
#14 0x00000000047e90c8 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x47e90c8)
#15 0x00000000047eb8a9 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (.part.0) SelectionDAGISel.cpp:0:0
#16 0x0000000002b26cd0 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#17 0x0000000003066a12 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3066a12)
#18 0x0000000003066b91 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3066b91)
#19 0x0000000003068840 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3068840)
#20 0x000000000391f3de clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-trunk/bin/clang+0x391f3de)
#21 0x0000000003f15269 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3f15269)
#22 0x0000000005dca6ac clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+0x5dca6ac)
#23 0x0000000003f146c5 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+0x3f146c5)
#24 0x00000000041aa421 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+0x41aa421)
#25 0x000000000412fdcb clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x412fdcb)
#26 0x000000000428d863 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+0x428d863)
#27 0x0000000000c4fc0c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+0xc4fc0c)
#28 0x0000000000c49bbd ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#29 0x0000000003f5d519 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#30 0x00000000035f4273 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+0x35f4273)
#31 0x0000000003f5d739 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#32 0x0000000003f23d17 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+0x3f23d17)
#33 0x0000000003f246cd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+0x3f246cd)
#34 0x0000000003f2e4bc clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3f2e4bc)
#35 0x0000000000c4d071 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+0xc4d071)
#36 0x0000000000b30454 main (/opt/compiler-explorer/clang-trunk/bin/clang+0xb30454)
#37 0x00007f06f7029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#38 0x00007f06f7029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#39 0x0000000000c4971e _start (/opt/compiler-explorer/clang-trunk/bin/clang+0xc4971e)
clang: error: clang frontend command failed with exit code 70 (use -v to see invocation)
Compiler returned: 70
```
Godbolt: https://godbolt.org/z/GTGx74fjz

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:
 %0 = bitcast <vscale x 16 x i8> zeroinitializer to <vscale x 128 x i1>
 %extract.t = extractelement <vscale x 128 x i1> %0, i64 0
  %cond = select i1 %extract.t, i32 0, i32 1
  store i32 %cond, ptr null, align 4
  ret i32 0
}

attributes #0 = { "target-features"="+64bit,+v" }
```
Godbolt: https://godbolt.org/z/fs6vjGj8W

Found via fuzzer.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWt9z26qz_2vIC6OMhH76IQ-OHefkTHubiXN7Hz0IkEOLwQeQm-Svv4OQHaHYbc-Jz_fl22ldiR-7H3aX3QUtNoavJWNXIL8G-fwCt_ZJ6asttpqT75HmO2UuakVfrh6ZsQQbBtIpiOcgnoIi9n-Jf-fSQgzQDBKQXvsm8oQ1rA-vq2ulBKQgv05APj80u4kbzCVAFUATCMq-HcJGaQhQZZ6UtpBBkM5hDNLr7tHzcY_o2nVk4VzcjXa8GMjnEKQLGEOQTiGKD4whhLCGABXDoYNeUM77pR4e9mvuX7vfhcBr40iDIo42WJMnkM71rsjWZLd63QmUFzWMvqQw2ujdLtoxYpWOam4NSOevOzEid43Jd6sxcSurGq02cK1orYSFhkvC4IZLBimnEqDSwie8Y9A-Mdi0QsB6PxegyXtF-dcGWywg01ppB7p7gFx2c5mkru1O7rDgFBr-yqBmf7XMWKgkxNAQLHAtGPSruPQk7z_dTJc30LT1hluIYd2uoWZbpzWr4JO1WycfgBYALdbcPrX1JVEbgBZC7Pb_RVutvjFiAVpwY1pmAFpALCnkkoiW-kUSjc3TcJUzuNVsqxVhxjAKjWq1b3YzsTGKcGwZhbqV0BDNt7aHvLSYfIe03WwPcoovQTy512qt8QZivW43TFqvWLRQW4eMqM2WC6Yj9rwVSjPt2gSW68jqVn4H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