[InlineCost] Fix scalable vectors in visitAlloca
authorCullen Rhodes <cullen.rhodes@arm.com>
Wed, 12 Aug 2020 18:03:46 +0000 (18:03 +0000)
committerCullen Rhodes <cullen.rhodes@arm.com>
Mon, 17 Aug 2020 10:34:27 +0000 (10:34 +0000)
Discovered as part of the VLS type work (see D85128).

Reviewed By: efriedma

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

llvm/lib/Analysis/InlineCost.cpp
llvm/test/Transforms/Inline/inline-scalable.ll [new file with mode: 0644]

index 33d7144..0a2de5d 100644 (file)
@@ -867,7 +867,7 @@ bool CallAnalyzer::visitAlloca(AllocaInst &I) {
       // is needed to track stack usage during inlining.
       Type *Ty = I.getAllocatedType();
       AllocatedSize = SaturatingMultiplyAdd(
-          AllocSize->getLimitedValue(), DL.getTypeAllocSize(Ty).getFixedSize(),
+          AllocSize->getLimitedValue(), DL.getTypeAllocSize(Ty).getKnownMinSize(),
           AllocatedSize);
       if (AllocatedSize > InlineConstants::MaxSimplifiedDynamicAllocaToInline) {
         HasDynamicAlloca = true;
@@ -881,7 +881,7 @@ bool CallAnalyzer::visitAlloca(AllocaInst &I) {
   if (I.isStaticAlloca()) {
     Type *Ty = I.getAllocatedType();
     AllocatedSize =
-        SaturatingAdd(DL.getTypeAllocSize(Ty).getFixedSize(), AllocatedSize);
+        SaturatingAdd(DL.getTypeAllocSize(Ty).getKnownMinSize(), AllocatedSize);
   }
 
   // We will happily inline static alloca instructions.
diff --git a/llvm/test/Transforms/Inline/inline-scalable.ll b/llvm/test/Transforms/Inline/inline-scalable.ll
new file mode 100644 (file)
index 0000000..756f556
--- /dev/null
@@ -0,0 +1,11 @@
+; RUN: opt -S -inline < %s | FileCheck %s
+
+define void @func() {
+; CHECK-LABEL: func
+; CHECK-NEXT:    [[VEC_ADDR:%.*]] = alloca <vscale x 4 x i32>
+; CHECK-NEXT:    call void @func()
+; CHECK-NEXT:    ret void
+  %vec.addr = alloca <vscale x 4 x i32>
+  call void @func();
+  ret void
+}