1 ; RUN: opt -debug-pass-manager -aa-pipeline=basic-aa -passes='require<phi-values>,memcpyopt,instcombine' -disable-output < %s 2>&1 | FileCheck %s
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.
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
13 target datalayout = "p:8:8-n8"
15 declare void @otherfn([4 x i8]*)
16 declare i32 @__gxx_personality_v0(...)
17 declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
18 @c = external global i8*, align 1
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
23 define void @fn(i8* %this, i64* %ptr) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
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
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
45 landingpad { i8*, i32 }
47 call void @otherfn([4 x i8]* nonnull %arr)
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.
56 %a = alloca i8, align 1
57 %0 = load i8*, i8** @c, align 1
58 %1 = bitcast i8* %0 to i8**
61 for.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
65 for.body: ; preds = %for.cond
66 store volatile i8 undef, i8* %a, align 1
69 for.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