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

    <tr>
        <th>Summary</th>
        <td>
            [AArch64] Assertion `VT.isVector() == N1.getValueType().isVector() && "TRUNCATE result type type should be vector iff the operand " "type is vector!"' failed.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:AArch64,
            llvm:crash,
            llvm:SelectionDAG
      </td>
    </tr>

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

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

<pre>
    I tried the following code that would trigger the assertion:

```
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64-unknown-linux-gnu"

define void @foo(ptr %0, <16 x i1> %1) {
bb1.i:
  %.bc = bitcast <16 x i1> %1 to <2 x i8>
  %.extract100 = extractelement <2 x i8> %.bc, i64 0
  %_47 = icmp eq i8 %.extract100, 0
  br i1 %_47, label %bb20, label %bb23

bb20: ; preds = %bb1.i
  store <16 x i8> zeroinitializer, ptr %0, align 1
  br label %bb23

bb23: ; preds = %bb20, %bb1.i
  ret void
}
```

https://llvm.godbolt.org/z/narrKadhK

From: https://github.com/rust-lang/rust/issues/120813

<details><summary>Details</summary>
<p>

```
llc: /home/dianqk/llvm/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:5786: SDValue llvm::SelectionDAG::getNode(unsigned int, const SDLoc &, EVT, SDValue, const SDNodeFlags): Assertion `VT.isVector() == N1.getValueType().isVector() && "TRUNCATE result type type should be vector iff the operand " "type is vector!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: ../llvm-project/build/bin/llc foo.ll
1.      Running pass 'Function Pass Manager' on module 'foo.ll'.
2.      Running pass 'AArch64 Instruction Selection' on function '@foo'
 #0 0x0000556ff83f71ea ___interceptor_backtrace.part.0 (../llvm-project/build/bin/llc+0xe91ea)
 #1 0x00007fe4460288c1 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/dianqk/llvm/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:13
 #2 0x00007fe446029a2e llvm::sys::RunSignalHandlers() /home/dianqk/llvm/llvm-project/llvm/lib/Support/Signals.cpp:0:5
 #3 0x00007fe446029a2e SignalHandler(int) /home/dianqk/llvm/llvm-project/llvm/lib/Support/Unix/Signals.inc:403:3
 #4 0x00007fe44ac54eb0 __restore_rt (/nix/store/7jiqcrg061xi5clniy7z5pvkc4jiaqav-glibc-2.38-27/lib/libc.so.6+0x3deb0)
 #5 0x00007fe44aca402c __pthread_kill_implementation (/nix/store/7jiqcrg061xi5clniy7z5pvkc4jiaqav-glibc-2.38-27/lib/libc.so.6+0x8d02c)
 #6 0x00007fe44ac54e06 gsignal (/nix/store/7jiqcrg061xi5clniy7z5pvkc4jiaqav-glibc-2.38-27/lib/libc.so.6+0x3de06)
 #7 0x00007fe44ac3d8f5 abort (/nix/store/7jiqcrg061xi5clniy7z5pvkc4jiaqav-glibc-2.38-27/lib/libc.so.6+0x268f5)
 #8 0x00007fe44ac3d819 _nl_load_domain.cold (/nix/store/7jiqcrg061xi5clniy7z5pvkc4jiaqav-glibc-2.38-27/lib/libc.so.6+0x26819)
 #9 0x00007fe44ac4d686 (/nix/store/7jiqcrg061xi5clniy7z5pvkc4jiaqav-glibc-2.38-27/lib/libc.so.6+0x36686)
#10 0x00007fe44e60ec7f llvm::SelectionDAG::getNode(unsigned int, llvm::SDLoc const&, llvm::EVT, llvm::SDValue, llvm::SDNodeFlags) /home/dianqk/llvm/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:5784:5
#11 0x00007fe44e5b719d llvm::SelectionDAG::getNode(unsigned int, llvm::SDLoc const&, llvm::EVT, llvm::SDValue) /home/dianqk/llvm/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:5605:10
#12 0x00007fe44e5b719d llvm::SelectionDAG::getZExtOrTrunc(llvm::SDValue, llvm::SDLoc const&, llvm::EVT) /home/dianqk/llvm/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1464:5
#13 0x00007fe45441467f replaceBoolVectorBitcast(llvm::SDNode*, llvm::SmallVectorImpl<llvm::SDValue>&, llvm::SelectionDAG&) /home/dianqk/llvm/llvm-project/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:0:27
#14 0x00007fe45441467f llvm::AArch64TargetLowering::ReplaceBITCASTResults(llvm::SDNode*, llvm::SmallVectorImpl<llvm::SDValue>&, llvm::SelectionDAG&) const /home/dianqk/llvm/llvm-project/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:24619:12
#15 0x00007fe454418b7a llvm::AArch64TargetLowering::ReplaceNodeResults(llvm::SDNode*, llvm::SmallVectorImpl<llvm::SDValue>&, llvm::SelectionDAG&) const /home/dianqk/llvm/llvm-project/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:0:5
#16 0x00007fe44e2cf55f llvm::DAGTypeLegalizer::CustomLowerNode(llvm::SDNode*, llvm::EVT, bool) /home/dianqk/llvm/llvm-project/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp:0:0
#17 0x00007fe44e201ad4 llvm::DAGTypeLegalizer::PromoteIntegerResult(llvm::SDNode*, unsigned int) /home/dianqk/llvm/llvm-project/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp:46:7
#18 0x00007fe44e2c33b9 llvm::DAGTypeLegalizer::run() /home/dianqk/llvm/llvm-project/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp:0:9
#19 0x00007fe44e2d3982 llvm::SelectionDAG::LegalizeTypes() /home/dianqk/llvm/llvm-project/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp:0:34
#20 0x00007fe44e6fffcf llvm::SelectionDAGISel::CodeGenAndEmitDAG() /home/dianqk/llvm/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:0:23
#21 0x00007fe44e6fe50e llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true>, false, true>, llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true>, false, true>, bool&) /home/dianqk/llvm/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:0:3
#22 0x00007fe44e6fa8ee llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) /home/dianqk/llvm/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1511:8
#23 0x00007fe44e6ef0bb llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) /home/dianqk/llvm/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:517:7
#24 0x00007fe44cb174a4 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /home/dianqk/llvm/llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:0:13
#25 0x00007fe446f13795 llvm::FPPassManager::runOnFunction(llvm::Function&) /home/dianqk/llvm/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1455:11
#26 0x00007fe446f2bd24 llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Function, true, false, void, false>, false, false>::operator++() /home/dianqk/llvm/llvm-project/llvm/include/llvm/ADT/ilist_iterator.h:157:48
#27 0x00007fe446f2bd24 llvm::FPPassManager::runOnModule(llvm::Module&) /home/dianqk/llvm/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1490:20
#28 0x00007fe446f14680 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/dianqk/llvm/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:0:27
#29 0x00007fe446f14680 llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/dianqk/llvm/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:542:44
#30 0x0000556ff84e54b5 compileModule(char**, llvm::LLVMContext&) /home/dianqk/llvm/llvm-project/llvm/tools/llc/llc.cpp:0:8
#31 0x0000556ff84de6d0 main /home/dianqk/llvm/llvm-project/llvm/tools/llc/llc.cpp:408:13
#32 0x00007fe44ac3f0ce __libc_start_call_main (/nix/store/7jiqcrg061xi5clniy7z5pvkc4jiaqav-glibc-2.38-27/lib/libc.so.6+0x280ce)
#33 0x00007fe44ac3f189 __libc_start_main@GLIBC_2.2.5 (/nix/store/7jiqcrg061xi5clniy7z5pvkc4jiaqav-glibc-2.38-27/lib/libc.so.6+0x28189)
#34 0x0000556ff83a50c5 _start (../llvm-project/build/bin/llc+0x970c5)
zsh: IOT instruction (core dumped)  ../llvm-project/build/bin/llc foo.ll
```

