Index: llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h =================================================================== --- llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h +++ llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -740,6 +740,11 @@ if (isa(U)) return TTI::TCC_Free; // Model all PHI nodes as free. + // Static alloca doesn't generate target instructions. + if (auto *A = dyn_cast(U)) + if (A->isStaticAlloca()) + return TTI::TCC_Free; + if (const GEPOperator *GEP = dyn_cast(U)) { return static_cast(this)->getGEPCost(GEP->getSourceElementType(), GEP->getPointerOperand(), Index: llvm/trunk/test/Analysis/CostModel/X86/costmodel.ll =================================================================== --- llvm/trunk/test/Analysis/CostModel/X86/costmodel.ll +++ llvm/trunk/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