1 ; RUN: opt -debug-pass=Executions -phi-values -memcpyopt -instcombine -disable-output < %s -enable-new-pm=0 2>&1 | FileCheck %s -check-prefixes=CHECK,CHECK-MEMCPY
2 ; RUN: opt -debug-pass=Executions -phi-values -memoryssa -instcombine -disable-output < %s -enable-new-pm=0 2>&1 | FileCheck %s -check-prefix=CHECK
3 ; RUN: opt -debug-pass-manager -aa-pipeline=basic-aa -passes='require<phi-values>,memcpyopt,instcombine' -disable-output < %s 2>&1 | FileCheck %s -check-prefixes=NPM
5 ; Check that phi values is not run when it's not already available, and that
6 ; basicaa is not freed after a pass that preserves CFG, as it preserves CFG.
8 ; CHECK: Executing Pass 'Phi Values Analysis'
9 ; CHECK: Executing Pass 'Basic Alias Analysis (stateless AA impl)'
10 ; CHECK: Executing Pass 'Memory SSA'
11 ; CHECK-MEMCPY: Executing Pass 'MemCpy Optimization'
12 ; CHECK-MEMCPY-DAG: Freeing Pass 'MemCpy Optimization'
13 ; CHECK-DAG: Freeing Pass 'Memory SSA'
14 ; CHECK-DAG: Freeing Pass 'Phi Values Analysis'
15 ; CHECK-NOT: Executing Pass 'Phi Values Analysis'
16 ; CHECK-NOT: Executing Pass 'Basic Alias Analysis (stateless AA impl)'
17 ; CHECK: Executing Pass 'Combine redundant instructions'
19 ; NPM-DAG: Running analysis: PhiValuesAnalysis
20 ; NPM-DAG: Running analysis: BasicAA
21 ; NPM-DAG: Running analysis: MemorySSA
22 ; NPM: Running pass: MemCpyOptPass
23 ; NPM-NOT: Invalidating analysis
24 ; NPM: Running pass: InstCombinePass
26 target datalayout = "p:8:8-n8"
28 declare void @otherfn([4 x i8]*)
29 declare i32 @__gxx_personality_v0(...)
30 declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
31 @c = external global i8*, align 1
33 ; This function is one where if we didn't free basicaa after memcpyopt then the
34 ; usage of basicaa in instcombine would cause a segfault due to stale phi-values
36 define void @fn(i8* %this, i64* %ptr) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
38 %arr = alloca [4 x i8], align 8
39 %gep1 = getelementptr inbounds [4 x i8], [4 x i8]* %arr, i64 0, i32 0
40 br i1 undef, label %then, label %if
46 %phi = phi i64* [ %ptr, %if ], [ null, %entry ]
47 store i8 1, i8* %gep1, align 8
48 %load = load i64, i64* %phi, align 8
49 %gep2 = getelementptr inbounds i8, i8* undef, i64 %load
50 %gep3 = getelementptr inbounds i8, i8* %gep2, i64 40
51 invoke i32 undef(i8* undef)
52 to label %invoke unwind label %lpad
58 landingpad { i8*, i32 }
60 call void @otherfn([4 x i8]* nonnull %arr)
64 ; When running instcombine after memdep, the basicaa used by instcombine uses
65 ; the phivalues that memdep used. This would then cause a segfault due to
66 ; instcombine deleting a phi whose values had been cached.
69 %a = alloca i8, align 1
70 %0 = load i8*, i8** @c, align 1
71 %1 = bitcast i8* %0 to i8**
74 for.cond: ; preds = %for.body, %entry
75 %d.0 = phi i8** [ %1, %entry ], [ null, %for.body ]
76 br i1 undef, label %for.body, label %for.cond.cleanup
78 for.body: ; preds = %for.cond
79 store volatile i8 undef, i8* %a, align 1
82 for.cond.cleanup: ; preds = %for.cond
83 call void @llvm.lifetime.end.p0i8(i64 1, i8* %a)
84 %2 = load i8*, i8** %d.0, align 1
85 store i8* %2, i8** @c, align 1