[llvm] r356555 - [TTI] getMemcpyCost

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 20 10:55:34 PDT 2019


There's already a good amount of information about lowering cost
scattered between SelectionDAG and TLI.  It would be really nice if the
default cost could be generalized to represent the default lowering
while still allowing targets to override if needed.

Philip

On 3/20/19 7:15 AM, Sjoerd Meijer via llvm-commits wrote:
> Author: sjoerdmeijer
> Date: Wed Mar 20 07:15:46 2019
> New Revision: 356555
>
> URL: http://llvm.org/viewvc/llvm-project?rev=356555&view=rev
> Log:
> [TTI] getMemcpyCost
>
> This adds new function getMemcpyCost to TTI so that the cost of a memcpy can be
> modeled and queried. The default implementation returns Expensive, but targets
> can override this function to model the cost more accurately.
>
> Differential Revision: https://reviews.llvm.org/D59252
>
> Added:
>     llvm/trunk/test/Analysis/CostModel/ARM/memcpy.ll
> Modified:
>     llvm/trunk/include/llvm/Analysis/TargetTransformInfo.h
>     llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h
>
> Modified: llvm/trunk/include/llvm/Analysis/TargetTransformInfo.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/TargetTransformInfo.h?rev=356555&r1=356554&r2=356555&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Analysis/TargetTransformInfo.h (original)
> +++ llvm/trunk/include/llvm/Analysis/TargetTransformInfo.h Wed Mar 20 07:15:46 2019
> @@ -246,6 +246,10 @@ public:
>                         ArrayRef<const Value *> Arguments,
>                         const User *U = nullptr) const;
>  
> +  /// \Return the expected cost of a memcpy, which could e.g. depend on the
> +  /// source/destination type and alignment and the number of bytes copied.
> +  int getMemcpyCost(const Instruction *I) const;
> +
>    /// \return The estimated number of case clusters when lowering \p 'SI'.
>    /// \p JTSize Set a jump table size only when \p SI is suitable for a jump
>    /// table.
> @@ -1053,6 +1057,7 @@ public:
>    virtual int getIntrinsicCost(Intrinsic::ID IID, Type *RetTy,
>                                 ArrayRef<const Value *> Arguments,
>                                 const User *U) = 0;
> +  virtual int getMemcpyCost(const Instruction *I) = 0;
>    virtual unsigned getEstimatedNumberOfCaseClusters(const SwitchInst &SI,
>                                                      unsigned &JTSize) = 0;
>    virtual int
> @@ -1267,6 +1272,9 @@ public:
>                         const User *U = nullptr) override {
>      return Impl.getIntrinsicCost(IID, RetTy, Arguments, U);
>    }
> +  int getMemcpyCost(const Instruction *I) {
> +    return Impl.getMemcpyCost(I);
> +  }
>    int getUserCost(const User *U, ArrayRef<const Value *> Operands) override {
>      return Impl.getUserCost(U, Operands);
>    }
>
> Modified: llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h?rev=356555&r1=356554&r2=356555&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h (original)
> +++ llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h Wed Mar 20 07:15:46 2019
> @@ -140,15 +140,22 @@ public:
>  
>    unsigned getInliningThresholdMultiplier() { return 1; }
>  
> +  unsigned getMemcpyCost(const Instruction *I) {
> +    return TTI::TCC_Expensive;
> +  }
> +
>    unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy,
>                              ArrayRef<Type *> ParamTys, const User *U) {
>      switch (IID) {
>      default:
>        // Intrinsics rarely (if ever) have normal argument setup constraints.
>        // Model them as having a basic instruction cost.
> -      // FIXME: This is wrong for libc intrinsics.
>        return TTI::TCC_Basic;
>  
> +    // TODO: other libc intrinsics.
> +    case Intrinsic::memcpy:
> +      return getMemcpyCost(dyn_cast<Instruction>(U));
> +
>      case Intrinsic::annotation:
>      case Intrinsic::assume:
>      case Intrinsic::sideeffect:
>
> Added: llvm/trunk/test/Analysis/CostModel/ARM/memcpy.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/CostModel/ARM/memcpy.ll?rev=356555&view=auto
> ==============================================================================
> --- llvm/trunk/test/Analysis/CostModel/ARM/memcpy.ll (added)
> +++ llvm/trunk/test/Analysis/CostModel/ARM/memcpy.ll Wed Mar 20 07:15:46 2019
> @@ -0,0 +1,13 @@
> +; RUN: opt < %s  -cost-model -analyze -cost-kind=code-size | FileCheck %s
> +
> +target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
> +target triple = "thumbv7m-arm-unknown-eabi"
> +
> +define void @memcpy(i8* %d, i8* %s, i32 %N) {
> +entry:
> +; CHECK: cost of 4 for instruction: call void @llvm.memcpy.p0i8.p0i8.i32
> +  call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 1 %d, i8* align 1 %s, i32 36, i1 false)
> +  ret void
> +}
> +
> +declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture writeonly, i8* nocapture readonly, i32, i1) #1
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list