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