<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi Philip,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Many thanks for your suggestions! My next steps were implementing this function in the ARM backend, and then actually use it. But I will now look first what's in SelectionDAG and TLI, and see if I can use and generalise this (to provide a default here in TTI).</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Thanks again,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Sjoerd.</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Philip Reames <listmail@philipreames.com><br>
<b>Sent:</b> 20 March 2019 17:55<br>
<b>To:</b> Sjoerd Meijer; llvm-commits@lists.llvm.org<br>
<b>Subject:</b> Re: [llvm] r356555 - [TTI] getMemcpyCost</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">There's already a good amount of information about lowering cost<br>
scattered between SelectionDAG and TLI.  It would be really nice if the<br>
default cost could be generalized to represent the default lowering<br>
while still allowing targets to override if needed.<br>
<br>
Philip<br>
<br>
On 3/20/19 7:15 AM, Sjoerd Meijer via llvm-commits wrote:<br>
> Author: sjoerdmeijer<br>
> Date: Wed Mar 20 07:15:46 2019<br>
> New Revision: 356555<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=356555&view=rev">http://llvm.org/viewvc/llvm-project?rev=356555&view=rev</a><br>
> Log:<br>
> [TTI] getMemcpyCost<br>
><br>
> This adds new function getMemcpyCost to TTI so that the cost of a memcpy can be<br>
> modeled and queried. The default implementation returns Expensive, but targets<br>
> can override this function to model the cost more accurately.<br>
><br>
> Differential Revision: <a href="https://reviews.llvm.org/D59252">https://reviews.llvm.org/D59252</a><br>
><br>
> Added:<br>
>     llvm/trunk/test/Analysis/CostModel/ARM/memcpy.ll<br>
> Modified:<br>
>     llvm/trunk/include/llvm/Analysis/TargetTransformInfo.h<br>
>     llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h<br>
><br>
> Modified: llvm/trunk/include/llvm/Analysis/TargetTransformInfo.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/TargetTransformInfo.h?rev=356555&r1=356554&r2=356555&view=diff">
http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/TargetTransformInfo.h?rev=356555&r1=356554&r2=356555&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/Analysis/TargetTransformInfo.h (original)<br>
> +++ llvm/trunk/include/llvm/Analysis/TargetTransformInfo.h Wed Mar 20 07:15:46 2019<br>
> @@ -246,6 +246,10 @@ public:<br>
>                         ArrayRef<const Value *> Arguments,<br>
>                         const User *U = nullptr) const;<br>
>  <br>
> +  /// \Return the expected cost of a memcpy, which could e.g. depend on the<br>
> +  /// source/destination type and alignment and the number of bytes copied.<br>
> +  int getMemcpyCost(const Instruction *I) const;<br>
> +<br>
>    /// \return The estimated number of case clusters when lowering \p 'SI'.<br>
>    /// \p JTSize Set a jump table size only when \p SI is suitable for a jump<br>
>    /// table.<br>
> @@ -1053,6 +1057,7 @@ public:<br>
>    virtual int getIntrinsicCost(Intrinsic::ID IID, Type *RetTy,<br>
>                                 ArrayRef<const Value *> Arguments,<br>
>                                 const User *U) = 0;<br>
> +  virtual int getMemcpyCost(const Instruction *I) = 0;<br>
>    virtual unsigned getEstimatedNumberOfCaseClusters(const SwitchInst &SI,<br>
>                                                      unsigned &JTSize) = 0;<br>
>    virtual int<br>
> @@ -1267,6 +1272,9 @@ public:<br>
>                         const User *U = nullptr) override {<br>
>      return Impl.getIntrinsicCost(IID, RetTy, Arguments, U);<br>
>    }<br>
> +  int getMemcpyCost(const Instruction *I) {<br>
> +    return Impl.getMemcpyCost(I);<br>
> +  }<br>
>    int getUserCost(const User *U, ArrayRef<const Value *> Operands) override {<br>
>      return Impl.getUserCost(U, Operands);<br>
>    }<br>
><br>
> Modified: llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h?rev=356555&r1=356554&r2=356555&view=diff">
http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h?rev=356555&r1=356554&r2=356555&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h (original)<br>
> +++ llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h Wed Mar 20 07:15:46 2019<br>
> @@ -140,15 +140,22 @@ public:<br>
>  <br>
>    unsigned getInliningThresholdMultiplier() { return 1; }<br>
>  <br>
> +  unsigned getMemcpyCost(const Instruction *I) {<br>
> +    return TTI::TCC_Expensive;<br>
> +  }<br>
> +<br>
>    unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy,<br>
>                              ArrayRef<Type *> ParamTys, const User *U) {<br>
>      switch (IID) {<br>
>      default:<br>
>        // Intrinsics rarely (if ever) have normal argument setup constraints.<br>
>        // Model them as having a basic instruction cost.<br>
> -      // FIXME: This is wrong for libc intrinsics.<br>
>        return TTI::TCC_Basic;<br>
>  <br>
> +    // TODO: other libc intrinsics.<br>
> +    case Intrinsic::memcpy:<br>
> +      return getMemcpyCost(dyn_cast<Instruction>(U));<br>
> +<br>
>      case Intrinsic::annotation:<br>
>      case Intrinsic::assume:<br>
>      case Intrinsic::sideeffect:<br>
><br>
> Added: llvm/trunk/test/Analysis/CostModel/ARM/memcpy.ll<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/CostModel/ARM/memcpy.ll?rev=356555&view=auto">
http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/CostModel/ARM/memcpy.ll?rev=356555&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/test/Analysis/CostModel/ARM/memcpy.ll (added)<br>
> +++ llvm/trunk/test/Analysis/CostModel/ARM/memcpy.ll Wed Mar 20 07:15:46 2019<br>
> @@ -0,0 +1,13 @@<br>
> +; RUN: opt < %s  -cost-model -analyze -cost-kind=code-size | FileCheck %s<br>
> +<br>
> +target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"<br>
> +target triple = "thumbv7m-arm-unknown-eabi"<br>
> +<br>
> +define void @memcpy(i8* %d, i8* %s, i32 %N) {<br>
> +entry:<br>
> +; CHECK: cost of 4 for instruction: call void @llvm.memcpy.p0i8.p0i8.i32<br>
> +  call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 1 %d, i8* align 1 %s, i32 36, i1 false)<br>
> +  ret void<br>
> +}<br>
> +<br>
> +declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture writeonly, i8* nocapture readonly, i32, i1) #1<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> llvm-commits@lists.llvm.org<br>
> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</div>
</span></font></div>
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose,
 or store or copy the information in any medium. Thank you.
</body>
</html>