xref: /llvm-project/llvm/test/Transforms/Inline/alloca_test.ll (revision 151602c7a9935558ca671b35359989b261045db0)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; This test ensures that alloca instructions in the entry block for an inlined
3; function are moved to the top of the function they are inlined into.
4;
5; RUN: opt -S -passes=inline < %s | FileCheck %s
6; RUN: opt -S -passes='cgscc(inline)' < %s | FileCheck %s
7
8define i32 @func(i32 %i) {
9  %X = alloca i32
10  store i32 %i, ptr %X
11  ret i32 %i
12}
13
14declare void @bar()
15
16define i32 @main(i32 %argc) {
17; CHECK-LABEL: @main(
18; CHECK-NEXT:  Entry:
19; CHECK-NEXT:    [[X_I:%.*]] = alloca i32
20;
21Entry:
22  call void @bar( )
23  %X = call i32 @func( i32 7 )
24  %Y = add i32 %X, %argc
25  ret i32 %Y
26}
27
28; https://llvm.org/bugs/show_bug.cgi?id=27277
29; Don't assume that the size is a ConstantInt (an undef value is also a constant).
30
31define void @PR27277(i32 %p1) {
32; CHECK-LABEL: @PR27277(
33; CHECK-NEXT:    [[VLA:%.*]] = alloca double, i32 %p1
34; CHECK-NEXT:    call void @PR27277(i32 undef)
35; CHECK-NEXT:    ret void
36;
37  %vla = alloca double, i32 %p1
38  call void @PR27277(i32 undef)
39  ret void
40}
41
42; Don't assume that the size is a ConstantInt (a ConstExpr is also a constant).
43
44@GV = common global ptr null
45
46define void @PR27277_part2(i32 %p1) {
47; CHECK-LABEL: @PR27277_part2(
48; CHECK-NEXT:    [[VLA:%.*]] = alloca double, i32 %p1
49; CHECK-NEXT:    call void @PR27277_part2(i32 ptrtoint (ptr @GV to i32))
50; CHECK-NEXT:    ret void
51;
52  %vla = alloca double, i32 %p1
53  call void @PR27277_part2(i32 ptrtoint (ptr @GV to i32))
54  ret void
55}
56
57