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