Johannes Doerfert | 53992c7 | 2020-01-27 22:24:32 -0600 | [diff] [blame] | 1 | ; RUN: opt -S -passes=attributor -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=4 < %s | FileCheck %s |
Stefan Stipanovic | 69ebb02 | 2019-07-22 19:36:27 +0000 | [diff] [blame] | 2 | |
| 3 | ; TEST 1 - negative. |
| 4 | |
| 5 | ; void *G; |
| 6 | ; void *foo(){ |
| 7 | ; void *V = malloc(4); |
| 8 | ; G = V; |
| 9 | ; return V; |
| 10 | ; } |
| 11 | |
| 12 | @G = external global i8* |
| 13 | |
| 14 | ; CHECK: define i8* @foo() |
| 15 | define i8* @foo() { |
| 16 | %1 = tail call noalias i8* @malloc(i64 4) |
| 17 | store i8* %1, i8** @G, align 8 |
| 18 | ret i8* %1 |
| 19 | } |
| 20 | |
| 21 | declare noalias i8* @malloc(i64) |
| 22 | |
| 23 | ; TEST 2 |
| 24 | ; call noalias function in return instruction. |
| 25 | |
| 26 | ; CHECK: define noalias i8* @return_noalias() |
| 27 | define i8* @return_noalias(){ |
| 28 | %1 = tail call noalias i8* @malloc(i64 4) |
| 29 | ret i8* %1 |
| 30 | } |
| 31 | |
Johannes Doerfert | 7516a5e | 2019-09-03 20:37:24 +0000 | [diff] [blame] | 32 | define void @nocapture(i8* %a){ |
| 33 | ret void |
| 34 | } |
| 35 | |
| 36 | ; CHECK: define noalias i8* @return_noalias_looks_like_capture() |
| 37 | define i8* @return_noalias_looks_like_capture(){ |
| 38 | %1 = tail call noalias i8* @malloc(i64 4) |
| 39 | call void @nocapture(i8* %1) |
| 40 | ret i8* %1 |
| 41 | } |
| 42 | |
Stefan Stipanovic | 69ebb02 | 2019-07-22 19:36:27 +0000 | [diff] [blame] | 43 | declare i8* @alias() |
| 44 | |
| 45 | ; TEST 3 |
| 46 | ; CHECK: define i8* @call_alias() |
| 47 | ; CHECK-NOT: noalias |
| 48 | define i8* @call_alias(){ |
| 49 | %1 = tail call i8* @alias() |
| 50 | ret i8* %1 |
| 51 | } |
| 52 | |
| 53 | ; TEST 4 |
| 54 | ; void *baz(); |
| 55 | ; void *foo(int a); |
| 56 | ; |
| 57 | ; void *bar() { |
| 58 | ; foo(0); |
| 59 | ; return baz(); |
| 60 | ; } |
| 61 | ; |
| 62 | ; void *foo(int a) { |
| 63 | ; if (a) |
| 64 | ; bar(); |
| 65 | ; return malloc(4); |
| 66 | ; } |
| 67 | |
| 68 | ; CHECK: define i8* @bar() |
| 69 | define i8* @bar() nounwind uwtable { |
| 70 | %1 = tail call i8* (...) @baz() |
| 71 | ret i8* %1 |
| 72 | } |
| 73 | |
Tim Northover | a009a60 | 2019-08-03 14:28:34 +0000 | [diff] [blame] | 74 | ; CHECK: define noalias i8* @foo1(i32 %0) |
| 75 | define i8* @foo1(i32 %0) nounwind uwtable { |
Stefan Stipanovic | 69ebb02 | 2019-07-22 19:36:27 +0000 | [diff] [blame] | 76 | %2 = icmp eq i32 %0, 0 |
| 77 | br i1 %2, label %5, label %3 |
| 78 | |
| 79 | 3: ; preds = %1 |
| 80 | %4 = tail call i8* (...) @baz() |
| 81 | br label %5 |
| 82 | |
| 83 | 5: ; preds = %1, %3 |
| 84 | %6 = tail call noalias i8* @malloc(i64 4) |
| 85 | ret i8* %6 |
| 86 | } |
| 87 | |
| 88 | declare i8* @baz(...) nounwind uwtable |
| 89 | |
| 90 | ; TEST 5 |
| 91 | |
| 92 | ; Returning global pointer. Should not be noalias. |
Johannes Doerfert | 12cbbab | 2019-08-20 06:15:50 +0000 | [diff] [blame] | 93 | ; CHECK: define nonnull align 8 dereferenceable(8) i8** @getter() |
Stefan Stipanovic | 69ebb02 | 2019-07-22 19:36:27 +0000 | [diff] [blame] | 94 | define i8** @getter() { |
| 95 | ret i8** @G |
| 96 | } |
| 97 | |
| 98 | ; Returning global pointer. Should not be noalias. |
Johannes Doerfert | 12cbbab | 2019-08-20 06:15:50 +0000 | [diff] [blame] | 99 | ; CHECK: define nonnull align 8 dereferenceable(8) i8** @calle1() |
Stefan Stipanovic | 69ebb02 | 2019-07-22 19:36:27 +0000 | [diff] [blame] | 100 | define i8** @calle1(){ |
| 101 | %1 = call i8** @getter() |
| 102 | ret i8** %1 |
| 103 | } |
| 104 | |
| 105 | ; TEST 6 |
| 106 | declare noalias i8* @strdup(i8* nocapture) nounwind |
| 107 | |
| 108 | ; CHECK: define noalias i8* @test6() |
| 109 | define i8* @test6() nounwind uwtable ssp { |
| 110 | %x = alloca [2 x i8], align 1 |
| 111 | %arrayidx = getelementptr inbounds [2 x i8], [2 x i8]* %x, i64 0, i64 0 |
| 112 | store i8 97, i8* %arrayidx, align 1 |
| 113 | %arrayidx1 = getelementptr inbounds [2 x i8], [2 x i8]* %x, i64 0, i64 1 |
| 114 | store i8 0, i8* %arrayidx1, align 1 |
| 115 | %call = call noalias i8* @strdup(i8* %arrayidx) nounwind |
| 116 | ret i8* %call |
| 117 | } |
| 118 | |
| 119 | ; TEST 7 |
| 120 | |
| 121 | ; CHECK: define noalias i8* @test7() |
| 122 | define i8* @test7() nounwind { |
| 123 | entry: |
| 124 | %A = call noalias i8* @malloc(i64 4) nounwind |
| 125 | %tobool = icmp eq i8* %A, null |
| 126 | br i1 %tobool, label %return, label %if.end |
| 127 | |
| 128 | if.end: |
| 129 | store i8 7, i8* %A |
| 130 | br label %return |
| 131 | |
| 132 | return: |
| 133 | %retval.0 = phi i8* [ %A, %if.end ], [ null, %entry ] |
| 134 | ret i8* %retval.0 |
| 135 | } |
| 136 | |
| 137 | ; TEST 8 |
| 138 | |
Tim Northover | a009a60 | 2019-08-03 14:28:34 +0000 | [diff] [blame] | 139 | ; CHECK: define noalias i8* @test8(i32* %0) |
| 140 | define i8* @test8(i32* %0) nounwind uwtable { |
Stefan Stipanovic | 69ebb02 | 2019-07-22 19:36:27 +0000 | [diff] [blame] | 141 | %2 = tail call noalias i8* @malloc(i64 4) |
| 142 | %3 = icmp ne i32* %0, null |
| 143 | br i1 %3, label %4, label %5 |
| 144 | |
| 145 | 4: ; preds = %1 |
| 146 | store i8 10, i8* %2 |
| 147 | br label %5 |
| 148 | |
| 149 | 5: ; preds = %1, %4 |
| 150 | ret i8* %2 |
| 151 | } |
Hideto Ueno | cbab334 | 2019-08-29 05:52:00 +0000 | [diff] [blame] | 152 | |
| 153 | ; TEST 9 |
| 154 | ; Simple Argument Test |
Johannes Doerfert | 53992c7 | 2020-01-27 22:24:32 -0600 | [diff] [blame] | 155 | declare void @use_i8(i8* nocapture) |
Johannes Doerfert | 7513363 | 2019-10-10 01:39:16 -0500 | [diff] [blame] | 156 | define internal void @test9a(i8* %a, i8* %b) { |
| 157 | ; CHECK: define internal void @test9a() |
| 158 | ret void |
| 159 | } |
| 160 | define internal void @test9b(i8* %a, i8* %b) { |
Johannes Doerfert | 53992c7 | 2020-01-27 22:24:32 -0600 | [diff] [blame] | 161 | ; FIXME: %b should be noalias |
| 162 | ; CHECK: define internal void @test9b(i8* noalias nocapture %a, i8* nocapture %b) |
Johannes Doerfert | 7513363 | 2019-10-10 01:39:16 -0500 | [diff] [blame] | 163 | call void @use_i8(i8* %a) |
| 164 | call void @use_i8(i8* %b) |
Hideto Ueno | cbab334 | 2019-08-29 05:52:00 +0000 | [diff] [blame] | 165 | ret void |
| 166 | } |
Johannes Doerfert | 53992c7 | 2020-01-27 22:24:32 -0600 | [diff] [blame] | 167 | define internal void @test9c(i8* %a, i8* %b, i8* %c) { |
| 168 | ; CHECK: define internal void @test9c(i8* noalias nocapture %a, i8* nocapture %b, i8* nocapture %c) |
| 169 | call void @use_i8(i8* %a) |
| 170 | call void @use_i8(i8* %b) |
| 171 | call void @use_i8(i8* %c) |
| 172 | ret void |
| 173 | } |
Hideto Ueno | cbab334 | 2019-08-29 05:52:00 +0000 | [diff] [blame] | 174 | define void @test9_helper(i8* %a, i8* %b) { |
Johannes Doerfert | 53992c7 | 2020-01-27 22:24:32 -0600 | [diff] [blame] | 175 | ; CHECK: define void @test9_helper(i8* nocapture %a, i8* nocapture %b) |
Johannes Doerfert | 7513363 | 2019-10-10 01:39:16 -0500 | [diff] [blame] | 176 | ; CHECK: tail call void @test9a() |
| 177 | ; CHECK: tail call void @test9a() |
Johannes Doerfert | 53992c7 | 2020-01-27 22:24:32 -0600 | [diff] [blame] | 178 | ; CHECK: tail call void @test9b(i8* noalias nocapture %a, i8* nocapture %b) |
| 179 | ; CHECK: tail call void @test9b(i8* noalias nocapture %b, i8* noalias nocapture %a) |
| 180 | ; CHECK: tail call void @test9c(i8* noalias nocapture %a, i8* nocapture %b, i8* nocapture %b) |
| 181 | ; CHECK: tail call void @test9c(i8* noalias nocapture %b, i8* noalias nocapture %a, i8* noalias nocapture %a) |
Johannes Doerfert | 7513363 | 2019-10-10 01:39:16 -0500 | [diff] [blame] | 182 | tail call void @test9a(i8* noalias %a, i8* %b) |
| 183 | tail call void @test9a(i8* noalias %b, i8* noalias %a) |
| 184 | tail call void @test9b(i8* noalias %a, i8* %b) |
| 185 | tail call void @test9b(i8* noalias %b, i8* noalias %a) |
Johannes Doerfert | 53992c7 | 2020-01-27 22:24:32 -0600 | [diff] [blame] | 186 | tail call void @test9c(i8* noalias %a, i8* %b, i8* %b) |
| 187 | tail call void @test9c(i8* noalias %b, i8* noalias %a, i8* noalias %a) |
Hideto Ueno | cbab334 | 2019-08-29 05:52:00 +0000 | [diff] [blame] | 188 | ret void |
| 189 | } |
| 190 | |
| 191 | |
| 192 | ; TEST 10 |
| 193 | ; Simple CallSite Test |
| 194 | |
Hideto Ueno | 6381b14 | 2019-08-30 10:00:32 +0000 | [diff] [blame] | 195 | declare void @test10_helper_1(i8* %a) |
| 196 | define void @test10_helper_2(i8* noalias %a) { |
Johannes Doerfert | cd4aab4 | 2019-10-13 03:08:18 -0500 | [diff] [blame] | 197 | ; CHECK: tail call void @test10_helper_1(i8* %a) |
| 198 | tail call void @test10_helper_1(i8* %a) |
Hideto Ueno | 6381b14 | 2019-08-30 10:00:32 +0000 | [diff] [blame] | 199 | ret void |
| 200 | } |
Hideto Ueno | cbab334 | 2019-08-29 05:52:00 +0000 | [diff] [blame] | 201 | define void @test10(i8* noalias %a) { |
| 202 | ; CHECK: define void @test10(i8* noalias %a) |
| 203 | ; FIXME: missing noalias |
Hideto Ueno | 6381b14 | 2019-08-30 10:00:32 +0000 | [diff] [blame] | 204 | ; CHECK-NEXT: tail call void @test10_helper_1(i8* %a) |
| 205 | tail call void @test10_helper_1(i8* %a) |
| 206 | |
| 207 | ; CHECK-NEXT: tail call void @test10_helper_2(i8* noalias %a) |
| 208 | tail call void @test10_helper_2(i8* %a) |
Hideto Ueno | cbab334 | 2019-08-29 05:52:00 +0000 | [diff] [blame] | 209 | ret void |
| 210 | } |
| 211 | |
| 212 | ; TEST 11 |
| 213 | ; CallSite Test |
| 214 | |
| 215 | declare void @test11_helper(i8* %a, i8 *%b) |
| 216 | define void @test11(i8* noalias %a) { |
| 217 | ; CHECK: define void @test11(i8* noalias %a) |
| 218 | ; CHECK-NEXT: tail call void @test11_helper(i8* %a, i8* %a) |
| 219 | tail call void @test11_helper(i8* %a, i8* %a) |
| 220 | ret void |
| 221 | } |
Hideto Ueno | 1d68ed8 | 2019-09-11 07:00:33 +0000 | [diff] [blame] | 222 | |
| 223 | |
| 224 | ; TEST 12 |
| 225 | ; CallSite Argument |
| 226 | declare void @use_nocapture(i8* nocapture) |
| 227 | declare void @use(i8*) |
| 228 | define void @test12_1() { |
| 229 | ; CHECK-LABEL: @test12_1( |
| 230 | ; CHECK-NEXT: [[A:%.*]] = alloca i8, align 4 |
| 231 | ; CHECK-NEXT: [[B:%.*]] = tail call noalias i8* @malloc(i64 4) |
| 232 | ; CHECK-NEXT: tail call void @use_nocapture(i8* noalias nonnull align 4 dereferenceable(1) [[A]]) |
| 233 | ; CHECK-NEXT: tail call void @use_nocapture(i8* noalias nonnull align 4 dereferenceable(1) [[A]]) |
Hideto Ueno | 30d86f1 | 2019-09-17 06:53:27 +0000 | [diff] [blame] | 234 | ; CHECK-NEXT: tail call void @use_nocapture(i8* noalias nocapture [[B]]) |
Johannes Doerfert | 0be9cf2 | 2019-10-14 17:29:05 -0500 | [diff] [blame] | 235 | ; CHECK-NEXT: tail call void @use_nocapture(i8* noalias nocapture [[B]]) |
Hideto Ueno | 1d68ed8 | 2019-09-11 07:00:33 +0000 | [diff] [blame] | 236 | ; CHECK-NEXT: ret void |
| 237 | ; |
| 238 | %A = alloca i8, align 4 |
| 239 | %B = tail call noalias i8* @malloc(i64 4) |
| 240 | tail call void @use_nocapture(i8* %A) |
| 241 | tail call void @use_nocapture(i8* %A) |
| 242 | tail call void @use_nocapture(i8* %B) |
| 243 | tail call void @use_nocapture(i8* %B) |
| 244 | ret void |
| 245 | } |
| 246 | |
| 247 | define void @test12_2(){ |
| 248 | ; CHECK-LABEL: @test12_2( |
| 249 | ; CHECK-NEXT: [[A:%.*]] = tail call noalias i8* @malloc(i64 4) |
| 250 | ; FIXME: This should be @use_nocapture(i8* noalias [[A]]) |
Hideto Ueno | 30d86f1 | 2019-09-17 06:53:27 +0000 | [diff] [blame] | 251 | ; CHECK-NEXT: tail call void @use_nocapture(i8* nocapture [[A]]) |
Johannes Doerfert | 0be9cf2 | 2019-10-14 17:29:05 -0500 | [diff] [blame] | 252 | ; FIXME: This should be @use_nocapture(i8* noalias nocapture [[A]]) |
| 253 | ; CHECK-NEXT: tail call void @use_nocapture(i8* nocapture [[A]]) |
Hideto Ueno | 1d68ed8 | 2019-09-11 07:00:33 +0000 | [diff] [blame] | 254 | ; CHECK-NEXT: tail call void @use(i8* [[A]]) |
Johannes Doerfert | 0be9cf2 | 2019-10-14 17:29:05 -0500 | [diff] [blame] | 255 | ; CHECK-NEXT: tail call void @use_nocapture(i8* nocapture [[A]]) |
Hideto Ueno | 1d68ed8 | 2019-09-11 07:00:33 +0000 | [diff] [blame] | 256 | ; CHECK-NEXT: ret void |
| 257 | ; |
| 258 | %A = tail call noalias i8* @malloc(i64 4) |
| 259 | tail call void @use_nocapture(i8* %A) |
| 260 | tail call void @use_nocapture(i8* %A) |
| 261 | tail call void @use(i8* %A) |
| 262 | tail call void @use_nocapture(i8* %A) |
| 263 | ret void |
| 264 | } |
| 265 | |
| 266 | declare void @two_args(i8* nocapture , i8* nocapture) |
| 267 | define void @test12_3(){ |
| 268 | ; CHECK-LABEL: @test12_3( |
| 269 | %A = tail call noalias i8* @malloc(i64 4) |
Johannes Doerfert | 0be9cf2 | 2019-10-14 17:29:05 -0500 | [diff] [blame] | 270 | ; CHECK: tail call void @two_args(i8* nocapture %A, i8* nocapture %A) |
Hideto Ueno | 1d68ed8 | 2019-09-11 07:00:33 +0000 | [diff] [blame] | 271 | tail call void @two_args(i8* %A, i8* %A) |
| 272 | ret void |
| 273 | } |
| 274 | |
| 275 | define void @test12_4(){ |
| 276 | ; CHECK-LABEL: @test12_4( |
| 277 | %A = tail call noalias i8* @malloc(i64 4) |
| 278 | %B = tail call noalias i8* @malloc(i64 4) |
| 279 | %A_0 = getelementptr i8, i8* %A, i64 0 |
| 280 | %A_1 = getelementptr i8, i8* %A, i64 1 |
| 281 | %B_0 = getelementptr i8, i8* %B, i64 0 |
| 282 | |
Johannes Doerfert | 0be9cf2 | 2019-10-14 17:29:05 -0500 | [diff] [blame] | 283 | ; CHECK: tail call void @two_args(i8* noalias nocapture %A, i8* noalias nocapture %B) |
Hideto Ueno | 1d68ed8 | 2019-09-11 07:00:33 +0000 | [diff] [blame] | 284 | tail call void @two_args(i8* %A, i8* %B) |
| 285 | |
Johannes Doerfert | 0be9cf2 | 2019-10-14 17:29:05 -0500 | [diff] [blame] | 286 | ; CHECK: tail call void @two_args(i8* nocapture %A, i8* nocapture %A_0) |
Hideto Ueno | 1d68ed8 | 2019-09-11 07:00:33 +0000 | [diff] [blame] | 287 | tail call void @two_args(i8* %A, i8* %A_0) |
| 288 | |
Johannes Doerfert | 0be9cf2 | 2019-10-14 17:29:05 -0500 | [diff] [blame] | 289 | ; CHECK: tail call void @two_args(i8* nocapture %A, i8* nocapture %A_1) |
Hideto Ueno | 1d68ed8 | 2019-09-11 07:00:33 +0000 | [diff] [blame] | 290 | tail call void @two_args(i8* %A, i8* %A_1) |
| 291 | |
Johannes Doerfert | 0be9cf2 | 2019-10-14 17:29:05 -0500 | [diff] [blame] | 292 | ; FIXME: This should be @two_args(i8* noalias nocapture %A_0, i8* noalias nocapture %B_0) |
| 293 | ; CHECK: tail call void @two_args(i8* nocapture %A_0, i8* nocapture %B_0) |
Hideto Ueno | 1d68ed8 | 2019-09-11 07:00:33 +0000 | [diff] [blame] | 294 | tail call void @two_args(i8* %A_0, i8* %B_0) |
| 295 | ret void |
| 296 | } |