[PATCH] D37833: [TargetTransformInfo] Detect 0 latency instructions

Guozhi Wei via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 14 12:21:28 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL313288: [TargetTransformInfo] Detect 0 latency instructions (authored by Carrot).

Changed prior to commit:
  https://reviews.llvm.org/D37833?vs=115134&id=115258#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D37833

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


Index: llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h
===================================================================
--- llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h
+++ llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h
@@ -775,7 +775,9 @@
   }
 
   int getInstructionLatency(const Instruction *I) {
-    if (isa<PHINode>(I))
+    SmallVector<const Value *, 4> Operands(I->value_op_begin(),
+                                           I->value_op_end());
+    if (getUserCost(I, Operands) == TTI::TCC_Free)
       return 0;
 
     if (isa<CallInst>(I))
Index: llvm/trunk/test/Analysis/CostModel/X86/costmodel.ll
===================================================================
--- llvm/trunk/test/Analysis/CostModel/X86/costmodel.ll
+++ llvm/trunk/test/Analysis/CostModel/X86/costmodel.ll
@@ -3,6 +3,8 @@
 
 ; Tests if the interface TargetTransformInfo::getInstructionCost() works correctly.
 
+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"
+
 define i64 @foo(i64 %arg) {
 
   ; LATENCY:  cost of 1 {{.*}} %I64 = add
@@ -13,6 +15,22 @@
   ; CODESIZE: cost of 1 {{.*}} load
   load i64, i64* undef, align 4
 
+  ; LATENCY:  cost of 0 {{.*}} bitcast
+  ; CODESIZE: cost of 0 {{.*}} bitcast
+  %BC = bitcast i8* undef to i32*
+
+  ; LATENCY:  cost of 0 {{.*}} inttoptr
+  ; CODESIZE: cost of 0 {{.*}} inttoptr
+  %I2P = inttoptr i64 undef to i8*
+
+  ; LATENCY:  cost of 0 {{.*}} ptrtoint
+  ; CODESIZE: cost of 0 {{.*}} ptrtoint
+  %P2I = ptrtoint i8* undef to i64
+
+  ; LATENCY:  cost of 0 {{.*}} trunc
+  ; CODESIZE: cost of 0 {{.*}} trunc
+  %TC = trunc i64 undef to i32
+
   ; LATENCY:  cost of 1 {{.*}} ret
   ; CODESIZE: cost of 1 {{.*}} ret
   ret i64 undef


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37833.115258.patch
Type: text/x-patch
Size: 1829 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170914/24638995/attachment.bin>


More information about the llvm-commits mailing list