1; RUN: opt -debugify -loop-simplify -loop-extract -S < %s | FileCheck %s 2 3; This tests 2 cases: 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. 6; 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). 9 10; CHECK-LABEL: define void @test() 11; CHECK-NEXT: entry: 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) 17 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* 22 23; CHECK-LABEL: define internal void @test.loop1(i8* %p1) 24; CHECK-NEXT: newFuncRoot: 25; CHECK-NEXT: br 26 27define void @test() { 28entry: 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) 34 br label %loop1 35 36loop1: 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 42 43loop2: 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 49 50exit: 51 ret void 52} 53 54declare i32 @foo(i8*) 55 56declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) 57declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) 58declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i64, i1 immarg) 59