1; RUN: opt -debug-pass=Executions -phi-values -memcpyopt -instcombine -disable-output < %s 2>&1 | FileCheck %s -check-prefixes=CHECK,CHECK-MEMCPY 2; RUN: opt -debug-pass=Executions -memdep -instcombine -disable-output < %s 2>&1 | FileCheck %s -check-prefix=CHECK 3 4; Check that phi values is not run when it's not already available, and that 5; basicaa is not freed after a pass that preserves CFG, as it preserves CFG. 6 7; CHECK: Executing Pass 'Phi Values Analysis' 8; CHECK: Executing Pass 'Basic Alias Analysis (stateless AA impl)' 9; CHECK: Executing Pass 'Memory Dependence Analysis' 10; CHECK-MEMCPY: Executing Pass 'MemCpy Optimization' 11; CHECK-MEMCPY-DAG: Freeing Pass 'MemCpy Optimization' 12; CHECK-DAG: Freeing Pass 'Memory Dependence Analysis' 13; CHECK-DAG: Freeing Pass 'Phi Values Analysis' 14; CHECK-NOT: Executing Pass 'Phi Values Analysis' 15; CHECK-NOT: Executing Pass 'Basic Alias Analysis (stateless AA impl)' 16; CHECK: Executing Pass 'Combine redundant instructions' 17 18target datalayout = "p:8:8-n8" 19 20declare void @otherfn([4 x i8]*) 21declare i32 @__gxx_personality_v0(...) 22declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) 23@c = external global i8*, align 1 24 25; This function is one where if we didn't free basicaa after memcpyopt then the 26; usage of basicaa in instcombine would cause a segfault due to stale phi-values 27; results being used. 28define void @fn(i8* %this, i64* %ptr) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { 29entry: 30 %arr = alloca [4 x i8], align 8 31 %gep1 = getelementptr inbounds [4 x i8], [4 x i8]* %arr, i64 0, i32 0 32 br i1 undef, label %then, label %if 33 34if: 35 br label %then 36 37then: 38 %phi = phi i64* [ %ptr, %if ], [ null, %entry ] 39 store i8 1, i8* %gep1, align 8 40 %load = load i64, i64* %phi, align 8 41 %gep2 = getelementptr inbounds i8, i8* undef, i64 %load 42 %gep3 = getelementptr inbounds i8, i8* %gep2, i64 40 43 invoke i32 undef(i8* undef) 44 to label %invoke unwind label %lpad 45 46invoke: 47 unreachable 48 49lpad: 50 landingpad { i8*, i32 } 51 catch i8* null 52 call void @otherfn([4 x i8]* nonnull %arr) 53 unreachable 54} 55 56; When running instcombine after memdep, the basicaa used by instcombine uses 57; the phivalues that memdep used. This would then cause a segfault due to 58; instcombine deleting a phi whose values had been cached. 59define void @fn2() { 60entry: 61 %a = alloca i8, align 1 62 %0 = load i8*, i8** @c, align 1 63 %1 = bitcast i8* %0 to i8** 64 br label %for.cond 65 66for.cond: ; preds = %for.body, %entry 67 %d.0 = phi i8** [ %1, %entry ], [ null, %for.body ] 68 br i1 undef, label %for.body, label %for.cond.cleanup 69 70for.body: ; preds = %for.cond 71 store volatile i8 undef, i8* %a, align 1 72 br label %for.cond 73 74for.cond.cleanup: ; preds = %for.cond 75 call void @llvm.lifetime.end.p0i8(i64 1, i8* %a) 76 %2 = load i8*, i8** %d.0, align 1 77 store i8* %2, i8** @c, align 1 78 ret void 79} 80