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

Guozhi Wei via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 15 11:12:36 PDT 2017


Carrot updated this revision to Diff 115429.
Carrot marked an inline comment as done.
Carrot retitled this revision from "[TargetTransformInfo] Instruction alloca has 0 cost" to "[TargetTransformInfo] Static alloca has 0 cost".
Carrot edited the summary of this revision.

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,14 @@
 
 define i64 @foo(i64 %arg) {
 
+  ; LATENCY:  cost of 0 {{.*}} alloca i32
+  ; CODESIZE: cost of 0 {{.*}} alloca i32
+  %A1 = alloca i32, align 8
+
+  ; LATENCY:  cost of 1 {{.*}} alloca i64, i64 undef
+  ; CODESIZE: cost of 1 {{.*}} alloca i64, i64 undef
+  %A2 = alloca i64, i64 undef, 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,11 @@
     if (isa<PHINode>(U))
       return TTI::TCC_Free; // Model all PHI nodes as free.
 
+    // Static alloca doesn't generate target instructions.
+    if (auto *A = dyn_cast<AllocaInst>(U))
+      if (A->isStaticAlloca())
+        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.115429.patch
Type: text/x-patch
Size: 1361 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170915/3ae7fcd8/attachment.bin>


More information about the llvm-commits mailing list