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

    <tr>
        <th>Summary</th>
        <td>
            aarch64 global isel backend assertion violation when translating udiv of i1
        </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>
    this triggers an assert:

```llvm
define i1 @f(i1 %0) {
  %2 = udiv i1 %0, true
  ret i1 %2
}
```

```terminal
regehr@john-home:~/arm-tests/assertion-fail$ /home/regehr/llvm-project/for-alive/bin/llc -o /dev/null --march=aarch64 -global-isel -global-isel-abort=0 reduced.ll
llc: /home/regehr/llvm-project/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp:4894: llvm::CombinerHelper::buildUDivUsingMul(llvm::MachineInstr&)::<lambda(const llvm::Constant*)>: Assertion `magics.ShiftAmount < Divisor.getBitWidth() && "We shouldn't generate an undefined shift!"' failed.
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 0x00007f1a21dbad35 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x00007f1a21db7d24 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f1a21741520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007f1a21795a7c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #4 0x00007f1a21795a7c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #5 0x00007f1a21795a7c pthread_kill ./nptl/pthread_kill.c:89:10
 #6 0x00007f1a21741476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #7 0x00007f1a217277f3 abort ./stdlib/abort.c:81:7
 #8 0x00007f1a2172771b _nl_load_domain ./intl/loadmsgcat.c:1177:9
 #9 0x00007f1a21738e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#10 0x00007f1a213e8d1d std::_Function_handler<bool (llvm::Constant const*), llvm::CombinerHelper::buildUDivUsingMul(llvm::MachineInstr&)::'lambda'(llvm::Constant const*)>::_M_invoke(std::_Any_data const&, llvm::Constant const*&&) CombinerHelper.cpp:0:0
#11 0x00007f1a214d1828 llvm::matchUnaryPredicate(llvm::MachineRegisterInfo const&, llvm::Register, std::function<bool (llvm::Constant const*)>, bool) (/home/regehr/llvm-project/for-alive/bin/../lib/../lib/libLLVMGlobalISel.so.16git+0x158828)
#12 0x00007f1a214079e4 llvm::CombinerHelper::buildUDivUsingMul(llvm::MachineInstr&) (/home/regehr/llvm-project/for-alive/bin/../lib/../lib/libLLVMGlobalISel.so.16git+0x8e9e4)
#13 0x00007f1a214088c9 llvm::CombinerHelper::applyUDivByConst(llvm::MachineInstr&) (/home/regehr/llvm-project/for-alive/bin/../lib/../lib/libLLVMGlobalISel.so.16git+0x8f8c9)
#14 0x00007f1a28fcbacd (anonymous namespace)::AArch64GenPreLegalizerCombinerHelper::tryCombineAll(llvm::GISelChangeObserver&, llvm::MachineInstr&, llvm::MachineIRBuilder&) const AArch64PreLegalizerCombiner.cpp:0:0
#15 0x00007f1a28fce9e9 (anonymous namespace)::AArch64PreLegalizerCombinerInfo::combine(llvm::GISelChangeObserver&, llvm::MachineInstr&, llvm::MachineIRBuilder&) const AArch64PreLegalizerCombiner.cpp:0:0
#16 0x00007f1a213e05a0 llvm::Combiner::combineMachineInstrs(llvm::MachineFunction&, llvm::GISelCSEInfo*) (/home/regehr/llvm-project/for-alive/bin/../lib/../lib/libLLVMGlobalISel.so.16git+0x675a0)
#17 0x00007f1a28fc61b2 (anonymous namespace)::AArch64PreLegalizerCombiner::runOnMachineFunction(llvm::MachineFunction&) AArch64PreLegalizerCombiner.cpp:0:0
#18 0x00007f1a23930ba6 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/regehr/llvm-project/for-alive/bin/../lib/libLLVMCodeGen.so.16git+0x394ba6)
#19 0x00007f1a22138213 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/regehr/llvm-project/for-alive/bin/../lib/libLLVMCore.so.16git+0x293213)
#20 0x00007f1a22138449 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/regehr/llvm-project/for-alive/bin/../lib/libLLVMCore.so.16git+0x293449)
#21 0x00007f1a22138d02 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/regehr/llvm-project/for-alive/bin/../lib/libLLVMCore.so.16git+0x293d02)
#22 0x00005634167d871a compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#23 0x00005634167cd540 main (/home/regehr/llvm-project/for-alive/bin/llc+0x11540)
#24 0x00007f1a21728d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#25 0x00007f1a21728e40 call_init ./csu/../csu/libc-start.c:128:20
#26 0x00007f1a21728e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#27 0x00005634167cda35 _start (/home/regehr/llvm-project/for-alive/bin/llc+0x11a35)
Aborted (core dumped)
```

cc @ornata @aemerson @nbushehri @Hatsunespica
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzNWNuSm7gW_Rr7RWUXiPuDH9y3JFXpmq70ZObRJZAMmgjhEsKnPV8_WxLY4OYkPck5mely2yDE0l77qq28oaeNrniLtOJlyVSLiESkbZnSi2C78O4W3vAde-4jxLF2Q5TtuWSI-2gRevsFTs0VjrwFztAiuXGTkBnCaBHcoY7yIzrPuYU1OzZMUkz3j3C_XnJ3tfCsNJqpmksi3LBiJasUSPNHU8lV1dTMsEjuF_iBqHqlWatbc20J8kau9oSLBQ5h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