[PATCH] D38104: [TargetTransformInfo] Handle intrinsic call in getInstructionLatency()

Guozhi Wei via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 20 15:33:12 PDT 2017


Carrot created this revision.

Usually an intrinsic is a simple target instruction, it should have a small latency. A real function call has much larger latency. So handle the intrinsic call in function getInstructionLatency().


https://reviews.llvm.org/D38104

Files:
  include/llvm/Analysis/TargetTransformInfoImpl.h
  test/Analysis/CostModel/X86/costmodel.ll


Index: test/Analysis/CostModel/X86/costmodel.ll
===================================================================
--- test/Analysis/CostModel/X86/costmodel.ll
+++ test/Analysis/CostModel/X86/costmodel.ll
@@ -5,6 +5,8 @@
 
 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-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
 
+declare { i32, i1 } @llvm.uadd.with.overflow.i32(i32, i32)
+
 define i64 @foo(i64 %arg) {
 
   ; LATENCY:  cost of 0 {{.*}} alloca i32
@@ -39,6 +41,10 @@
   ; CODESIZE: cost of 0 {{.*}} trunc
   %TC = trunc i64 undef to i32
 
+  ; LATENCY:  cost of 1 {{.*}} call
+  ; CODESIZE: cost of 1 {{.*}} call
+  %uadd = call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 undef, i32 undef)
+
   ; LATENCY:  cost of 1 {{.*}} ret
   ; CODESIZE: cost of 1 {{.*}} ret
   ret i64 undef
Index: include/llvm/Analysis/TargetTransformInfoImpl.h
===================================================================
--- include/llvm/Analysis/TargetTransformInfoImpl.h
+++ include/llvm/Analysis/TargetTransformInfoImpl.h
@@ -785,8 +785,14 @@
     if (getUserCost(I, Operands) == TTI::TCC_Free)
       return 0;
 
-    if (isa<CallInst>(I))
+    // Usually an intrinsic is a simple instruction.
+    // A real function call is much slower.
+    if (auto *CI = dyn_cast<CallInst>(I)) {
+      const Function *F = CI->getCalledFunction();
+      if (F && F->getIntrinsicID())
+        return 1;
       return 40;
+    }
 
     if (isa<LoadInst>(I))
       return 4;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38104.116096.patch
Type: text/x-patch
Size: 1535 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170920/9b5bd65b/attachment.bin>


More information about the llvm-commits mailing list