1 ; RUN: opt -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 i32* %v1
14 ; CHECK-NEXT: %p1 = bitcast i32* %v1 to i8*
15 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i8* %p1,
16 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 undef, i8* %p1, i64 4, i1 true)
18 ; CHECK-LABEL: define internal void @test.loop2()
19 ; CHECK-NEXT: newFuncRoot:
20 ; CHECK-NEXT: %v2 = alloca i32
21 ; CHECK-NEXT: %p2 = bitcast i32* %v2 to i8*
23 ; CHECK-LABEL: define internal void @test.loop1(i8* %p1)
24 ; CHECK-NEXT: newFuncRoot:
29 %v1 = alloca i32, align 4
30 %v2 = alloca i32, align 4
31 %p1 = bitcast i32* %v1 to i8*
32 %p2 = bitcast i32* %v2 to i8*
33 call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 undef, i8* %p1, i64 4, i1 true)
37 call void @llvm.lifetime.start.p0i8(i64 4, i8* %p1)
38 %r1 = call i32 @foo(i8* %p1)
39 call void @llvm.lifetime.end.p0i8(i64 4, i8* %p1)
40 %cmp1 = icmp ne i32 %r1, 0
41 br i1 %cmp1, label %loop1, label %loop2
44 call void @llvm.lifetime.start.p0i8(i64 4, i8* %p2)
45 %r2 = call i32 @foo(i8* %p2)
46 call void @llvm.lifetime.end.p0i8(i64 4, i8* %p2)
47 %cmp2 = icmp ne i32 %r2, 0
48 br i1 %cmp2, label %loop2, label %exit
56 declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture)
57 declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture)
58 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i64, i1 immarg)