• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 -memdep -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=memcpyopt,instcombine -disable-output < %s 2>&1 | FileCheck %s -check-prefixes=NPM
4
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.
7
8; CHECK: Executing Pass 'Phi Values Analysis'
9; CHECK: Executing Pass 'Basic Alias Analysis (stateless AA impl)'
10; CHECK: Executing Pass 'Memory Dependence Analysis'
11; CHECK-MEMCPY: Executing Pass 'MemCpy Optimization'
12; CHECK-MEMCPY-DAG: Freeing Pass 'MemCpy Optimization'
13; CHECK-DAG: Freeing Pass 'Memory Dependence Analysis'
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'
18
19; NPM-DAG: Running analysis: PhiValuesAnalysis
20; NPM-DAG: Running analysis: BasicAA
21; NPM-DAG: Running analysis: MemoryDependenceAnalysis
22; NPM: Running pass: MemCpyOptPass
23; NPM-NOT: Invalidating analysis
24; NPM: Running pass: InstCombinePass
25
26target datalayout = "p:8:8-n8"
27
28declare void @otherfn([4 x i8]*)
29declare i32 @__gxx_personality_v0(...)
30declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
31@c = external global i8*, align 1
32
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
35; results being used.
36define void @fn(i8* %this, i64* %ptr) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
37entry:
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
41
42if:
43  br label %then
44
45then:
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
53
54invoke:
55  unreachable
56
57lpad:
58  landingpad { i8*, i32 }
59     catch i8* null
60  call void @otherfn([4 x i8]* nonnull %arr)
61  unreachable
62}
63
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.
67define void @fn2() {
68entry:
69  %a = alloca i8, align 1
70  %0 = load i8*, i8** @c, align 1
71  %1 = bitcast i8* %0 to i8**
72  br label %for.cond
73
74for.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
77
78for.body:                                         ; preds = %for.cond
79  store volatile i8 undef, i8* %a, align 1
80  br label %for.cond
81
82for.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
86  ret void
87}
88