diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp --- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp @@ -1569,8 +1569,7 @@ InstructionCost AArch64TTIImpl::getGatherScatterOpCost( unsigned Opcode, Type *DataTy, const Value *Ptr, bool VariableMask, Align Alignment, TTI::TargetCostKind CostKind, const Instruction *I) { - - if (!isa(DataTy)) + if (useNeonVector(DataTy)) return BaseT::getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask, Alignment, CostKind, I); auto *VT = cast(DataTy); @@ -1589,7 +1588,11 @@ ElementCount LegalVF = LT.second.getVectorElementCount(); InstructionCost MemOpCost = getMemoryOpCost(Opcode, VT->getElementType(), Alignment, 0, CostKind, I); - return LT.first * MemOpCost * getMaxNumElements(LegalVF, I->getFunction()); + unsigned int MaxNumElements = getMaxNumElements(LegalVF, I->getFunction()); + if(isa(DataTy)) + return (LT.first * MemOpCost * MaxNumElements) / MaxNumElements; + else + return LT.first * MemOpCost * MaxNumElements; } bool AArch64TTIImpl::useNeonVector(const Type *Ty) const { diff --git a/llvm/test/Analysis/CostModel/AArch64/sve-gather-vls.ll b/llvm/test/Analysis/CostModel/AArch64/sve-gather-vls.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Analysis/CostModel/AArch64/sve-gather-vls.ll @@ -0,0 +1,51 @@ +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=256 | FileCheck %s -D#VBITS=256 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=384 | FileCheck %s -D#VBITS=256 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=512 | FileCheck %s -D#VBITS=512 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=640 | FileCheck %s -D#VBITS=512 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=768 | FileCheck %s -D#VBITS=512 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=896 | FileCheck %s -D#VBITS=512 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=1024 | FileCheck %s -D#VBITS=1024 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=1152 | FileCheck %s -D#VBITS=1024 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=1280 | FileCheck %s -D#VBITS=1024 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=1408 | FileCheck %s -D#VBITS=1024 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=1536 | FileCheck %s -D#VBITS=1024 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=1664 | FileCheck %s -D#VBITS=1024 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=1792 | FileCheck %s -D#VBITS=1024 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=1920 | FileCheck %s -D#VBITS=1024 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=2048 | FileCheck %s -D#VBITS=2048 + +target triple = "aarch64-unknown-linux-gnu" + +define void @sve-gather_vls(<512 x i1> %v512i1mask, <256 x i1> %v256i1mask, <128 x i1> %v128i1mask, <16 x i1> %v16i1mask) #0 { +; CHECK-LABEL: 'sve-gather_vls' +; CHECK: Cost Model: Found an estimated cost of [[#div(mul(div(2047,VBITS)+1,div(VBITS,8)),div(VBITS,8))]] for instruction: %res.v256i8 = call <256 x i8> @llvm.masked.gather.v256i8.v256p0i8(<256 x i8*> undef, i32 0, <256 x i1> %v256i1mask, <256 x i8> zeroinitializer) +; CHECK: Cost Model: Found an estimated cost of [[#div(mul(div(4095,VBITS)+1,div(VBITS,16)),div(VBITS,16))]] for instruction: %res.v256i16 = call <256 x i16> @llvm.masked.gather.v256i16.v256p0i16(<256 x i16*> undef, i32 0, <256 x i1> %v256i1mask, <256 x i16> zeroinitializer) +; CHECK: Cost Model: Found an estimated cost of [[#div(mul(div(511,VBITS)+1,div(VBITS,32)),div(VBITS,32))]] for instruction: %res.v16i32 = call <16 x i32> @llvm.masked.gather.v16i32.v16p0i32(<16 x i32*> undef, i32 0, <16 x i1> %v16i1mask, <16 x i32> zeroinitializer) +; CHECK: Cost Model: Found an estimated cost of [[#div(mul(div(1023,VBITS)+1,div(VBITS,64)),div(VBITS,64))]] for instruction: %res.v16i64 = call <16 x i64> @llvm.masked.gather.v16i64.v16p0i64(<16 x i64*> undef, i32 0, <16 x i1> %v16i1mask, <16 x i64> zeroinitializer) +; CHECK: Cost Model: Found an estimated cost of [[#div(mul(div(8191,VBITS)+1,div(VBITS,16)),div(VBITS,16))]] for instruction: %res.v512f16 = call <512 x half> @llvm.masked.gather.v512f16.v512p0f16(<512 x half*> undef, i32 0, <512 x i1> %v512i1mask, <512 x half> zeroinitializer) +; CHECK: Cost Model: Found an estimated cost of [[#div(mul(div(8191,VBITS)+1,div(VBITS,32)),div(VBITS,32))]] for instruction: %res.v256f32 = call <256 x float> @llvm.masked.gather.v256f32.v256p0f32(<256 x float*> undef, i32 0, <256 x i1> %v256i1mask, <256 x float> zeroinitializer) +; CHECK: Cost Model: Found an estimated cost of [[#div(mul(div(8191,VBITS)+1,div(VBITS,64)),div(VBITS,64))]] for instruction: %res.v128f64 = call <128 x double> @llvm.masked.gather.v128f64.v128p0f64(<128 x double*> undef, i32 0, <128 x i1> %v128i1mask, <128 x double> zeroinitializer) +; CHECK: Cost Model: Found an estimated cost of 0 for instruction: ret void +entry: + %res.v256i8 = call <256 x i8> @llvm.masked.gather.v256i8.v256p0i8(<256 x i8*> undef, i32 0, <256 x i1> %v256i1mask, <256 x i8> zeroinitializer) + %res.v256i16 = call <256 x i16> @llvm.masked.gather.v256i16.v256p0i16(<256 x i16*> undef, i32 0, <256 x i1> %v256i1mask, <256 x i16> zeroinitializer) + %res.v16i32 = call <16 x i32> @llvm.masked.gather.v16i32.v16p0i32(<16 x i32*> undef, i32 0, <16 x i1> %v16i1mask, <16 x i32> zeroinitializer) + %res.v16i64 = call <16 x i64> @llvm.masked.gather.v16i64.v16p0i64(<16 x i64*> undef, i32 0, <16 x i1> %v16i1mask, <16 x i64> zeroinitializer) + + %res.v512f16 = call <512 x half> @llvm.masked.gather.v512f16.v512p0f16(<512 x half*> undef, i32 0, <512 x i1> %v512i1mask, <512 x half> zeroinitializer) + %res.v256f32 = call <256 x float> @llvm.masked.gather.v256f32.v256p0f32(<256 x float*> undef, i32 0, <256 x i1> %v256i1mask, <256 x float> zeroinitializer) + %res.v128f64 = call <128 x double> @llvm.masked.gather.v128f64.v128p0f64(<128 x double*> undef, i32 0, <128 x i1> %v128i1mask, <128 x double> zeroinitializer) + + ret void +} + +declare <256 x i8> @llvm.masked.gather.v256i8.v256p0i8(<256 x i8*>, i32, <256 x i1>, <256 x i8>) +declare <256 x i16> @llvm.masked.gather.v256i16.v256p0i16(<256 x i16*>, i32, <256 x i1>, <256 x i16>) +declare <16 x i32> @llvm.masked.gather.v16i32.v16p0i32(<16 x i32*>, i32, <16 x i1>, <16 x i32>) +declare <16 x i64> @llvm.masked.gather.v16i64.v16p0i64(<16 x i64*>, i32, <16 x i1>, <16 x i64>) + +declare <512 x half> @llvm.masked.gather.v512f16.v512p0f16(<512 x half*>, i32, <512 x i1>, <512 x half>) +declare <256 x float> @llvm.masked.gather.v256f32.v256p0f32(<256 x float*>, i32, <256 x i1>, <256 x float>) +declare <128 x double> @llvm.masked.gather.v128f64.v128p0f64(<128 x double*>, i32, <128 x i1>, <128 x double>) + +attributes #0 = { "target-features"="+sve" } diff --git a/llvm/test/Analysis/CostModel/AArch64/sve-scatter-vls.ll b/llvm/test/Analysis/CostModel/AArch64/sve-scatter-vls.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Analysis/CostModel/AArch64/sve-scatter-vls.ll @@ -0,0 +1,50 @@ +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=256 | FileCheck %s -D#VBITS=256 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=384 | FileCheck %s -D#VBITS=256 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=512 | FileCheck %s -D#VBITS=512 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=640 | FileCheck %s -D#VBITS=512 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=768 | FileCheck %s -D#VBITS=512 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=896 | FileCheck %s -D#VBITS=512 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=1024 | FileCheck %s -D#VBITS=1024 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=1152 | FileCheck %s -D#VBITS=1024 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=1280 | FileCheck %s -D#VBITS=1024 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=1408 | FileCheck %s -D#VBITS=1024 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=1536 | FileCheck %s -D#VBITS=1024 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=1664 | FileCheck %s -D#VBITS=1024 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=1792 | FileCheck %s -D#VBITS=1024 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=1920 | FileCheck %s -D#VBITS=1024 +; RUN: opt < %s -cost-model -analyze -aarch64-sve-vector-bits-min=2048 | FileCheck %s -D#VBITS=2048 + +target triple = "aarch64-unknown-linux-gnu" + +define void @sve-scatter_vls(<512 x i1> %v512i1mask, <256 x i1> %v256i1mask, <128 x i1> %v128i1mask, <16 x i1> %v16i1mask) #0 { +; CHECK-LABEL: 'sve-scatter_vls' +; CHECK: Cost Model: Found an estimated cost of [[#div(mul(div(2047,VBITS)+1,div(VBITS,8)),div(VBITS,8))]] for instruction: call void @llvm.masked.scatter.v256i8.v256p0i8(<256 x i8> undef, <256 x i8*> undef, i32 0, <256 x i1> %v256i1mask) +; CHECK: Cost Model: Found an estimated cost of [[#div(mul(div(4095,VBITS)+1,div(VBITS,16)),div(VBITS,16))]] for instruction: call void @llvm.masked.scatter.v256i16.v256p0i16(<256 x i16> undef, <256 x i16*> undef, i32 0, <256 x i1> %v256i1mask) +; CHECK: Cost Model: Found an estimated cost of [[#div(mul(div(511,VBITS)+1,div(VBITS,32)),div(VBITS,32))]] for instruction: call void @llvm.masked.scatter.v16i32.v16p0i32(<16 x i32> undef, <16 x i32*> undef, i32 0, <16 x i1> %v16i1mask) +; CHECK: Cost Model: Found an estimated cost of [[#div(mul(div(1023,VBITS)+1,div(VBITS,64)),div(VBITS,64))]] for instruction: call void @llvm.masked.scatter.v16i64.v16p0i64(<16 x i64> undef, <16 x i64*> undef, i32 0, <16 x i1> %v16i1mask) +; CHECK: Cost Model: Found an estimated cost of [[#div(mul(div(8191,VBITS)+1,div(VBITS,16)),div(VBITS,16))]] for instruction: call void @llvm.masked.scatter.v512f16.v512p0f16(<512 x half> undef, <512 x half*> undef, i32 0, <512 x i1> %v512i1mask) +; CHECK: Cost Model: Found an estimated cost of [[#div(mul(div(8191,VBITS)+1,div(VBITS,32)),div(VBITS,32))]] for instruction: call void @llvm.masked.scatter.v256f32.v256p0f32(<256 x float> undef, <256 x float*> undef, i32 0, <256 x i1> %v256i1mask) +; CHECK: Cost Model: Found an estimated cost of [[#div(mul(div(8191,VBITS)+1,div(VBITS,64)),div(VBITS,64))]] for instruction: call void @llvm.masked.scatter.v128f64.v128p0f64(<128 x double> undef, <128 x double*> undef, i32 0, <128 x i1> %v128i1mask) +; CHECK: Cost Model: Found an estimated cost of 0 for instruction: ret void +entry: + call void @llvm.masked.scatter.v256i8.v256p0i8(<256 x i8> undef, <256 x i8*> undef, i32 0, <256 x i1> %v256i1mask) + call void @llvm.masked.scatter.v256i16.v256p0i16(<256 x i16> undef, <256 x i16*> undef, i32 0, <256 x i1> %v256i1mask) + call void @llvm.masked.scatter.v16i32.v16p0i32(<16 x i32> undef, <16 x i32*> undef, i32 0, <16 x i1> %v16i1mask) + call void @llvm.masked.scatter.v16i64.v16p0i64(<16 x i64> undef, <16 x i64*> undef, i32 0, <16 x i1> %v16i1mask) + + call void @llvm.masked.scatter.v512f16.v512p0f16(<512 x half> undef, <512 x half*> undef, i32 0, <512 x i1> %v512i1mask) + call void @llvm.masked.scatter.v256f32.v256p0f32(<256 x float> undef, <256 x float*> undef, i32 0, <256 x i1> %v256i1mask) + call void @llvm.masked.scatter.v128f64.v128p0f64(<128 x double> undef, <128 x double*> undef, i32 0, <128 x i1> %v128i1mask) + ret void +} + +declare void @llvm.masked.scatter.v256i8.v256p0i8(<256 x i8>, <256 x i8*>, i32, <256 x i1>) +declare void @llvm.masked.scatter.v256i16.v256p0i16(<256 x i16>, <256 x i16*>, i32, <256 x i1>) +declare void @llvm.masked.scatter.v16i32.v16p0i32(<16 x i32>, <16 x i32*>, i32, <16 x i1>) +declare void @llvm.masked.scatter.v16i64.v16p0i64(<16 x i64>, <16 x i64*>, i32, <16 x i1>) + +declare void @llvm.masked.scatter.v512f16.v512p0f16(<512 x half>, <512 x half*>, i32, <512 x i1>) +declare void @llvm.masked.scatter.v256f32.v256p0f32(<256 x float>, <256 x float*>, i32, <256 x i1>) +declare void @llvm.masked.scatter.v128f64.v128p0f64(<128 x double>, <128 x double*>, i32, <128 x i1>) + +attributes #0 = { "target-features"="+sve" }