The IR in https://gist.github.com/nikic/1fa40bc972e815f9606518c5b2218699 run through "llc -O3" causes "LLVM ERROR: invalid symbol redefinition". The error does not occur at -O2.
The relevant difference between O2 and O3 seems to be the tail dup placement threshold in machine block placement. Running with -O2 -tail-dup-placement-threshold=3 also reproduces the problem.
The tail of the assembly before the error looks like this: @ %bb.38: .p2align 2 .LJTI0_1: .long .LBB0_47+1 .long .LBB0_43+1 .long .LBB0_43+1 .long .LBB0_44+1 .LBB0_39: @ =>This Inner Loop Header: Depth=1 cmp r0, #0 bne .LBB0_47 @ %bb.40: @ in Loop: Header=BB0_39 Depth=1 adr r3, .LJTI0_1 ldr r3, [r3, r1] mov pc, r3 .p2align 2 @ %bb.41: .p2align 2 And the "invalid symbol redefinition" occurs on the ".LJTI0_1" label. Combined with the indication in the previous comment what likely happens here is that a block using a jumptable is tail-duplicated (including the jumptable), but the label for the jumptable is reused. The label is generated in https://github.com/llvm/llvm-project/blob/e97aa961d3255d95c32bb884858ccdd3a00dbadc/llvm/lib/Target/ARM/ARMAsmPrinter.cpp#L254 based on the function number and the jumptable index.
Candidate patch: https://reviews.llvm.org/D65606
Fixed by https://reviews.llvm.org/rL367753.
Merged to release_90 in r367808.