Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp =================================================================== --- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -19221,9 +19221,9 @@ unsigned DestNumElts = V.getValueType().getVectorNumElements(); if ((SrcNumElts % DestNumElts) == 0) { unsigned SrcDestRatio = SrcNumElts / DestNumElts; - unsigned NewExtNumElts = NVT.getVectorNumElements() * SrcDestRatio; + ElementCount NewExtEC = NVT.getVectorElementCount() * SrcDestRatio; EVT NewExtVT = EVT::getVectorVT(*DAG.getContext(), SrcVT.getScalarType(), - NewExtNumElts); + NewExtEC); if (TLI.isOperationLegalOrCustom(ISD::EXTRACT_SUBVECTOR, NewExtVT)) { SDLoc DL(N); SDValue NewIndex = DAG.getVectorIdxConstant(ExtIdx * SrcDestRatio, DL); @@ -19235,13 +19235,13 @@ if ((DestNumElts % SrcNumElts) == 0) { unsigned DestSrcRatio = DestNumElts / SrcNumElts; if ((NVT.getVectorNumElements() % DestSrcRatio) == 0) { - unsigned NewExtNumElts = NVT.getVectorNumElements() / DestSrcRatio; + ElementCount NewExtEC = NVT.getVectorElementCount() / DestSrcRatio; EVT ScalarVT = SrcVT.getScalarType(); if ((ExtIdx % DestSrcRatio) == 0) { SDLoc DL(N); unsigned IndexValScaled = ExtIdx / DestSrcRatio; EVT NewExtVT = - EVT::getVectorVT(*DAG.getContext(), ScalarVT, NewExtNumElts); + EVT::getVectorVT(*DAG.getContext(), ScalarVT, NewExtEC); if (TLI.isOperationLegalOrCustom(ISD::EXTRACT_SUBVECTOR, NewExtVT)) { SDValue NewIndex = DAG.getVectorIdxConstant(IndexValScaled, DL); SDValue NewExtract = @@ -19249,7 +19249,7 @@ V.getOperand(0), NewIndex); return DAG.getBitcast(NVT, NewExtract); } - if (NewExtNumElts == 1 && + if (NewExtEC == 1 && TLI.isOperationLegalOrCustom(ISD::EXTRACT_VECTOR_ELT, ScalarVT)) { SDValue NewIndex = DAG.getVectorIdxConstant(IndexValScaled, DL); SDValue NewExtract = Index: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp =================================================================== --- llvm/lib/Target/AArch64/AArch64ISelLowering.cpp +++ llvm/lib/Target/AArch64/AArch64ISelLowering.cpp @@ -13856,9 +13856,6 @@ SDValue Idx = N->getOperand(3); uint64_t IdxConst = cast(Idx)->getZExtValue(); - if (IdxConst > Src1->getNumOperands() - 1) - report_fatal_error("index larger than expected"); - EVT ResVT = N->getValueType(0); uint64_t NumLanes = ResVT.getVectorElementCount().Min; SDValue Val = Index: llvm/test/CodeGen/AArch64/sve-extract-subvector.ll =================================================================== --- /dev/null +++ llvm/test/CodeGen/AArch64/sve-extract-subvector.ll @@ -0,0 +1,29 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve < %s | FileCheck %s + +; Test that DAGCombiner doesn't drop the scalable flag when it tries to fold: +; extract_subv (bitcast X), Index --> bitcast (extract_subv X, Index') + +define @extract_nxv16i8_nxv4i64( %z0_z1) { +; CHECK-LABEL: extract_nxv16i8_nxv4i64: +; CHECK: // %bb.0: +; CHECK-NEXT: mov z0.d, z1.d +; CHECK-NEXT: ret + %z0_z1_bc = bitcast %z0_z1 to + %ext = call @llvm.aarch64.sve.tuple.get.nxv32i8( %z0_z1_bc, i32 1) + ret %ext +} + + +define @extract_nxv2i64_nxv32i8( %z0_z1) { +; CHECK-LABEL: extract_nxv2i64_nxv32i8: +; CHECK: // %bb.0: +; CHECK-NEXT: mov z0.d, z1.d +; CHECK-NEXT: ret + %z0_z1_bc = bitcast %z0_z1 to + %ext = call @llvm.aarch64.sve.tuple.get.nxv4i64( %z0_z1_bc, i32 1) + ret %ext +} + +declare @llvm.aarch64.sve.tuple.get.nxv4i64(, i32) +declare @llvm.aarch64.sve.tuple.get.nxv32i8(, i32)