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

    <tr>
        <th>Summary</th>
        <td>
            Assertion `hiBit <= BitWidth && "hiBit out of range"' failed.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            bug,
            backend:X86,
            crash-on-valid,
            llvm:SelectionDAG
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            abhishek-kaushik22
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          abhishek-kaushik22
      </td>
    </tr>
</table>

<pre>
    The assertion is hit when trying to compile this piece of IR
```
define <8 x i1> @i8_mask_extract_8(i8 %mask) {
  %.splatinsert = insertelement <8 x i8> poison, i8 %mask, i64 0
  %.splat = shufflevector <8 x i8> %.splatinsert, <8 x i8> poison, <8 x i32> zeroinitializer
  %1 = and <8 x i8> %.splat, <i8 2, i8 4, i8 8, i8 16, i8 32, i8 64, i8 128, i8 poison>
  %cmp.45 = icmp ne <8 x i8> %1, zeroinitializer
  ret <8 x i1> %cmp.45
}
```
Godbolt: https://godbolt.org/z/ahvf5dMcq
```
llc: /root/llvm-project/llvm/include/llvm/ADT/APInt.h:1368: void llvm::APInt::setBits(unsigned int, unsigned int): Assertion `hiBit <= BitWidth && "hiBit 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: /opt/compiler-explorer/clang-assertions-trunk/bin/llc -o /app/output.s -x86-asm-syntax=intel -mcpu=x86-64-v4 -debug <source>
1.      Running pass 'Function Pass Manager' on module '<source>'.
2.      Running pass 'X86 DAG->DAG Instruction Selection' on function '@i8_mask_extract_8'
 #0 0x0000000003f7b3b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3f7b3b8)
 #1 0x0000000003f78264 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #2 0x00007cec2cc42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007cec2cc969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x00007cec2cc42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x00007cec2cc287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x00007cec2cc2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #7 0x00007cec2cc39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #8 0x0000000000d20778 (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0xd20778)
 #9 0x000000000239f592 combineSetCC(llvm::SDNode*, llvm::SelectionDAG&, llvm::TargetLowering::DAGCombinerInfo&, llvm::X86Subtarget const&) X86ISelLowering.cpp:0:0
#10 0x00000000023fb0b2 llvm::X86TargetLowering::PerformDAGCombine(llvm::SDNode*, llvm::TargetLowering::DAGCombinerInfo&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x23fb0b2)
#11 0x0000000003baddd1 (anonymous namespace)::DAGCombiner::combine(llvm::SDNode*) DAGCombiner.cpp:0:0
#12 0x0000000003baf6e0 (anonymous namespace)::DAGCombiner::Run(llvm::CombineLevel) DAGCombiner.cpp:0:0
#13 0x0000000003bb1863 llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::BatchAAResults*, llvm::CodeGenOptLevel) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3bb1863)
#14 0x0000000003d174bd llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3d174bd)
#15 0x0000000003d1aa0d llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3d1aa0d)
#16 0x0000000003d1be45 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3d1be45)
#17 0x0000000003d075ef llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3d075ef)
#18 0x0000000002ec2359 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#19 0x00000000034e719c llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x34e719c)
#20 0x00000000034e7561 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x34e7561)
#21 0x00000000034e7dcb llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x34e7dcb)
#22 0x00000000008eac9d compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#23 0x00000000007ba91e main (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x7ba91e)
#24 0x00007cec2cc29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#25 0x00007cec2cc29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#26 0x00000000008e1125 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x8e1125)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```

This is a regression from the previous release and the guilty commit is https://github.com/llvm/llvm-project/commit/17857d92416da5997262318a6f62fccad9c5a156.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMWFtv47gV_jXMC2FDou4PflDsOA2Q6QaTwXbfDIo6kthQpEpSmWR_fUFJjiwnszNpjaJBEsu8fOf7zoWkSI3htQTYoOgaEUKLhpsGnlZPtDcNfyIEEYKi3RXtbaP05n3_VaHK1823BjA1BrTlSmJucMMt_t6AxFa_clljqzBTbccFYNtwgzsODLCq8N1X5OUo9qZfLy-h4hIwCrYpfsHcR8ENRqHH00NLzdMBXqymzB5SRFK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