[llvm] r313410 - [TargetTransformInfo] Static alloca has 0 cost

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


Author: carrot
Date: Fri Sep 15 15:28:12 2017
New Revision: 313410

URL: http://llvm.org/viewvc/llvm-project?rev=313410&view=rev
Log:
[TargetTransformInfo] Static alloca has 0 cost

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

Differential Revision: https://reviews.llvm.org/D37879


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

Modified: llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h?rev=313410&r1=313409&r2=313410&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h (original)
+++ llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h Fri Sep 15 15:28:12 2017
@@ -740,6 +740,11 @@ public:
     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(),

Modified: llvm/trunk/test/Analysis/CostModel/X86/costmodel.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/CostModel/X86/costmodel.ll?rev=313410&r1=313409&r2=313410&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/CostModel/X86/costmodel.ll (original)
+++ llvm/trunk/test/Analysis/CostModel/X86/costmodel.ll Fri Sep 15 15:28:12 2017
@@ -7,6 +7,14 @@ target datalayout = "e-p:64:64:64-i1:8:8
 
 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




More information about the llvm-commits mailing list