55 lines · plain
1; RUN: opt -passes=debugify,loop-simplify,loop-extract -S < %s | FileCheck %s2 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 to8; 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 i3213; CHECK-NEXT: #dbg_value(ptr %v114; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 undef, ptr %v1, i64 4, i1 true)15 16; CHECK-LABEL: define internal void @test.loop2()17; CHECK-NEXT: newFuncRoot:18; CHECK-NEXT: %v2 = alloca i3219 20; CHECK-LABEL: define internal void @test.loop1(ptr %v1)21; CHECK-NEXT: newFuncRoot:22; CHECK-NEXT: #dbg_value23; CHECK-NEXT: br24 25define void @test() {26entry:27 %v1 = alloca i32, align 428 %v2 = alloca i32, align 429 call void @llvm.memcpy.p0.p0.i64(ptr align 4 undef, ptr %v1, i64 4, i1 true)30 br label %loop131 32loop1:33 call void @llvm.lifetime.start.p0(ptr %v1)34 %r1 = call i32 @foo(ptr %v1)35 call void @llvm.lifetime.end.p0(ptr %v1)36 %cmp1 = icmp ne i32 %r1, 037 br i1 %cmp1, label %loop1, label %loop238 39loop2:40 call void @llvm.lifetime.start.p0(ptr %v2)41 %r2 = call i32 @foo(ptr %v2)42 call void @llvm.lifetime.end.p0(ptr %v2)43 %cmp2 = icmp ne i32 %r2, 044 br i1 %cmp2, label %loop2, label %exit45 46exit:47 ret void48}49 50declare i32 @foo(ptr)51 52declare void @llvm.lifetime.start.p0(ptr nocapture)53declare void @llvm.lifetime.end.p0(ptr nocapture)54declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg)55