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

    <tr>
        <th>Summary</th>
        <td>
            [R600] Allocating Large Number of `i1`'s on Stack Crashes with Error "Register number out of range"
        </td>
    </tr>

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

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

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

<pre>
    ## Description

Allocating more than 504 `i1`'s on stack crashes with Error "Register number out of range" when interacting with other code.

## Minimal Reproduction

https://godbolt.org/z/6nzxW74Yh

### Code

```ll
define void @f() {
BB:
  br label %BB1

BB1:                                            ; preds = %BB1, %BB
  br i1 false, label %BB1, label %BB2

BB2:                                            ; preds = %BB1
  %A = alloca i1, i32 505                       ; any number greater than 504 fails
  %G = getelementptr i1, i1* %A, i32 1
  %B = ashr i1 false, true
  store i1 %B, i1* %G
  ret void
}
```

### Stack Trace

```
llc: /home/henry/aflplusplus-isel/llvm-project/llvm/include/llvm/MC/MCRegisterInfo.h:62: unsigned int llvm::MCRegisterClass::getRegister(unsigned int) const: Assertion `i < getNumRegs() && "Register 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: ./llvm-project/build-debug/bin/llc ./crash-reports/dagisel-r600/1.ll -mtriple=r600
1.      Running pass 'Function Pass Manager' on module './crash-reports/dagisel-r600/1.ll'.
2.      Running pass 'Finalize ISel and expand pseudo-instructions' on function '@f'
 #0 0x0000000003adad2a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/Support/Unix/Signals.inc:569:11
 #1 0x0000000003adaedb PrintStackTraceSignalHandler(void*) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/Support/Unix/Signals.inc:636:1
 #2 0x0000000003ad9526 llvm::sys::RunSignalHandlers() /home/henry/aflplusplus-isel/llvm-project/llvm/lib/Support/Signals.cpp:103:5
 #3 0x0000000003adb605 SignalHandler(int) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/Support/Unix/Signals.inc:407:1
 #4 0x00007f119b726980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
 #5 0x00007f119a616e87 raise /build/glibc-uZu3wS/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #6 0x00007f119a6187f1 abort /build/glibc-uZu3wS/glibc-2.27/stdlib/abort.c:81:0
 #7 0x00007f119a6083fa __assert_fail_base /build/glibc-uZu3wS/glibc-2.27/assert/assert.c:89:0
 #8 0x00007f119a608472 (/lib/x86_64-linux-gnu/libc.so.6+0x30472)
 #9 0x0000000000df1cd2 llvm::MCRegisterClass::getRegister(unsigned int) const /home/henry/aflplusplus-isel/llvm-project/llvm/include/llvm/MC/MCRegisterInfo.h:0:5
#10 0x0000000001432a5e llvm::TargetRegisterClass::getRegister(unsigned int) const /home/henry/aflplusplus-isel/llvm-project/llvm/include/llvm/CodeGen/TargetRegisterInfo.h:92:16
#11 0x000000000190945d llvm::R600InstrInfo::reserveIndirectRegisters(llvm::BitVector&, llvm::MachineFunction const&, llvm::R600RegisterInfo const&) const /home/henry/aflplusplus-isel/llvm-project/llvm/lib/Target/AMDGPU/R600InstrInfo.cpp:1077:48
#12 0x0000000001928292 llvm::R600RegisterInfo::getReservedRegs(llvm::MachineFunction const&) const /home/henry/aflplusplus-isel/llvm-project/llvm/lib/Target/AMDGPU/R600RegisterInfo.cpp:62:3
#13 0x00000000029574fe llvm::MachineRegisterInfo::freezeReservedRegs(llvm::MachineFunction const&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/CodeGen/MachineRegisterInfo.cpp:510:43
#14 0x0000000002bf43b5 llvm::TargetLoweringBase::finalizeLowering(llvm::MachineFunction&) const /home/henry/aflplusplus-isel/llvm-project/llvm/lib/CodeGen/TargetLoweringBase.cpp:2208:1
#15 0x00000000026f248c (anonymous namespace)::FinalizeISel::runOnMachineFunction(llvm::MachineFunction&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/CodeGen/FinalizeISel.cpp:74:10
#16 0x0000000002894c85 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:91:8
#17 0x0000000002f797d6 llvm::FPPassManager::runOnFunction(llvm::Function&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1430:23
#18 0x0000000002f7e602 llvm::FPPassManager::runOnModule(llvm::Module&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1476:16
#19 0x0000000002f7a0a9 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1545:23
#20 0x0000000002f79c1d llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:535:16
#21 0x0000000002f7e8e1 llvm::legacy::PassManager::run(llvm::Module&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1672:3
#22 0x0000000000d2cdbc compileModule(char**, llvm::LLVMContext&) /home/henry/aflplusplus-isel/llvm-project/llvm/tools/llc/llc.cpp:737:41
#23 0x0000000000d2b162 main /home/henry/aflplusplus-isel/llvm-project/llvm/tools/llc/llc.cpp:418:13
#24 0x00007f119a5f9c87 __libc_start_main /build/glibc-uZu3wS/glibc-2.27/csu/../csu/libc-start.c:344:0
#25 0x0000000000d2a96a _start (./llvm-project/build-debug/bin/llc+0xd2a96a)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzNWdlu4zgW_Rr7hbBBUfuDH-ykUh0g6QmS7h5MvxiURNmaoUiBlCrL1_clJVlL0lVGdSo1hq2FpHj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