summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuozhi Wei <carrot@google.com>2017-09-15 22:28:12 +0000
committerGuozhi Wei <carrot@google.com>2017-09-15 22:28:12 +0000
commit3d1305f6da8dbaa16716793f260d3d0edfb9fcd5 (patch)
treea81a68724066f198e63203a8994da74f80251df1
parentbeb22b543718734ae62fc7325aa73d6708b2a42f (diff)
downloadbcm5719-llvm-3d1305f6da8dbaa16716793f260d3d0edfb9fcd5.tar.gz
bcm5719-llvm-3d1305f6da8dbaa16716793f260d3d0edfb9fcd5.zip
[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 llvm-svn: 313410
-rw-r--r--llvm/include/llvm/Analysis/TargetTransformInfoImpl.h5
-rw-r--r--llvm/test/Analysis/CostModel/X86/costmodel.ll8
2 files changed, 13 insertions, 0 deletions
diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
index 2191bd16456..63b47ffa3a5 100644
--- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
+++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
@@ -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(),
diff --git a/llvm/test/Analysis/CostModel/X86/costmodel.ll b/llvm/test/Analysis/CostModel/X86/costmodel.ll
index f7958580b13..d16cc27cb16 100644
--- a/llvm/test/Analysis/CostModel/X86/costmodel.ll
+++ b/llvm/test/Analysis/CostModel/X86/costmodel.ll
@@ -7,6 +7,14 @@ target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f3
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
OpenPOWER on IntegriCloud