1 ; RUN: opt -passes=debugify,loop-simplify,loop-extract -S < %s | FileCheck %s
2 ; RUN: opt -passes=debugify,loop-simplify,loop-extract -S < %s --try-experimental-debuginfo-iterators | FileCheck %s
5 ; 1. loop1 should be extracted into a function, without extracting %v1 alloca.
6 ; 2. loop2 should be extracted into a function, with the %v2 alloca.
8 ; This used to produce an invalid IR, where `memcpy` will have a reference to
9 ; the, now, external value (local to the extracted loop function).
11 ; CHECK-LABEL: define void @test()
13 ; CHECK-NEXT: %v1 = alloca i32
14 ; CHECK-NEXT: #dbg_value(ptr %v1
15 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 undef, ptr %v1, i64 4, i1 true)
17 ; CHECK-LABEL: define internal void @test.loop2()
18 ; CHECK-NEXT: newFuncRoot:
19 ; CHECK-NEXT: %v2 = alloca i32
21 ; CHECK-LABEL: define internal void @test.loop1(ptr %v1)
22 ; CHECK-NEXT: newFuncRoot:
27 %v1 = alloca i32, align 4
28 %v2 = alloca i32, align 4
29 call void @llvm.memcpy.p0.p0.i64(ptr align 4 undef, ptr %v1, i64 4, i1 true)
33 call void @llvm.lifetime.start.p0(i64 4, ptr %v1)
34 %r1 = call i32 @foo(ptr %v1)
35 call void @llvm.lifetime.end.p0(i64 4, ptr %v1)
36 %cmp1 = icmp ne i32 %r1, 0
37 br i1 %cmp1, label %loop1, label %loop2
40 call void @llvm.lifetime.start.p0(i64 4, ptr %v2)
41 %r2 = call i32 @foo(ptr %v2)
42 call void @llvm.lifetime.end.p0(i64 4, ptr %v2)
43 %cmp2 = icmp ne i32 %r2, 0
44 br i1 %cmp2, label %loop2, label %exit
52 declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture)
53 declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture)
54 declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg)