[llvm] r265005 - [TTI] Let the cost model estimate ctpop costs based on legality
Eric Christopher via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 31 13:17:17 PDT 2016
Thanks Ben!
-eric
On Thu, Mar 31, 2016 at 3:47 AM Benjamin Kramer via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
> Author: d0k
> Date: Thu Mar 31 05:42:40 2016
> New Revision: 265005
>
> URL: http://llvm.org/viewvc/llvm-project?rev=265005&view=rev
> Log:
> [TTI] Let the cost model estimate ctpop costs based on legality
>
> PPC has a vector popcount, this lets the vectorizer use the correct cost
> for it. Tweak X86 test to use an intrinsic that's actually scalarized (we
> have a somewhat efficient lowering for vector popcount using SSE, the
> cost model finds that now).
>
> Added:
> llvm/trunk/test/Analysis/CostModel/PowerPC/popcnt.ll
> Modified:
> llvm/trunk/include/llvm/CodeGen/BasicTTIImpl.h
> llvm/trunk/test/Analysis/CostModel/X86/scalarize.ll
>
> Modified: llvm/trunk/include/llvm/CodeGen/BasicTTIImpl.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/BasicTTIImpl.h?rev=265005&r1=265004&r2=265005&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/CodeGen/BasicTTIImpl.h (original)
> +++ llvm/trunk/include/llvm/CodeGen/BasicTTIImpl.h Thu Mar 31 05:42:40 2016
> @@ -621,6 +621,7 @@ public:
> unsigned getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy,
> ArrayRef<Type *> Tys) {
> unsigned ISD = 0;
> + unsigned SingleCallCost = 10; // Library call cost. Make it expensive.
> switch (IID) {
> default: {
> // Assume that we need to scalarize this intrinsic.
> @@ -725,6 +726,13 @@ public:
> case Intrinsic::masked_load:
> return static_cast<T *>(this)
> ->getMaskedMemoryOpCost(Instruction::Load, RetTy, 0, 0);
> + case Intrinsic::ctpop:
> + ISD = ISD::CTPOP;
> + // In case of legalization use TCC_Expensive. This is cheaper than a
> + // library call but still not a cheap instruction.
> + SingleCallCost = TargetTransformInfo::TCC_Expensive;
> + break;
> + // FIXME: ctlz, cttz, ...
> }
>
> const TargetLoweringBase *TLI = getTLI();
> @@ -785,7 +793,7 @@ public:
> }
>
> // This is going to be turned into a library call, make it expensive.
> - return 10;
> + return SingleCallCost;
> }
>
> /// \brief Compute a cost of the given call instruction.
>
> Added: llvm/trunk/test/Analysis/CostModel/PowerPC/popcnt.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/CostModel/PowerPC/popcnt.ll?rev=265005&view=auto
>
> ==============================================================================
> --- llvm/trunk/test/Analysis/CostModel/PowerPC/popcnt.ll (added)
> +++ llvm/trunk/test/Analysis/CostModel/PowerPC/popcnt.ll Thu Mar 31
> 05:42:40 2016
> @@ -0,0 +1,11 @@
> +; RUN: opt < %s -cost-model -analyze -mtriple=powerpc64-unknown-linux-gnu
> -mcpu=pwr8 | FileCheck %s
> +target datalayout =
> "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f128:128:128-v128:128:128-n32:64"
> +target triple = "powerpc64-unknown-linux-gnu"
> +
> +define <4 x i32> @test1(<4 x i32> %arg) {
> + ; CHECK: cost of 1 {{.*}} call <4 x i32> @llvm.ctpop.v4i32
> + %ctpop = call <4 x i32> @llvm.ctpop.v4i32(<4 x i32> %arg)
> + ret <4 x i32> %ctpop
> +}
> +
> +declare <4 x i32> @llvm.ctpop.v4i32(<4 x i32>)
>
> Modified: llvm/trunk/test/Analysis/CostModel/X86/scalarize.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/CostModel/X86/scalarize.ll?rev=265005&r1=265004&r2=265005&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Analysis/CostModel/X86/scalarize.ll (original)
> +++ llvm/trunk/test/Analysis/CostModel/X86/scalarize.ll Thu Mar 31
> 05:42:40 2016
> @@ -13,8 +13,8 @@
> declare %i4 @llvm.bswap.v4i32(%i4)
> declare %i8 @llvm.bswap.v2i64(%i8)
>
> -declare %i4 @llvm.ctpop.v4i32(%i4)
> -declare %i8 @llvm.ctpop.v2i64(%i8)
> +declare %i4 @llvm.cttz.v4i32(%i4)
> +declare %i8 @llvm.cttz.v2i64(%i8)
>
> ; CHECK32-LABEL: test_scalarized_intrinsics
> ; CHECK64-LABEL: test_scalarized_intrinsics
> @@ -28,12 +28,12 @@ define void @test_scalarized_intrinsics(
> ; CHECK64: cost of 6 {{.*}}bswap.v2i64
> %r3 = call %i8 @llvm.bswap.v2i64(%i8 undef)
>
> -; CHECK32: cost of 12 {{.*}}ctpop.v4i32
> -; CHECK64: cost of 12 {{.*}}ctpop.v4i32
> - %r4 = call %i4 @llvm.ctpop.v4i32(%i4 undef)
> -; CHECK32: cost of 10 {{.*}}ctpop.v2i64
> -; CHECK64: cost of 6 {{.*}}ctpop.v2i64
> - %r5 = call %i8 @llvm.ctpop.v2i64(%i8 undef)
> +; CHECK32: cost of 12 {{.*}}cttz.v4i32
> +; CHECK64: cost of 12 {{.*}}cttz.v4i32
> + %r4 = call %i4 @llvm.cttz.v4i32(%i4 undef)
> +; CHECK32: cost of 10 {{.*}}cttz.v2i64
> +; CHECK64: cost of 6 {{.*}}cttz.v2i64
> + %r5 = call %i8 @llvm.cttz.v2i64(%i8 undef)
>
> ; CHECK32: ret
> ; CHECK64: ret
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160331/93c71fdb/attachment.html>
More information about the llvm-commits
mailing list