Index: llvm/lib/CodeGen/TargetLoweringBase.cpp =================================================================== --- llvm/lib/CodeGen/TargetLoweringBase.cpp +++ llvm/lib/CodeGen/TargetLoweringBase.cpp @@ -1016,8 +1016,8 @@ // If type is to be expanded, split the vector. // <4 x i140> -> <2 x i140> if (LK.first == TypeExpandInteger) { - if (VT.getVectorElementCount() == ElementCount::getScalable(1)) - report_fatal_error("Cannot legalize this scalable vector"); + if (VT.getVectorElementCount().isScalable()) + return LegalizeKind(TypeScalarizeScalableVector, EltVT); return LegalizeKind(TypeSplitVector, VT.getHalfNumVectorElementsVT(Context)); } @@ -1080,7 +1080,7 @@ } if (VT.getVectorElementCount() == ElementCount::getScalable(1)) - report_fatal_error("Cannot legalize this vector"); + return LegalizeKind(TypeScalarizeScalableVector, EltVT); // Vectors with illegal element types are expanded. EVT NVT = EVT::getVectorVT(Context, EltVT, @@ -1845,6 +1845,9 @@ while (true) { LegalizeKind LK = getTypeConversion(C, MTy); + if (LK.first == TypeScalarizeScalableVector) + Cost.setInvalid(); + if (LK.first == TypeLegal) return std::make_pair(Cost, MTy.getSimpleVT()); Index: llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp =================================================================== --- llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp +++ llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp @@ -1180,6 +1180,9 @@ return BaseT::getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace, CostKind); auto LT = TLI->getTypeLegalizationCost(DL, Src); + if (!LT.first.isValid()) + return LT.first; + return LT.first * 2; } @@ -1192,6 +1195,9 @@ Alignment, CostKind, I); auto *VT = cast(DataTy); auto LT = TLI->getTypeLegalizationCost(DL, DataTy); + if (!LT.first.isValid()) + return LT.first; + ElementCount LegalVF = LT.second.getVectorElementCount(); Optional MaxNumVScale = getMaxVScale(); assert(MaxNumVScale && "Expected valid max vscale value"); @@ -1218,6 +1224,8 @@ CostKind); auto LT = TLI->getTypeLegalizationCost(DL, Ty); + if (!LT.first.isValid()) + return LT.first; // TODO: consider latency as well for TCK_SizeAndLatency. if (CostKind == TTI::TCK_CodeSize || CostKind == TTI::TCK_SizeAndLatency) Index: llvm/test/Analysis/CostModel/AArch64/sve-illegal-types.ll =================================================================== --- /dev/null +++ llvm/test/Analysis/CostModel/AArch64/sve-illegal-types.ll @@ -0,0 +1,49 @@ +; RUN: opt -cost-model -analyze -mtriple=aarch64--linux-gnu -mattr=+sve < %s | FileCheck %s + +define @load_nxvi128(* %val) { +; CHECK-LABEL: 'load_nxvi128' +; CHECK-NEXT: Invalid cost for instruction: %load = load , * %val + %load = load , * %val + ret %load +} + +define void @store_nxvi128(* %ptrs, %val) { +; CHECK-LABEL: 'store_nxvi128' +; CHECK-NEXT: Invalid cost for instruction: store %val, * %ptrs + store %val, * %ptrs + ret void +} + +define @masked_load_nxvfp128(* %val, %mask, %passthru) { +; CHECK-LABEL: 'masked_load_nxvfp128' +; CHECK-NEXT: Invalid cost for instruction: %mload = call @llvm.masked.load.nxv4f128.p0nxv4f128(* %val, i32 8, %mask, %passthru) + %mload = call @llvm.masked.load.nxv4f128(* %val, i32 8, %mask, %passthru) + ret %mload +} + +define void @masked_store_nxvfp128( %val, * %ptrs, %mask) { +; CHECK-LABEL: 'masked_store_nxvfp128' +; CHECK-NEXT: Invalid cost for instruction: call void @llvm.masked.store.nxv4f128.p0nxv4f128( %val, * %ptrs, i32 8, %mask) + call void @llvm.masked.store.nxv4f128( %val, * %ptrs, i32 8, %mask) + ret void +} + +define @masked_gather_nxv2i128( %ld, %masks, %passthru) { +; CHECK-LABEL: 'masked_gather_nxv2i128' +; CHECK-NEXT: Invalid cost for instruction: %mgather = call @llvm.masked.gather.nxv2i128.nxv2p0i128( %ld, i32 0, %masks, %passthru) + %mgather = call @llvm.masked.gather.nxv2i128( %ld, i32 0, %masks, %passthru) + ret %mgather +} + +define void @masked_scatter_nxv4i128( %val, %ptrs, %masks) { +; CHECK-LABEL: 'masked_scatter_nxv4i128' +; CHECK-NEXT: Invalid cost for instruction: call void @llvm.masked.scatter.nxv4i128.nxv4p0i128( %val, %ptrs, i32 0, %masks) + call void @llvm.masked.scatter.nxv4i128( %val, %ptrs, i32 0, %masks) + ret void +} + +declare @llvm.masked.load.nxv4f128(*, i32, , ) +declare @llvm.masked.gather.nxv2i128(, i32, , ) + +declare void @llvm.masked.store.nxv4f128(, *, i32, ) +declare void @llvm.masked.scatter.nxv4i128(, , i32, ) Index: llvm/test/Transforms/LoopVectorize/AArch64/scalable-vf-hint.ll =================================================================== --- llvm/test/Transforms/LoopVectorize/AArch64/scalable-vf-hint.ll +++ llvm/test/Transforms/LoopVectorize/AArch64/scalable-vf-hint.ll @@ -1,8 +1,8 @@ ; REQUIRES: asserts ; RUN: opt -mtriple=aarch64-none-linux-gnu -mattr=+sve -loop-vectorize -S -scalable-vectorization=on < %s 2>&1 | FileCheck %s ; RUN: opt -mtriple=aarch64-none-linux-gnu -mattr=+sve -loop-vectorize -pass-remarks-analysis=loop-vectorize -debug-only=loop-vectorize -S -scalable-vectorization=on < %s 2>&1 | FileCheck --check-prefix=CHECK-DBG %s -; RUN: opt -mtriple=aarch64-none-linux-gnu -loop-vectorize -pass-remarks-analysis=loop-vectorize -debug-only=loop-vectorize -S -scalable-vectorization=on < %s 2>&1 | FileCheck --check-prefix=CHECK-NO-SVE %s -; RUN: opt -mtriple=aarch64-none-linux-gnu -loop-vectorize -force-target-supports-scalable-vectors=true -pass-remarks-analysis=loop-vectorize -debug-only=loop-vectorize -S -scalable-vectorization=on < %s 2>&1 | FileCheck --check-prefix=CHECK-NO-MAX-VSCALE %s +; RUN: opt -mtriple=aarch64-none-linux-gnu -loop-vectorize -pass-remarks-analysis=loop-vectorize -debug-only=loop-vectorize -S -scalable-vectorization=on < %s 2>%t | FileCheck --check-prefix=CHECK-NO-SVE %s +; RUN: cat %t | FileCheck %s -check-prefix=CHECK-NO-SVE-REMARKS target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" @@ -309,11 +309,12 @@ !16 = !{!"llvm.loop.vectorize.width", i32 16} !17 = !{!"llvm.loop.vectorize.scalable.enable", i1 true} -; CHECK-NO-SVE-LABEL: LV: Checking a loop in "test_no_sve" -; CHECK-NO-SVE: LV: Disabling scalable vectorization, because target does not support scalable vectors. -; CHECK-NO-SVE: remark: :0:0: Disabling scalable vectorization, because target does not support scalable vectors. -; CHECK-NO-SVE: LV: User VF=vscale x 4 is unsafe. Ignoring scalable UserVF. -; CHECK-NO-SVE: LV: Selecting VF: 4. +; CHECK-NO-SVE-REMARKS-LABEL: LV: Checking a loop in "test_no_sve" +; CHECK-NO-SVE-REMARKS: LV: Disabling scalable vectorization, because target does not support scalable vectors. +; CHECK-NO-SVE-REMARKS: remark: :0:0: Disabling scalable vectorization, because target does not support scalable vectors. +; CHECK-NO-SVE-REMARKS: LV: User VF=vscale x 4 is unsafe. Ignoring scalable UserVF. +; CHECK-NO-SVE-REMARKS: LV: Selecting VF: 4. +; CHECK-NO-SVE-LABEL: @test_no_sve ; CHECK-NO-SVE: <4 x i32> ; CHECK-NO-SVE-NOT: define void @test_no_sve(i32* %a, i32* %b) { @@ -343,11 +344,12 @@ ; Test the LV falls back to fixed-width vectorization if scalable vectors are ; supported but max vscale is undefined. ; -; CHECK-NO-MAX-VSCALE-LABEL: LV: Checking a loop in "test_no_max_vscale" -; CEHCK-NO-MAX-VSCALE: The max safe fixed VF is: 4. -; CHECK-NO-MAX-VSCALE: LV: User VF=vscale x 4 is unsafe. Ignoring scalable UserVF. -; CHECK-NO-MAX-VSCALE: LV: Selecting VF: 4. -; CHECK-NO-MAX-VSCALE: <4 x i32> +; CHECK-NO-SVE-REMARKS-LABEL: LV: Checking a loop in "test_no_max_vscale" +; CHECK-NO-SVE-REMARKS: The max safe fixed VF is: 4. +; CHECK-NO-SVE-REMARKS: LV: User VF=vscale x 4 is unsafe. Ignoring scalable UserVF. +; CHECK-NO-SVE-REMARKS: LV: Selecting VF: 4. +; CHECK-NO-SVE-LABEL: @test_no_max_vscale +; CHECK-NO-SVE: <4 x i32> define void @test_no_max_vscale(i32* %a, i32* %b) { entry: br label %loop Index: llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp =================================================================== --- llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp +++ llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp @@ -573,11 +573,6 @@ EXPECT_EQ(getTypeToTransformTo(FromVT), ToVT); } -TEST_F(AArch64SelectionDAGTest, getTypeConversion_NoScalarizeEVT_nxv1f128) { - EVT FromVT = EVT::getVectorVT(Context, MVT::f128, 1, true); - EXPECT_DEATH(getTypeAction(FromVT), "Cannot legalize this vector"); -} - TEST_F(AArch64SelectionDAGTest, TestFold_STEP_VECTOR) { SDLoc Loc; auto IntVT = EVT::getIntegerVT(Context, 8);