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