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(ptr)
16 declare i32 @__gxx_personality_v0(...)
17 declare void @llvm.lifetime.end.p0(i64, ptr nocapture)
18 @c = external global ptr, 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(ptr %this, ptr %ptr, i1 %arg) personality ptr @__gxx_personality_v0 {
25 %arr = alloca [4 x i8], align 8
26 br i1 %arg, label %then, label %if
32 %phi = phi ptr [ %ptr, %if ], [ null, %entry ]
33 store i8 1, ptr %arr, align 8
34 %load = load i64, ptr %phi, align 8
35 %gep2 = getelementptr inbounds i8, ptr undef, i64 %load
36 %gep3 = getelementptr inbounds i8, ptr %gep2, i64 40
37 invoke i32 undef(ptr undef)
38 to label %invoke unwind label %lpad
44 landingpad { ptr, i32 }
46 call void @otherfn(ptr nonnull %arr)
50 ; When running instcombine after memdep, the basicaa used by instcombine uses
51 ; the phivalues that memdep used. This would then cause a segfault due to
52 ; instcombine deleting a phi whose values had been cached.
53 define void @fn2(i1 %arg) {
55 %a = alloca i8, align 1
56 %0 = load ptr, ptr @c, align 1
59 for.cond: ; preds = %for.body, %entry
60 %d.0 = phi ptr [ %0, %entry ], [ null, %for.body ]
61 br i1 %arg, label %for.body, label %for.cond.cleanup
63 for.body: ; preds = %for.cond
64 store volatile i8 undef, ptr %a, align 1
67 for.cond.cleanup: ; preds = %for.cond
68 call void @llvm.lifetime.end.p0(i64 1, ptr %a)
69 %1 = load ptr, ptr %d.0, align 1
70 store ptr %1, ptr @c, align 1