diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp @@ -4527,7 +4527,7 @@ SDValue DAGTypeLegalizer::WidenVecRes_SELECT(SDNode *N) { EVT WidenVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0)); - unsigned WidenNumElts = WidenVT.getVectorNumElements(); + ElementCount WidenEC = WidenVT.getVectorElementCount(); SDValue Cond1 = N->getOperand(0); EVT CondVT = Cond1.getValueType(); @@ -4541,8 +4541,7 @@ } EVT CondEltVT = CondVT.getVectorElementType(); - EVT CondWidenVT = EVT::getVectorVT(*DAG.getContext(), - CondEltVT, WidenNumElts); + EVT CondWidenVT = EVT::getVectorVT(*DAG.getContext(), CondEltVT, WidenEC); if (getTypeAction(CondVT) == TargetLowering::TypeWidenVector) Cond1 = GetWidenedVector(Cond1); diff --git a/llvm/test/CodeGen/AArch64/sve-pred-log.ll b/llvm/test/CodeGen/AArch64/sve-pred-log.ll --- a/llvm/test/CodeGen/AArch64/sve-pred-log.ll +++ b/llvm/test/CodeGen/AArch64/sve-pred-log.ll @@ -32,6 +32,14 @@ ret %res; } +define @vselect_1( %Pg, %Pn, %Pd) { +; CHECK-LABEL: vselect_1: +; CHECK: sel p0.b, p0, p1.b, p2.b +; CHECK-NEXT: ret + %res = select %Pg, %Pn, %Pd + ret %res; +} + define @and_16( %Pg, %Pn, %Pd) { ; CHECK-LABEL: and_16: ; CHECK: and p0.b, p0/z, p1.b, p2.b diff --git a/llvm/test/CodeGen/AArch64/sve-select.ll b/llvm/test/CodeGen/AArch64/sve-select.ll --- a/llvm/test/CodeGen/AArch64/sve-select.ll +++ b/llvm/test/CodeGen/AArch64/sve-select.ll @@ -1,6 +1,18 @@ ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py ; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve -verify-machineinstrs < %s | FileCheck %s +define @select_nxv1i8(i1 %cond, %a, %b) { +; CHECK-LABEL: select_nxv1i8: +; CHECK: // %bb.0: +; CHECK-NEXT: // kill: def $w0 killed $w0 def $x0 +; CHECK-NEXT: sbfx x8, x0, #0, #1 +; CHECK-NEXT: whilelo p0.b, xzr, x8 +; CHECK-NEXT: sel z0.b, p0, z0.b, z1.b +; CHECK-NEXT: ret + %res = select i1 %cond, %a, %b + ret %res +} + define @select_nxv16i8(i1 %cond, %a, %b) { ; CHECK-LABEL: select_nxv16i8: ; CHECK: // %bb.0: @@ -13,6 +25,18 @@ ret %res } +define @select_nxv1i16(i1 %cond, %a, %b) { +; CHECK-LABEL: select_nxv1i16: +; CHECK: // %bb.0: +; CHECK-NEXT: // kill: def $w0 killed $w0 def $x0 +; CHECK-NEXT: sbfx x8, x0, #0, #1 +; CHECK-NEXT: whilelo p0.h, xzr, x8 +; CHECK-NEXT: sel z0.h, p0, z0.h, z1.h +; CHECK-NEXT: ret + %res = select i1 %cond, %a, %b + ret %res +} + define @select_nxv8i16(i1 %cond, %a, %b) { ; CHECK-LABEL: select_nxv8i16: ; CHECK: // %bb.0: @@ -25,6 +49,18 @@ ret %res } +define @select_nxv1i32(i1 %cond, %a, %b) { +; CHECK-LABEL: select_nxv1i32: +; CHECK: // %bb.0: +; CHECK-NEXT: // kill: def $w0 killed $w0 def $x0 +; CHECK-NEXT: sbfx x8, x0, #0, #1 +; CHECK-NEXT: whilelo p0.s, xzr, x8 +; CHECK-NEXT: sel z0.s, p0, z0.s, z1.s +; CHECK-NEXT: ret + %res = select i1 %cond, %a, %b + ret %res +} + define @select_nxv4i32(i1 %cond, %a, %b) { ; CHECK-LABEL: select_nxv4i32: ; CHECK: // %bb.0: @@ -37,6 +73,18 @@ ret %res } +define @select_nxv1i64(i1 %cond, %a, %b) { +; CHECK-LABEL: select_nxv1i64: +; CHECK: // %bb.0: +; CHECK-NEXT: // kill: def $w0 killed $w0 def $x0 +; CHECK-NEXT: sbfx x8, x0, #0, #1 +; CHECK-NEXT: whilelo p0.d, xzr, x8 +; CHECK-NEXT: sel z0.d, p0, z0.d, z1.d +; CHECK-NEXT: ret + %res = select i1 %cond, %a, %b + ret %res +} + define @select_nxv2i64(i1 %cond, %a, %b) { ; CHECK-LABEL: select_nxv2i64: ; CHECK: // %bb.0: @@ -133,6 +181,18 @@ ret %res } +define @select_nxv1i1(i1 %cond, %a, %b) { +; CHECK-LABEL: select_nxv1i1: +; CHECK: // %bb.0: +; CHECK-NEXT: // kill: def $w0 killed $w0 def $x0 +; CHECK-NEXT: sbfx x8, x0, #0, #1 +; CHECK-NEXT: whilelo p2.d, xzr, x8 +; CHECK-NEXT: sel p0.b, p2, p0.b, p1.b +; CHECK-NEXT: ret + %res = select i1 %cond, %a, %b + ret %res +} + ; Integer vector select define @sel_nxv16i8( %p, %dst, %a) { @@ -162,6 +222,15 @@ ret %sel } +define @sel_nxv1i64( %p, %dst, %a) { +; CHECK-LABEL: sel_nxv1i64: +; CHECK: // %bb.0: +; CHECK-NEXT: mov z0.d, p0/m, z1.d +; CHECK-NEXT: ret + %sel = select %p, %a, %dst + ret %sel +} + define @sel_nxv2i64( %p, %dst, %a) { ; CHECK-LABEL: sel_nxv2i64: ; CHECK: // %bb.0: @@ -295,6 +364,20 @@ ret %sel } +define @icmp_select_nxv1i64( %a, %b, i64 %x0) { +; CHECK-LABEL: icmp_select_nxv1i64: +; CHECK: // %bb.0: +; CHECK-NEXT: cmp x0, #0 +; CHECK-NEXT: cset w8, eq +; CHECK-NEXT: sbfx x8, x8, #0, #1 +; CHECK-NEXT: whilelo p0.d, xzr, x8 +; CHECK-NEXT: sel z0.d, p0, z0.d, z1.d +; CHECK-NEXT: ret + %mask = icmp eq i64 %x0, 0 + %sel = select i1 %mask, %a, %b + ret %sel +} + define @icmp_select_nxv2i64( %a, %b, i64 %x0) { ; CHECK-LABEL: icmp_select_nxv2i64: ; CHECK: // %bb.0: @@ -309,6 +392,20 @@ ret %sel } +define @icmp_select_nxv1i32( %a, %b, i64 %x0) { +; CHECK-LABEL: icmp_select_nxv1i32: +; CHECK: // %bb.0: +; CHECK-NEXT: cmp x0, #0 +; CHECK-NEXT: cset w8, eq +; CHECK-NEXT: sbfx x8, x8, #0, #1 +; CHECK-NEXT: whilelo p0.s, xzr, x8 +; CHECK-NEXT: sel z0.s, p0, z0.s, z1.s +; CHECK-NEXT: ret + %mask = icmp eq i64 %x0, 0 + %sel = select i1 %mask, %a, %b + ret %sel +} + define @icmp_select_nxv4i32( %a, %b, i64 %x0) { ; CHECK-LABEL: icmp_select_nxv4i32: ; CHECK: // %bb.0: @@ -323,6 +420,20 @@ ret %sel } +define @icmp_select_nxv1i16( %a, %b, i64 %x0) { +; CHECK-LABEL: icmp_select_nxv1i16: +; CHECK: // %bb.0: +; CHECK-NEXT: cmp x0, #0 +; CHECK-NEXT: cset w8, eq +; CHECK-NEXT: sbfx x8, x8, #0, #1 +; CHECK-NEXT: whilelo p0.h, xzr, x8 +; CHECK-NEXT: sel z0.h, p0, z0.h, z1.h +; CHECK-NEXT: ret + %mask = icmp eq i64 %x0, 0 + %sel = select i1 %mask, %a, %b + ret %sel +} + define @icmp_select_nxv8i16( %a, %b, i64 %x0) { ; CHECK-LABEL: icmp_select_nxv8i16: ; CHECK: // %bb.0: @@ -337,6 +448,20 @@ ret %sel } +define @icmp_select_nxv1i8( %a, %b, i64 %x0) { +; CHECK-LABEL: icmp_select_nxv1i8: +; CHECK: // %bb.0: +; CHECK-NEXT: cmp x0, #0 +; CHECK-NEXT: cset w8, eq +; CHECK-NEXT: sbfx x8, x8, #0, #1 +; CHECK-NEXT: whilelo p0.b, xzr, x8 +; CHECK-NEXT: sel z0.b, p0, z0.b, z1.b +; CHECK-NEXT: ret + %mask = icmp eq i64 %x0, 0 + %sel = select i1 %mask, %a, %b + ret %sel +} + define @icmp_select_nxv16i8( %a, %b, i64 %x0) { ; CHECK-LABEL: icmp_select_nxv16i8: ; CHECK: // %bb.0: @@ -351,6 +476,20 @@ ret %sel } +define @icmp_select_nxv1i1( %a, %b, i64 %x0) { +; CHECK-LABEL: icmp_select_nxv1i1: +; CHECK: // %bb.0: +; CHECK-NEXT: cmp x0, #0 +; CHECK-NEXT: cset w8, eq +; CHECK-NEXT: sbfx x8, x8, #0, #1 +; CHECK-NEXT: whilelo p2.d, xzr, x8 +; CHECK-NEXT: sel p0.b, p2, p0.b, p1.b +; CHECK-NEXT: ret + %mask = icmp eq i64 %x0, 0 + %sel = select i1 %mask, %a, %b + ret %sel +} + define @icmp_select_nxv2i1( %a, %b, i64 %x0) { ; CHECK-LABEL: icmp_select_nxv2i1: ; CHECK: // %bb.0: diff --git a/llvm/test/CodeGen/RISCV/rvv/vselect-int-rv32.ll b/llvm/test/CodeGen/RISCV/rvv/vselect-int-rv32.ll --- a/llvm/test/CodeGen/RISCV/rvv/vselect-int-rv32.ll +++ b/llvm/test/CodeGen/RISCV/rvv/vselect-int-rv32.ll @@ -69,6 +69,40 @@ ret %vc } +define @vmerge_vv_nxv3i8( %va, %vb, %cond) { +; CHECK-LABEL: vmerge_vv_nxv3i8: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e8, mf2, ta, mu +; CHECK-NEXT: vmerge.vvm v8, v9, v8, v0 +; CHECK-NEXT: ret + %vc = select %cond, %va, %vb + ret %vc +} + +define @vmerge_xv_nxv3i8( %va, i8 signext %b, %cond) { +; CHECK-LABEL: vmerge_xv_nxv3i8: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a1, zero, e8, mf2, ta, mu +; CHECK-NEXT: vmerge.vxm v8, v8, a0, v0 +; CHECK-NEXT: ret + %head = insertelement undef, i8 %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = select %cond, %splat, %va + ret %vc +} + +define @vmerge_iv_nxv3i8( %va, %cond) { +; CHECK-LABEL: vmerge_iv_nxv3i8: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e8, mf2, ta, mu +; CHECK-NEXT: vmerge.vim v8, v8, 3, v0 +; CHECK-NEXT: ret + %head = insertelement undef, i8 3, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = select %cond, %splat, %va + ret %vc +} + define @vmerge_vv_nxv4i8( %va, %vb, %cond) { ; CHECK-LABEL: vmerge_vv_nxv4i8: ; CHECK: # %bb.0: diff --git a/llvm/test/CodeGen/RISCV/rvv/vselect-int-rv64.ll b/llvm/test/CodeGen/RISCV/rvv/vselect-int-rv64.ll --- a/llvm/test/CodeGen/RISCV/rvv/vselect-int-rv64.ll +++ b/llvm/test/CodeGen/RISCV/rvv/vselect-int-rv64.ll @@ -69,6 +69,40 @@ ret %vc } +define @vmerge_vv_nxv3i8( %va, %vb, %cond) { +; CHECK-LABEL: vmerge_vv_nxv3i8: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e8, mf2, ta, mu +; CHECK-NEXT: vmerge.vvm v8, v9, v8, v0 +; CHECK-NEXT: ret + %vc = select %cond, %va, %vb + ret %vc +} + +define @vmerge_xv_nxv3i8( %va, i8 signext %b, %cond) { +; CHECK-LABEL: vmerge_xv_nxv3i8: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a1, zero, e8, mf2, ta, mu +; CHECK-NEXT: vmerge.vxm v8, v8, a0, v0 +; CHECK-NEXT: ret + %head = insertelement undef, i8 %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = select %cond, %splat, %va + ret %vc +} + +define @vmerge_iv_nxv3i8( %va, %cond) { +; CHECK-LABEL: vmerge_iv_nxv3i8: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e8, mf2, ta, mu +; CHECK-NEXT: vmerge.vim v8, v8, 3, v0 +; CHECK-NEXT: ret + %head = insertelement undef, i8 3, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = select %cond, %splat, %va + ret %vc +} + define @vmerge_vv_nxv4i8( %va, %vb, %cond) { ; CHECK-LABEL: vmerge_vv_nxv4i8: ; CHECK: # %bb.0: