summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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