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

    <tr>
        <th>Summary</th>
        <td>
            [clang][ICE] Assertion `Reg < Regs.size() && "Mismatch in # registers expected"' failed.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

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

<pre>
    DejaGnu testcase:
avx512bw-kaddq-1.c
```
#include <immintrin.h>

void
avx512bw_test ()
{
  __mmask64 k = _kadd_mask64 (11, 12);
  asm volatile ("" : "+k" (k));
}
```
compile command:
```
clang avx512bw-kaddq-1.c -mavx512bw -m32 -S
```
```
clang: /root/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:1039: void llvm::RegsForValue::AddInlineAsmOperands(llvm::InlineAsm::Kind, bool, unsigned int, const llvm::SDLoc&, llvm::SelectionDAG&, std::vector<llvm::SDValue, std::allocator<llvm::SDValue> >&) const: Assertion `Reg < Regs.size() && "Mismatch in # registers expected"' 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 -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-9.2.0 -fcolor-diagnostics -fno-crash-diagnostics -mavx512bw -m32 <source>
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module '<source>'.
4.      Running pass 'X86 DAG->DAG Instruction Selection' on function '@avx512bw_test'
 #0 0x00000000037de8b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x37de8b8)
 #1 0x00000000037dc59c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x37dc59c)
 #2 0x0000000003724de8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007fe700e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007fe700e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007fe700e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007fe700e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007fe700e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007fe700e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x000000000483d3ef llvm::RegsForValue::AddInlineAsmOperands(llvm::InlineAsm::Kind, bool, unsigned int, llvm::SDLoc const&, llvm::SelectionDAG&, std::vector<llvm::SDValue, std::allocator<llvm::SDValue>>&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x483d3ef)
#10 0x000000000486b0ae llvm::SelectionDAGBuilder::visitInlineAsm(llvm::CallBase const&, llvm::BasicBlock const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x486b0ae)
#11 0x000000000485ae47 llvm::SelectionDAGBuilder::visitCall(llvm::CallInst const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x485ae47)
#12 0x000000000488d9d2 llvm::SelectionDAGBuilder::visit(llvm::Instruction const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x488d9d2)
#13 0x0000000004911f9d llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true>, false, true>, llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true>, false, true>, bool&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4911f9d)
#14 0x0000000004912e18 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4912e18)
#15 0x0000000004914c27 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (.part.0) SelectionDAGISel.cpp:0:0
#16 0x00000000023dd03c (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) X86ISelDAGToDAG.cpp:0:0
#17 0x0000000002bd0901 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#18 0x00000000031901e9 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x31901e9)
#19 0x0000000003190421 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3190421)
#20 0x0000000003190c62 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3190c62)
#21 0x0000000003a57296 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) BackendUtil.cpp:0:0
#22 0x0000000003a57621 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-assertions-trunk/bin/clang+0x3a57621)
#23 0x000000000405e98c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x405e98c)
#24 0x0000000005fd6149 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5fd6149)
#25 0x000000000405dd28 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x405dd28)
#26 0x00000000042cae49 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x42cae49)
#27 0x0000000004249f7e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4249f7e)
#28 0x00000000043aa64e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x43aa64e)
#29 0x0000000000c05476 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc05476)
#30 0x0000000000bfcd3a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#31 0x000000000409ee69 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
#32 0x0000000003725294 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3725294)
#33 0x000000000409f45f 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
#34 0x00000000040675c5 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x40675c5)
#35 0x000000000406802d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x406802d)
#36 0x000000000406ff25 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x406ff25)
#37 0x0000000000c028fc clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc028fc)
#38 0x0000000000afb5f1 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xafb5f1)
#39 0x00007fe700e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#40 0x00007fe700e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#41 0x0000000000bfc81e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xbfc81e)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
https://godbolt.org/z/WvqEanxsf

the option `-m32` cause this ICE.

https://github.com/llvm/llvm-project/blob/9a95b2481e5ee0708aa8604e0c04b5bd1041de3a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp#L1034-L1043
Regs.size() = 1, while NumRegs = 2.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWltz27iS_jX0C4oqEqR4efCDLFmZzCabVORzdt5UINCUMCYBDQA68vz6LfAiEbScxDvK7FSdVBKRuDS-_rrRaIAgWvOdALj15nfefHVDGrOX6nYpH7h4BHVTSPZ8u4LfyTvRIAPaUKLBixZesPKCBXk6zkNcfPUfCWN_-OGMduVeEvR_u1cccUGrhgHyoiWvay6M4mK296L7vkX7_5PkzBW8tUMiD2cezvuW6V33gNB2W9dEPyYxekRetEJbi2LbF3k4C0MPL1GIbd_o1IvoGj3JihheQScZexgjL1qg9vHusX3F2aPtN-rqpauL2lFZH6wsKuuaCHYiZ9qsImKHXjKG_HooRH4dYeRvLpN4QVwHeq2kNB5eV9VT7R-U_B3o8Gp_eOHh9VIyeAfCw-sNVEANl2K1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