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

    <tr>
        <th>Summary</th>
        <td>
            [x86_64] extractelement v1i1 crashes on icelake-server
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    [Demo on Compiler Explorer](https://godbolt.org/z/P4hMGMWrh)

- The bug goes away when `-mcpu=icelake-server` is removed.
- Using a constant v1i1 doesn't crash.

Code:
```llvm
@G = global <1 x i1> <i1 true>
@G.1 = global i1 false

define void @foo(i32 %x) {
  %LGV = load <1 x i1>, ptr @G
  ; This works:
  ;%E = extractelement <1 x i1> <i1 true>, i32 %x
  ; This doesn't:
  %E = extractelement <1 x i1> %LGV, i32 %x
  store i1 %E, ptr @G.1
  ret void
}
```

Crash backtrace:
```
LLVM ERROR: Cannot select: 0x8191910: i8 = truncate 0x81912f0
  0x81912f0: i128 = bitcast 0x81917c0
    0x81917c0: v1i128 = sign_extend 0x8191440
 0x8191440: v1i1,ch = load<(dereferenceable load (s8) from @G)> 0x8115160, 0x8191ad0, undef:i64
        0x8191ad0: i64,ch = load<(load (s64) from got)> 0x8115160, 0x8191a60, undef:i64
          0x8191a60: i64 = X86ISD::WrapperRIP TargetGlobalAddress:i64<ptr @G> 0 [TF=5]
 0x8191590: i64 = TargetGlobalAddress<ptr @G> 0 [TF=5]
          0x81913d0: i64 = undef
        0x81913d0: i64 = undef
In function: foo
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-trunk/bin/llc -o /app/output.s -x86-asm-syntax=intel -mtriple=x86_64 -mcpu=icelake-server <source>
1.      Running pass 'Function Pass Manager' on module '<source>'.
2.      Running pass 'X86 DAG->DAG Instruction Selection' on function '@foo'
 #0 0x000000000305a128 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/llc+0x305a128)
 #1 0x0000000003057cec SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f785178e420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007f785125100b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #4 0x00007f7851230859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x000000000069de84 llvm::RISCVISAInfo::updateImplication() (.cold) RISCVISAInfo.cpp:0:0
 #6 0x0000000002e42ef4 llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*) (/opt/compiler-explorer/clang-trunk/bin/llc+0x2e42ef4)
 #7 0x0000000002e48585 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) (/opt/compiler-explorer/clang-trunk/bin/llc+0x2e48585)
 #8 0x000000000196ed1d (anonymous namespace)::X86DAGToDAGISel::Select(llvm::SDNode*) X86ISelDAGToDAG.cpp:0:0
 #9 0x0000000002e40557 llvm::SelectionDAGISel::DoInstructionSelection() (/opt/compiler-explorer/clang-trunk/bin/llc+0x2e40557)
#10 0x0000000002e4ce15 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/compiler-explorer/clang-trunk/bin/llc+0x2e4ce15)
#11 0x0000000002e4f869 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x2e4f869)
#12 0x0000000002e51f36 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (.part.0) SelectionDAGISel.cpp:0:0
#13 0x0000000001978741 (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) X86ISelDAGToDAG.cpp:0:0
#14 0x0000000002439700 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#15 0x000000000291aeb2 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x291aeb2)
#16 0x000000000291b031 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x291b031)
#17 0x000000000291cba0 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x291cba0)
#18 0x00000000007673f0 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#19 0x00000000006a8b82 main (/opt/compiler-explorer/clang-trunk/bin/llc+0x6a8b82)
#20 0x00007f7851232083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#21 0x000000000075f33e _start (/opt/compiler-explorer/clang-trunk/bin/llc+0x75f33e)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0mFtv2zzSgH8Nc0PYoKjzRS4cnz4DzfcGcbZv98qgpLHNjUQKJJU4--sXpGRbct0mm2aLtol4mHk4M5whybTmOwFwi8I7FM5uWGP2Ut1K9qzym0wWb7ZjBpXEUuCprGpegsLzQ11KBQqFM0STvTG1Rv4E0QWii50sMlmasVQ7RBf_RnTxEOzvl_d_qz2iKSIzRCbt_yP8tAecNTu8k6Axe2Vv-HUPAqOIjKq8bpA_4zmU7BlGGtQLKBQRzDVWUMkXKMZHMf_QXOwww7kU2jBh8IvHPVxI0ALR2OBcMb0f91VPZQGWuG2KSPu3LF-qrikgS4z8Gd6VMmMlRv7UwwfMPeTP7Qf3sFENIH9-Hj_2-jO4h7es1NDXWsCWC8AvkhcYBWQrJaIJ9ylGNDwgmmIU37UjsW36tvzuJJaSFQMCRKe4NsrKWJ7G-3f4ac81fpXqWZ_W5joQDedOEhyMYrmBEioQ5nerolN8ArvUcDJsX8uHVLg1XZOtjVRgbWbl9Jc39o5DFBhnuc6g8ezCeQP3WofjjOXPFuaKp9vPb9--3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