[PATCH] D37879: [TargetTransformInfo] Instruction alloca has 0 cost

Guozhi Wei via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 14 17:32:59 PDT 2017


Carrot created this revision.

Instruction alloca usually doesn't generate any machine instructions, so it has 0 cost.


https://reviews.llvm.org/D37879

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
@@ -7,6 +7,10 @@
 
 define i64 @foo(i64 %arg) {
 
+  ; LATENCY:  cost of 0 {{.*}} alloca
+  ; CODESIZE: cost of 0 {{.*}} alloca
+  %A = alloca i64, align 8
+
   ; LATENCY:  cost of 1 {{.*}} %I64 = add
   ; CODESIZE: cost of 1 {{.*}} %I64 = add
   %I64 = add i64 undef, undef
Index: include/llvm/Analysis/TargetTransformInfoImpl.h
===================================================================
--- include/llvm/Analysis/TargetTransformInfoImpl.h
+++ include/llvm/Analysis/TargetTransformInfoImpl.h
@@ -740,6 +740,9 @@
     if (isa<PHINode>(U))
       return TTI::TCC_Free; // Model all PHI nodes as free.
 
+    if (isa<AllocaInst>(U))
+      return TTI::TCC_Free;
+
     if (const GEPOperator *GEP = dyn_cast<GEPOperator>(U)) {
       return static_cast<T *>(this)->getGEPCost(GEP->getSourceElementType(),
                                                 GEP->getPointerOperand(),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37879.115325.patch
Type: text/x-patch
Size: 1092 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170915/fa714436/attachment.bin>


More information about the llvm-commits mailing list