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

    <tr>
        <th>Summary</th>
        <td>
            aarch64 global isel backend crashes on valid input
        </td>
    </tr>

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

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

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

<pre>
    I'm seeing a crash when trying to compile this code using `--march=aarch64 -global-isel -global-isel-abort=0`:

```llvm
define i32 @f(i32 %0) {
  %2 = shl i32 %0, 8
  %3 = or i32 %0, %2
  %4 = shl i32 %3, 8
  ret i32 %4
}
```

```shell
regehr@john-home:~/arm-tests/core-dump$ ~/llvm-project/for-alive/bin/opt -verify reduced.ll -o /dev/null
regehr@john-home:~/arm-tests/core-dump$ /home/regehr/llvm-project/for-alive/bin/llc -o /dev/null --march=aarch64 -global-isel -global-isel-abort=0 reduced.ll
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /home/regehr/llvm-project/for-alive/bin/llc -o /dev/null --march=aarch64 -global-isel -global-isel-abort=0 reduced.ll
1.      Running pass 'Function Pass Manager' on module 'reduced.ll'.
2.      Running pass 'AArch64PreLegalizerCombiner' on function '@f'
 #0 0x00007f5aeae50d35 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x00007f5aeae4dd24 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f5aea7d7520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007f5aea56137f llvm::getDefSrcRegIgnoringCopies(llvm::Register, llvm::MachineRegisterInfo const&) (/home/regehr/llvm-project/for-alive/bin/../lib/../lib/libLLVMGlobalISel.so.16git+0x15237f)
 #4 0x00007f5aea5619d3 llvm::getOpcodeDef(unsigned int, llvm::Register, llvm::MachineRegisterInfo const&) (/home/regehr/llvm-project/for-alive/bin/../lib/../lib/libLLVMGlobalISel.so.16git+0x1529d3)
 #5 0x00007f5aea490260 llvm::CombinerHelper::matchAnyExplicitUseIsUndef(llvm::MachineInstr&) (/home/regehr/llvm-project/for-alive/bin/../lib/../lib/libLLVMGlobalISel.so.16git+0x81260)
 #6 0x00007f5af205e848 (anonymous namespace)::AArch64GenPreLegalizerCombinerHelper::tryCombineAll(llvm::GISelChangeObserver&, llvm::MachineInstr&, llvm::MachineIRBuilder&) const AArch64PreLegalizerCombiner.cpp:0:0
 #7 0x00007f5af20649e9 (anonymous namespace)::AArch64PreLegalizerCombinerInfo::combine(llvm::GISelChangeObserver&, llvm::MachineInstr&, llvm::MachineIRBuilder&) const AArch64PreLegalizerCombiner.cpp:0:0
 #8 0x00007f5aea4765a0 llvm::Combiner::combineMachineInstrs(llvm::MachineFunction&, llvm::GISelCSEInfo*) (/home/regehr/llvm-project/for-alive/bin/../lib/../lib/libLLVMGlobalISel.so.16git+0x675a0)
 #9 0x00007f5af205c1b2 (anonymous namespace)::AArch64PreLegalizerCombiner::runOnMachineFunction(llvm::MachineFunction&) AArch64PreLegalizerCombiner.cpp:0:0
#10 0x00007f5aec9c6ba6 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/regehr/llvm-project/for-alive/bin/../lib/libLLVMCodeGen.so.16git+0x394ba6)
#11 0x00007f5aeb1ce213 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/regehr/llvm-project/for-alive/bin/../lib/libLLVMCore.so.16git+0x293213)
#12 0x00007f5aeb1ce449 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/regehr/llvm-project/for-alive/bin/../lib/libLLVMCore.so.16git+0x293449)
#13 0x00007f5aeb1ced02 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/regehr/llvm-project/for-alive/bin/../lib/libLLVMCore.so.16git+0x293d02)
#14 0x00005578cc52471a compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#15 0x00005578cc519540 main (/home/regehr/llvm-project/for-alive/bin/llc+0x11540)
#16 0x00007f5aea7bed90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#17 0x00007f5aea7bee40 call_init ./csu/../csu/libc-start.c:128:20
#18 0x00007f5aea7bee40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#19 0x00005578cc519a35 _start (/home/regehr/llvm-project/for-alive/bin/llc+0x11a35)
Segmentation fault (core dumped)
regehr@john-home:~/arm-tests/core-dump$ 
```

cc @ornata @aemerson @nbushehri @hatsunespica
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzVWNtu2zgQ_Rr5hbAhUfcHPzi3boAEDZrtvgYUNZbUpSiBpLLJfv0OKTuWHO-2TYC2GziyNKRmzpkLyXHRlc_ra4-mLdEAjawII1wxXZO_apDEqGcrMx3hXds3AoipG40PJZBB2yEv8ZfLlilee-EFs99JRJaV6Aomlo0GMXtYsqJTBmf6-J4Xbjz_wvP318QfP0I8tqOohG0jgTQhJV7kbz2auVsa-x7NiZeejdOIFaE8vCC6FuQw55xkkxmhm9Gp2QT75mROdKwlnGlRYPYD0Q51enEE_yQnXYMQo0xBBbVCPl-6Wi7rrgXriPTSo1dMtUsD2mi8552CZTm0vUcRlBu2jln2qvsC3ODjtlNLJppHwPuikXjtekOWj6Ca7TNCLQcO5UpgBDoEfFXCI17l8C4c9MpNpFe7t78BlBD8FQLyppyZcBop3N1cbu4viR6KtjGYucVQ4Zwep9uUrY3pteVEr_BTNaYeihXm8Q70a-yN1gNYzoTJkjSSi6G0GQ-7kigY_9MoxmE1mr83KCDON_tU9nEov1NdpVhLmKqGFqSxIH411wUW6KdBSlvEPdMaraRXg-Sm6SS5s4JbJlkFCDQlKGq7csD6x6eJKpruXEFPqdtsHL47BTdQIbO_QZ13LVJ7UbrdG8TnscLTXal5NPSJ_-TjX7qNGTCI_TKMyZ1qpHGO_91G4r6pJBO_YbyEVZo9dk3p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