1; REQUIRES: aarch64-registered-target
2; REQUIRES: shell
3
4; Test IPA over a single combined file
5; RUN: llvm-as %s -o %t0.bc
6; RUN: llvm-as %S/Inputs/ipa-alias.ll -o %t1.bc
7; RUN: llvm-link %t0.bc %t1.bc -o %t.combined.bc
8
9; RUN: opt -S -analyze -stack-safety-local %t.combined.bc -enable-new-pm=0 | FileCheck %s --check-prefixes=CHECK,LOCAL
10; RUN: opt -S -passes="print<stack-safety-local>" -disable-output %t.combined.bc 2>&1 | FileCheck %s --check-prefixes=CHECK,LOCAL
11
12; RUN: opt -S -analyze -stack-safety %t.combined.bc -enable-new-pm=0 | FileCheck %s --check-prefixes=CHECK,GLOBAL,NOLTO
13; RUN: opt -S -passes="print-stack-safety" -disable-output %t.combined.bc 2>&1 | FileCheck %s --check-prefixes=CHECK,GLOBAL,NOLTO
14
15; Do an end-to-test using the new LTO API
16; RUN: opt -module-summary %s -o %t.summ0.bc
17; RUN: opt -module-summary %S/Inputs/ipa-alias.ll -o %t.summ1.bc
18
19; RUN: echo > %t.res.txt \
20; RUN:  -r %t.summ0.bc,AliasCall,px \
21; RUN:  -r %t.summ0.bc,AliasToBitcastAliasWrite1, \
22; RUN:  -r %t.summ0.bc,AliasToPreemptableAliasWrite1, \
23; RUN:  -r %t.summ0.bc,AliasWrite1, \
24; RUN:  -r %t.summ0.bc,BitcastAliasCall,px \
25; RUN:  -r %t.summ0.bc,BitcastAliasWrite1, \
26; RUN:  -r %t.summ0.bc,InterposableAliasCall,px \
27; RUN:  -r %t.summ0.bc,InterposableAliasWrite1, \
28; RUN:  -r %t.summ0.bc,PreemptableAliasCall,px \
29; RUN:  -r %t.summ0.bc,PreemptableAliasWrite1, \
30; RUN:  -r %t.summ1.bc,AliasToBitcastAliasWrite1,px \
31; RUN:  -r %t.summ1.bc,AliasToPreemptableAliasWrite1,px \
32; RUN:  -r %t.summ1.bc,AliasWrite1,px \
33; RUN:  -r %t.summ1.bc,BitcastAliasWrite1,px \
34; RUN:  -r %t.summ1.bc,InterposableAliasWrite1,px \
35; RUN:  -r %t.summ1.bc,PreemptableAliasWrite1,px \
36; RUN:  -r %t.summ1.bc,Write1,px
37
38; RUN: llvm-lto2 run %t.summ0.bc %t.summ1.bc -o %t.lto -stack-safety-print -stack-safety-run -save-temps -thinlto-threads 1 -O0 \
39; RUN:  $(cat %t.res.txt) \
40; RUN:    2>&1 | FileCheck %s --check-prefixes=CHECK,GLOBAL,LTO
41
42; RUN: llvm-lto2 run %t.summ0.bc %t.summ1.bc -o %t-newpm.lto -stack-safety-print -stack-safety-run -save-temps -use-new-pm -thinlto-threads 1 -O0 \
43; RUN:  $(cat %t.res.txt) \
44; RUN:    2>&1 | FileCheck %s --check-prefixes=CHECK,GLOBAL,LTO
45
46target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
47target triple = "aarch64-unknown-linux"
48
49attributes #0 = { noinline sanitize_memtag "target-features"="+mte,+neon" }
50
51declare void @PreemptableAliasWrite1(i8* %p)
52declare void @AliasToPreemptableAliasWrite1(i8* %p)
53
54declare void @InterposableAliasWrite1(i8* %p)
55; Aliases to interposable aliases are not allowed
56
57declare void @AliasWrite1(i8* %p)
58
59declare void @BitcastAliasWrite1(i32* %p)
60declare void @AliasToBitcastAliasWrite1(i8* %p)
61
62; Call to dso_preemptable alias to a dso_local aliasee
63define void @PreemptableAliasCall() #0 {
64; CHECK-LABEL: @PreemptableAliasCall dso_preemptable{{$}}
65; CHECK-NEXT: args uses:
66; CHECK-NEXT: allocas uses:
67; LOCAL-NEXT: x1[1]: empty-set, @PreemptableAliasWrite1(arg0, [0,1)){{$}}
68; GLOBAL-NEXT: x1[1]: full-set, @PreemptableAliasWrite1(arg0, [0,1)){{$}}
69; LOCAL-NEXT: x2[1]: empty-set, @AliasToPreemptableAliasWrite1(arg0, [0,1)){{$}}
70; GLOBAL-NEXT: x2[1]: [0,1), @AliasToPreemptableAliasWrite1(arg0, [0,1)){{$}}
71; CHECK-EMPTY:
72entry:
73  %x1 = alloca i8
74  call void @PreemptableAliasWrite1(i8* %x1)
75
76  %x2 = alloca i8
77; Alias to a preemptable alias is not preemptable
78  call void @AliasToPreemptableAliasWrite1(i8* %x2)
79  ret void
80}
81
82; Call to an interposable alias to a non-interposable aliasee
83define void @InterposableAliasCall() #0 {
84; CHECK-LABEL: @InterposableAliasCall dso_preemptable{{$}}
85; CHECK-NEXT: args uses:
86; CHECK-NEXT: allocas uses:
87; LOCAL-NEXT: x[1]: empty-set, @InterposableAliasWrite1(arg0, [0,1)){{$}}
88; NOLTO-NEXT: x[1]: full-set, @InterposableAliasWrite1(arg0, [0,1)){{$}}
89; LTO-NEXT: x[1]: [0,1), @InterposableAliasWrite1(arg0, [0,1)){{$}}
90; CHECK-EMPTY:
91entry:
92  %x = alloca i8
93; ThinLTO can resolve the prevailing implementation for interposable definitions.
94  call void @InterposableAliasWrite1(i8* %x)
95  ret void
96}
97
98; Call to a dso_local/non-interposable alias/aliasee
99define void @AliasCall() #0 {
100; CHECK-LABEL: @AliasCall dso_preemptable{{$}}
101; CHECK-NEXT: args uses:
102; CHECK-NEXT: allocas uses:
103; LOCAL-NEXT: x[1]: empty-set, @AliasWrite1(arg0, [0,1)){{$}}
104; GLOBAL-NEXT: x[1]: [0,1), @AliasWrite1(arg0, [0,1)){{$}}
105; CHECK-EMPTY:
106entry:
107  %x = alloca i8
108  call void @AliasWrite1(i8* %x)
109  ret void
110}
111
112; Call to a bitcasted dso_local/non-interposable alias/aliasee
113define void @BitcastAliasCall() #0 {
114; CHECK-LABEL: @BitcastAliasCall dso_preemptable{{$}}
115; CHECK-NEXT: args uses:
116; CHECK-NEXT: allocas uses:
117; LOCAL-NEXT: x1[4]: empty-set, @BitcastAliasWrite1(arg0, [0,1)){{$}}
118; GLOBAL-NEXT: x1[4]: [0,1), @BitcastAliasWrite1(arg0, [0,1)){{$}}
119; LOCAL-NEXT: x2[1]: empty-set, @AliasToBitcastAliasWrite1(arg0, [0,1)){{$}}
120; GLOBAL-NEXT: x2[1]: [0,1), @AliasToBitcastAliasWrite1(arg0, [0,1)){{$}}
121; CHECK-EMPTY:
122entry:
123  %x1 = alloca i32
124  call void @BitcastAliasWrite1(i32* %x1)
125  %x2 = alloca i8
126  call void @AliasToBitcastAliasWrite1(i8* %x2)
127  ret void
128}
129
130; The rest is from Inputs/ipa-alias.ll
131
132; CHECK-LABEL: @Write1{{$}}
133; CHECK-NEXT: args uses:
134; CHECK-NEXT: p[]: [0,1){{$}}
135; CHECK-NEXT: allocas uses:
136; CHECK-EMPTY:
137