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

    <tr>
        <th>Summary</th>
        <td>
            aarch64 "Bad machine code: Using an undefined physical register" with -enable-ext-tsp-block-placement
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    Repro courtesy of @aeubanks:

```
% cat tmp.ll 
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
target triple = "arm64-apple-macosx10.15.0"

declare ptr @g(ptr)

define void @f(i32 %event_type, ptr %p) {
entry:
 switch i32 %event_type, label %sw.bb200 [
    i32 0, label %common.ret
 i32 1, label %sw.bb199
    i32 57, label %sw.bb199
    i32 44, label %common.ret
  ]

sw.bb199:
  %a = call ptr @g(ptr null)
  ret void

sw.bb200:
  %b = call ptr @g(ptr poison) [ "clang.arc.attachedcall"(ptr @objc_retainAutoreleasedReturnValue) ]
 ret void

common.ret:
  ret void
}

declare ptr @objc_retainAutoreleasedReturnValue()
```

```
% bin/llc -o /dev/null tmp.ll -enable-ext-tsp-block-placement
...
*** Bad machine code: Using an undefined physical register ***
- function:    f
- basic block: %bb.7 sw.bb200 (0x137870c00)
- instruction: BUNDLE implicit-def $lr, implicit-def $w30, implicit-def $sp, implicit-def $wsp, implicit-def dead $x0, implicit-def $fp, implicit-def $w29, implicit $sp, implicit killed $x0, implicit $xzr, implicit $fp
- operand 8:   implicit killed $x0

*** Bad machine code: Using an undefined physical register ***
- function:    f
- basic block: %bb.7 sw.bb200 (0x137870c00)
- instruction: BL @g, <regmask $fp $lr $wzr $xzr $b8 $b9 $b10 $b11 $b12 $b13 $b14 $b15 $d8 $d9 $d10 $d11 $d12 $d13 $d14 $d15 $h8 $h9 $h10 $h11 $h12 $h13 $h14 $h15 $s8 $s9 $s10 $s11 $s12 and 55 more...>, implicit-def $lr, implicit $sp, implicit killed $x0, implicit-def dead $lr, implicit $sp, implicit-def $sp, implicit-def dead $x0
- operand 4:   implicit killed $x0
LLVM ERROR: Found 2 machine code errors.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: out/gn/bin/llc -o /dev/null tmp.ll -enable-ext-tsp-block-placement
1.      Running pass 'Function Pass Manager' on module 'tmp.ll'.
2.      Running pass 'Branch Probability Basic Block Placement' on function '@f'
zsh: abort out/gn/bin/llc -o /dev/null tmp.ll -enable-ext-tsp-block-placement
```

Doesn't seem to be a recent regression. Happens both on today's HEAD and at llvmorg-17-init-6829-g23643d1a from April
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUVk2P46gW_TVkc2UL448kiyySTkWzqHmvVK2Z7QjDjc0UBgtwV6d__RMmSX1luluj3jwpMso15wDnnnsN9151BnFD6h2p9ws-hd66jVHCLlorT5tHHJ0FYScX0J_AHoFUlOPUcvPkSbkldE_o5dnQ8y_9ZTUIHiAMY641pGDgrsMAkgeu-clOAUi5B8IYZgMptzZTTUXKbVNlqmArUm4LtspMyVLsc4wx9oYqODVqvNBwNzRVxsdRYzZwYf3XguZFndMrLD0lCs0dwhhcPFFH2GoMjrD120lHZRC-WCXjpCNhK1UyIKzGL2jCX-E0ImGfEgmrR8LWQJa7BEYT3OmqEPhnFUQPN_Gat6hj2D_nbcsohZiOhAOYMfTNPGGHwZrcYTjPilOKj1TFev2Wpl7-xKSq-v5iQOr9a5muLNfDRhifUyK41u9EBjNpfVUawGGYJf5AySh9S9n-I-Volbdm1r_eRR8IzU2XcydyHgIXPcoIiyZIAFJR2_4t_nIYuDLbKViHGrlH-YhhcuZPridMfOez3tznK21edvpu4nL_HeP9zCZWL7Z8V2H_VHatMoQdtBaQWSDsIPELYYeo-6UaMzS81Zjh15AFP2attuIpGzUXOKA5ZzrP8wvn-Qc7LmHg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