llvm.org GIT mirror llvm / d2e45b0
Merging r278571: ------------------------------------------------------------------------ r278571 | rnk | 2016-08-12 15:23:04 -0700 (Fri, 12 Aug 2016) | 6 lines [Inliner] Don't treat inalloca allocas as static They aren't static, and moving them to the entry block across something else will only result in tears. Root cause of http://crbug.com/636558. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_39@278831 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg 4 years ago
2 changed file(s) with 73 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
12931293 return DebugLoc::get(DL.getLine(), DL.getCol(), DL.getScope(), Last);
12941294 }
12951295
1296 /// Return the result of AI->isStaticAlloca() if AI were moved to the entry
1297 /// block. Allocas used in inalloca calls and allocas of dynamic array size
1298 /// cannot be static.
1299 static bool allocaWouldBeStaticInEntry(const AllocaInst *AI ) {
1300 return isa(AI->getArraySize()) && !AI->isUsedWithInAlloca();
1301 }
1302
12961303 /// Update inlined instructions' line numbers to
12971304 /// to encode location where these instructions are inlined.
12981305 static void fixupLineNumbers(Function *Fn, Function::iterator FI,
13271334
13281335 // Don't update static allocas, as they may get moved later.
13291336 if (auto *AI = dyn_cast(BI))
1330 if (isa(AI->getArraySize()))
1337 if (allocaWouldBeStaticInEntry(AI))
13311338 continue;
13321339
13331340 BI->setDebugLoc(TheCallDL);
16251632 continue;
16261633 }
16271634
1628 if (!isa(AI->getArraySize()))
1635 if (!allocaWouldBeStaticInEntry(AI))
16291636 continue;
16301637
16311638 // Keep track of the static allocas that we inline into the caller.
16341641 // Scan for the block of allocas that we can move over, and move them
16351642 // all at once.
16361643 while (isa(I) &&
1637 isa(cast(I)->getArraySize())) {
1644 allocaWouldBeStaticInEntry(cast(I))) {
16381645 IFI.StaticAllocas.push_back(cast(I));
16391646 ++I;
16401647 }
0 ; RUN: opt -always-inline -S < %s | FileCheck %s
1
2 ; We used to misclassify inalloca as a static alloca in the inliner. This only
3 ; arose with for alwaysinline functions, because the normal inliner refuses to
4 ; inline such things.
5
6 ; Generated using this C++ source:
7 ; struct Foo {
8 ; Foo();
9 ; Foo(const Foo &o);
10 ; ~Foo();
11 ; int a;
12 ; };
13 ; __forceinline void h(Foo o) {}
14 ; __forceinline void g() { h(Foo()); }
15 ; void f() { g(); }
16
17 ; ModuleID = 't.cpp'
18 source_filename = "t.cpp"
19 target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
20 target triple = "i386-pc-windows-msvc19.0.24210"
21
22 %struct.Foo = type { i32 }
23
24 declare i8* @llvm.stacksave()
25 declare void @llvm.stackrestore(i8*)
26
27 declare x86_thiscallcc %struct.Foo* @"\01??0Foo@@QAE@XZ"(%struct.Foo* returned) unnamed_addr
28 declare x86_thiscallcc void @"\01??1Foo@@QAE@XZ"(%struct.Foo*) unnamed_addr
29
30 define void @f() {
31 entry:
32 call void @g()
33 ret void
34 }
35
36 define internal void @g() alwaysinline {
37 entry:
38 %inalloca.save = call i8* @llvm.stacksave()
39 %argmem = alloca inalloca <{ %struct.Foo }>, align 4
40 %0 = getelementptr inbounds <{ %struct.Foo }>, <{ %struct.Foo }>* %argmem, i32 0, i32 0
41 %call = call x86_thiscallcc %struct.Foo* @"\01??0Foo@@QAE@XZ"(%struct.Foo* %0)
42 call void @h(<{ %struct.Foo }>* inalloca %argmem)
43 call void @llvm.stackrestore(i8* %inalloca.save)
44 ret void
45 }
46
47 ; Function Attrs: alwaysinline inlinehint nounwind
48 define internal void @h(<{ %struct.Foo }>* inalloca) alwaysinline {
49 entry:
50 %o = getelementptr inbounds <{ %struct.Foo }>, <{ %struct.Foo }>* %0, i32 0, i32 0
51 call x86_thiscallcc void @"\01??1Foo@@QAE@XZ"(%struct.Foo* %o)
52 ret void
53 }
54
55 ; CHECK: define void @f()
56 ; CHECK: %inalloca.save.i = call i8* @llvm.stacksave()
57 ; CHECK: alloca inalloca <{ %struct.Foo }>, align 4
58 ; CHECK: %call.i = call x86_thiscallcc %struct.Foo* @"\01??0Foo@@QAE@XZ"(%struct.Foo* %0)
59 ; CHECK: %o.i.i = getelementptr inbounds <{ %struct.Foo }>, <{ %struct.Foo }>* %argmem.i, i32 0, i32 0
60 ; CHECK: call x86_thiscallcc void @"\01??1Foo@@QAE@XZ"(%struct.Foo* %o.i.i)
61 ; CHECK: call void @llvm.stackrestore(i8* %inalloca.save.i)
62 ; CHECK: ret void