xref: /llvm-project/llvm/test/Analysis/BasicAA/phi-values-usage.ll (revision 1469d82e1cb3edc939d6b93089046edfef0cf36c)
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(ptr)
16declare i32 @__gxx_personality_v0(...)
17declare void @llvm.lifetime.end.p0(i64, ptr nocapture)
18@c = external global ptr, 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(ptr %this, ptr %ptr, i1 %arg) personality ptr @__gxx_personality_v0 {
24entry:
25  %arr = alloca [4 x i8], align 8
26  br i1 %arg, label %then, label %if
27
28if:
29  br label %then
30
31then:
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
39
40invoke:
41  unreachable
42
43lpad:
44  landingpad { ptr, i32 }
45     catch ptr null
46  call void @otherfn(ptr nonnull %arr)
47  unreachable
48}
49
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.
53define void @fn2(i1 %arg) {
54entry:
55  %a = alloca i8, align 1
56  %0 = load ptr, ptr @c, align 1
57  br label %for.cond
58
59for.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
62
63for.body:                                         ; preds = %for.cond
64  store volatile i8 undef, ptr %a, align 1
65  br label %for.cond
66
67for.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
71  ret void
72}
73