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

    <tr>
        <th>Summary</th>
        <td>
            [RegBankSelect] Assertion `N < NumContainedTys && "Element number out of range!"'
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:ARM,
            llvm:codegen,
            crash-on-valid
      </td>
    </tr>

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

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

<pre>
    I tried the following code:

```llvm
target triple = "arm64"

@p = external global { {}, { ptr } }

define void @foo() {
bb:
  %i1 = load ptr, ptr @p, align 8
  store ptr %i1, ptr null, align 8
  ret void
}
```

When using llc in LLVM 18, the following error occurs:

```
llc: /root/llvm-project/llvm/include/llvm/IR/DerivedTypes.h:343: llvm::Type* llvm::StructType::getElementType(unsigned int) const: Assertion `N < NumContainedTys && "Element number out of range!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/llc -o /app/output.s -x86-asm-syntax=intel -O0 <source>
1.      Running pass 'Function Pass Manager' on module '<source>'.
2.      Running pass 'RegBankSelect' on function '@foo'
...
 #8 0x0000000000b27667 llvm::AArch64RegisterBankInfo::isLoadFromFPType(llvm::MachineInstr const&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0xb27667)
 #9 0x0000000000b2b155 llvm::AArch64RegisterBankInfo::getInstrMapping(llvm::MachineInstr const&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0xb2b155)
#10 0x0000000004203f47 llvm::RegBankSelect::assignInstr(llvm::MachineInstr&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x4203f47)
#11 0x00000000042044d3 llvm::RegBankSelect::assignRegisterBanks(llvm::MachineFunction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x42044d3)
...
Compiler returned: 139
```

https://llvm.godbolt.org/z/a4h1abfKc
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVt1u4zYTfRr6ZmCDomTJuvCFE0dAsMl--ZKivaaokcyGIgX-pNk-fUFaduzFbrFoF2gQBeGIPDznzHAo7pwcNOKWrG_Ier_gwR-M3e4l1___tGhN92V7D95K7MAfEHqjlPlD6gGE6ZDkO0L3hJ7-lvT4q9TbeAx5bgf0EWBSCCTfA2GM27EsCGNXaws6pff47tFqrmBQpuUKSHUTH1LtCbtNo8lbINU-PpcIHfZSI7wZ2QEpaG8MYRvC6rQ6zWjbM2EAwtYySzsqw7sIGvETdkGn-D9XctCwOS1w3lg8TohLT7N1UOobsy36RGVmeKZ6suiS-W8H1BBcdFUpAVLDw8Ovj5BtIu6162itsWCECNZ9z_3jUClB8h0Q1lhjPGFNTMpysuZ3FKchYY3UQoUOPwL3z4Q1e7TyDbtfvkzoVgeS7_Iij2hpTr4j-S6-Iuwy8uJtED7F03hAf6dwRH2MsU3QqdQ6kNrHvAijnY-oO-fQemk0kJJ-BpLfwucw3hrtudSRhQPCSsLKWDwzJugwtmjBBA-mB8v1gIRlsapYBT2XCrvV0Ymnh7vdyx240I7SA4c2DGBxMtaDN3DwfkpWsoawZpD-ENqVMOOHI18ZJ50L6AhrgOuoJfmX0iQsdwdouXj1lguct3_xXLxCF8bpnDC6IrR-smawfARuhxAVuTldZoq7CDNOUqFd4vukjEUbY4rrYclPbrmlt0G_Eta0UieeApYmQvBpikDBT8GvHCzfN-WSu3HpvmjP30m-l9qjguX_aDTbmWAFkvzuSC6L5J6D1rHeJu6i-VUTtEgZeoqBR675EClVYDSMpgvxcLPqCoxVswHsW4DPONxw_fqCKrmagPrTJhFqPsHVEWO1msGAsHwD9J2ef1pWlWV1UYi7nRWHsnjGQTqPNm5zr3tzfCndg-FdY83YPM11-bHykYuD1Hivnbdzeca6m0sVUj_5V_kh7Ia-HwkTVn8oqr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