</p>
</details> 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWs9y27iTfhr4ghILBP8ffJAlK-saZ8Ybe3LYCwsEQQpjEGBAMLHz9FsAKZGU7WTGM_bO_lIxJTaB7q8_NBpNQKTreC0ZOwfRBYi2Z6Q3e6XPt5zI__7lrFDl4_kVNJqzEpo9g5USQn3jsoZUlQyaPTHwm-pFadvUNdOuFek6pg1XEgRrgLYAHa4xGv-7W0N0zQwsiSGCPKreQBBsIcCYrRoQrNmKpyBY278Ar7gfg2DtLvYuDkGwjsMV97Ft4ON0JQM8yG6tDOOFEaN5K9jBACGa7uNw1ct7qb7JleCyf1jVsj92G64lq7hk8KviJQQhqpQCOG2NhgBHCOANBMHGj-ED5D4ILq3UBziDILkY-heF7_EjCdA28ArqUBTcUNKZZzRAo6wUW2EKgst5Z_ZgNKHGR8gpGW-ZYA2TZtFrtGVB8jiEaKYlDxPXm9OmhewL5OmJbtvp2KHQkPtjN_tAkIIJe18UGJ0Kgjl7rkGwhiC4gK1mZTfSHw20jPo7ozSbaHDYvzOtuOSGE8G_M22tzFkngtcS-jOEP8IQvIBhQH8KRzPjxntUkmyfDd3hujem7ezw4h3AO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