1 ; RUN: llc -mcpu=corei7 -no-stack-coloring=false < %s | FileCheck %s --check-prefix=YESCOLOR 2 ; RUN: llc -mcpu=corei7 -no-stack-coloring=true < %s | FileCheck %s --check-prefix=NOCOLOR 3 4 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" 5 target triple = "x86_64-apple-macosx10.8.0" 6 7 ;YESCOLOR: subq $144, %rsp 8 ;NOCOLOR: subq $272, %rsp 9 10 define i32 @myCall_w2(i32 %in) { 11 entry: 12 %a = alloca [17 x i8*], align 8 13 %a2 = alloca [16 x i8*], align 8 14 %b = bitcast [17 x i8*]* %a to i8* 15 %b2 = bitcast [16 x i8*]* %a2 to i8* 16 call void @llvm.lifetime.start(i64 -1, i8* %b) 17 %t1 = call i32 @foo(i32 %in, i8* %b) 18 %t2 = call i32 @foo(i32 %in, i8* %b) 19 call void @llvm.lifetime.end(i64 -1, i8* %b) 20 call void @llvm.lifetime.start(i64 -1, i8* %b2) 21 %t3 = call i32 @foo(i32 %in, i8* %b2) 22 %t4 = call i32 @foo(i32 %in, i8* %b2) 23 call void @llvm.lifetime.end(i64 -1, i8* %b2) 24 %t5 = add i32 %t1, %t2 25 %t6 = add i32 %t3, %t4 26 %t7 = add i32 %t5, %t6 27 ret i32 %t7 28 } 29 30 31 ;YESCOLOR: subq $272, %rsp 32 ;NOCOLOR: subq $272, %rsp 33 34 define i32 @myCall2_no_merge(i32 %in, i1 %d) { 35 entry: 36 %a = alloca [17 x i8*], align 8 37 %a2 = alloca [16 x i8*], align 8 38 %b = bitcast [17 x i8*]* %a to i8* 39 %b2 = bitcast [16 x i8*]* %a2 to i8* 40 call void @llvm.lifetime.start(i64 -1, i8* %b) 41 %t1 = call i32 @foo(i32 %in, i8* %b) 42 %t2 = call i32 @foo(i32 %in, i8* %b) 43 br i1 %d, label %bb2, label %bb3 44 bb2: 45 call void @llvm.lifetime.start(i64 -1, i8* %b2) 46 %t3 = call i32 @foo(i32 %in, i8* %b2) 47 %t4 = call i32 @foo(i32 %in, i8* %b2) 48 call void @llvm.lifetime.end(i64 -1, i8* %b2) 49 %t5 = add i32 %t1, %t2 50 %t6 = add i32 %t3, %t4 51 %t7 = add i32 %t5, %t6 52 call void @llvm.lifetime.end(i64 -1, i8* %b) 53 ret i32 %t7 54 bb3: 55 call void @llvm.lifetime.end(i64 -1, i8* %b) 56 ret i32 0 57 } 58 59 ;YESCOLOR: subq $144, %rsp 60 ;NOCOLOR: subq $272, %rsp 61 62 define i32 @myCall2_w2(i32 %in, i1 %d) { 63 entry: 64 %a = alloca [17 x i8*], align 8 65 %a2 = alloca [16 x i8*], align 8 66 %b = bitcast [17 x i8*]* %a to i8* 67 %b2 = bitcast [16 x i8*]* %a2 to i8* 68 call void @llvm.lifetime.start(i64 -1, i8* %b) 69 %t1 = call i32 @foo(i32 %in, i8* %b) 70 %t2 = call i32 @foo(i32 %in, i8* %b) 71 call void @llvm.lifetime.end(i64 -1, i8* %b) 72 br i1 %d, label %bb2, label %bb3 73 bb2: 74 call void @llvm.lifetime.start(i64 -1, i8* %b2) 75 %t3 = call i32 @foo(i32 %in, i8* %b2) 76 %t4 = call i32 @foo(i32 %in, i8* %b2) 77 call void @llvm.lifetime.end(i64 -1, i8* %b2) 78 %t5 = add i32 %t1, %t2 79 %t6 = add i32 %t3, %t4 80 %t7 = add i32 %t5, %t6 81 ret i32 %t7 82 bb3: 83 ret i32 0 84 } 85 ;YESCOLOR: subq $200, %rsp 86 ;NOCOLOR: subq $408, %rsp 87 88 89 90 91 define i32 @myCall_w4(i32 %in) { 92 entry: 93 %a1 = alloca [14 x i8*], align 8 94 %a2 = alloca [13 x i8*], align 8 95 %a3 = alloca [12 x i8*], align 8 96 %a4 = alloca [11 x i8*], align 8 97 %b1 = bitcast [14 x i8*]* %a1 to i8* 98 %b2 = bitcast [13 x i8*]* %a2 to i8* 99 %b3 = bitcast [12 x i8*]* %a3 to i8* 100 %b4 = bitcast [11 x i8*]* %a4 to i8* 101 call void @llvm.lifetime.start(i64 -1, i8* %b4) 102 call void @llvm.lifetime.start(i64 -1, i8* %b1) 103 %t1 = call i32 @foo(i32 %in, i8* %b1) 104 %t2 = call i32 @foo(i32 %in, i8* %b1) 105 call void @llvm.lifetime.end(i64 -1, i8* %b1) 106 call void @llvm.lifetime.start(i64 -1, i8* %b2) 107 %t9 = call i32 @foo(i32 %in, i8* %b2) 108 %t8 = call i32 @foo(i32 %in, i8* %b2) 109 call void @llvm.lifetime.end(i64 -1, i8* %b2) 110 call void @llvm.lifetime.start(i64 -1, i8* %b3) 111 %t3 = call i32 @foo(i32 %in, i8* %b3) 112 %t4 = call i32 @foo(i32 %in, i8* %b3) 113 call void @llvm.lifetime.end(i64 -1, i8* %b3) 114 %t11 = call i32 @foo(i32 %in, i8* %b4) 115 call void @llvm.lifetime.end(i64 -1, i8* %b4) 116 %t5 = add i32 %t1, %t2 117 %t6 = add i32 %t3, %t4 118 %t7 = add i32 %t5, %t6 119 ret i32 %t7 120 } 121 122 ;YESCOLOR: subq $112, %rsp 123 ;NOCOLOR: subq $400, %rsp 124 125 define i32 @myCall2_w4(i32 %in) { 126 entry: 127 %a1 = alloca [14 x i8*], align 8 128 %a2 = alloca [13 x i8*], align 8 129 %a3 = alloca [12 x i8*], align 8 130 %a4 = alloca [11 x i8*], align 8 131 %b1 = bitcast [14 x i8*]* %a1 to i8* 132 %b2 = bitcast [13 x i8*]* %a2 to i8* 133 %b3 = bitcast [12 x i8*]* %a3 to i8* 134 %b4 = bitcast [11 x i8*]* %a4 to i8* 135 call void @llvm.lifetime.start(i64 -1, i8* %b1) 136 %t1 = call i32 @foo(i32 %in, i8* %b1) 137 %t2 = call i32 @foo(i32 %in, i8* %b1) 138 call void @llvm.lifetime.end(i64 -1, i8* %b1) 139 call void @llvm.lifetime.start(i64 -1, i8* %b2) 140 %t9 = call i32 @foo(i32 %in, i8* %b2) 141 %t8 = call i32 @foo(i32 %in, i8* %b2) 142 call void @llvm.lifetime.end(i64 -1, i8* %b2) 143 call void @llvm.lifetime.start(i64 -1, i8* %b3) 144 %t3 = call i32 @foo(i32 %in, i8* %b3) 145 %t4 = call i32 @foo(i32 %in, i8* %b3) 146 call void @llvm.lifetime.end(i64 -1, i8* %b3) 147 br i1 undef, label %bb2, label %bb3 148 bb2: 149 call void @llvm.lifetime.start(i64 -1, i8* %b4) 150 %t11 = call i32 @foo(i32 %in, i8* %b4) 151 call void @llvm.lifetime.end(i64 -1, i8* %b4) 152 %t5 = add i32 %t1, %t2 153 %t6 = add i32 %t3, %t4 154 %t7 = add i32 %t5, %t6 155 ret i32 %t7 156 bb3: 157 ret i32 0 158 } 159 160 161 ;YESCOLOR: subq $144, %rsp 162 ;NOCOLOR: subq $272, %rsp 163 164 165 define i32 @myCall2_noend(i32 %in, i1 %d) { 166 entry: 167 %a = alloca [17 x i8*], align 8 168 %a2 = alloca [16 x i8*], align 8 169 %b = bitcast [17 x i8*]* %a to i8* 170 %b2 = bitcast [16 x i8*]* %a2 to i8* 171 call void @llvm.lifetime.start(i64 -1, i8* %b) 172 %t1 = call i32 @foo(i32 %in, i8* %b) 173 %t2 = call i32 @foo(i32 %in, i8* %b) 174 call void @llvm.lifetime.end(i64 -1, i8* %b) 175 br i1 %d, label %bb2, label %bb3 176 bb2: 177 call void @llvm.lifetime.start(i64 -1, i8* %b2) 178 %t3 = call i32 @foo(i32 %in, i8* %b2) 179 %t4 = call i32 @foo(i32 %in, i8* %b2) 180 %t5 = add i32 %t1, %t2 181 %t6 = add i32 %t3, %t4 182 %t7 = add i32 %t5, %t6 183 ret i32 %t7 184 bb3: 185 ret i32 0 186 } 187 188 ;YESCOLOR: subq $144, %rsp 189 ;NOCOLOR: subq $272, %rsp 190 define i32 @myCall2_noend2(i32 %in, i1 %d) { 191 entry: 192 %a = alloca [17 x i8*], align 8 193 %a2 = alloca [16 x i8*], align 8 194 %b = bitcast [17 x i8*]* %a to i8* 195 %b2 = bitcast [16 x i8*]* %a2 to i8* 196 call void @llvm.lifetime.start(i64 -1, i8* %b) 197 %t1 = call i32 @foo(i32 %in, i8* %b) 198 %t2 = call i32 @foo(i32 %in, i8* %b) 199 br i1 %d, label %bb2, label %bb3 200 bb2: 201 call void @llvm.lifetime.end(i64 -1, i8* %b) 202 call void @llvm.lifetime.start(i64 -1, i8* %b2) 203 %t3 = call i32 @foo(i32 %in, i8* %b2) 204 %t4 = call i32 @foo(i32 %in, i8* %b2) 205 %t5 = add i32 %t1, %t2 206 %t6 = add i32 %t3, %t4 207 %t7 = add i32 %t5, %t6 208 ret i32 %t7 209 bb3: 210 ret i32 0 211 } 212 213 214 ;YESCOLOR: subq $144, %rsp 215 ;NOCOLOR: subq $272, %rsp 216 define i32 @myCall2_nostart(i32 %in, i1 %d) { 217 entry: 218 %a = alloca [17 x i8*], align 8 219 %a2 = alloca [16 x i8*], align 8 220 %b = bitcast [17 x i8*]* %a to i8* 221 %b2 = bitcast [16 x i8*]* %a2 to i8* 222 %t1 = call i32 @foo(i32 %in, i8* %b) 223 %t2 = call i32 @foo(i32 %in, i8* %b) 224 call void @llvm.lifetime.end(i64 -1, i8* %b) 225 br i1 %d, label %bb2, label %bb3 226 bb2: 227 call void @llvm.lifetime.start(i64 -1, i8* %b2) 228 %t3 = call i32 @foo(i32 %in, i8* %b2) 229 %t4 = call i32 @foo(i32 %in, i8* %b2) 230 %t5 = add i32 %t1, %t2 231 %t6 = add i32 %t3, %t4 232 %t7 = add i32 %t5, %t6 233 ret i32 %t7 234 bb3: 235 ret i32 0 236 } 237 238 ; Adopt the test from Transforms/Inline/array_merge.ll' 239 ;YESCOLOR: subq $816, %rsp 240 ;NOCOLOR: subq $1616, %rsp 241 define void @array_merge() nounwind ssp { 242 entry: 243 %A.i1 = alloca [100 x i32], align 4 244 %B.i2 = alloca [100 x i32], align 4 245 %A.i = alloca [100 x i32], align 4 246 %B.i = alloca [100 x i32], align 4 247 %0 = bitcast [100 x i32]* %A.i to i8* 248 call void @llvm.lifetime.start(i64 -1, i8* %0) nounwind 249 %1 = bitcast [100 x i32]* %B.i to i8* 250 call void @llvm.lifetime.start(i64 -1, i8* %1) nounwind 251 call void @bar([100 x i32]* %A.i, [100 x i32]* %B.i) nounwind 252 call void @llvm.lifetime.end(i64 -1, i8* %0) nounwind 253 call void @llvm.lifetime.end(i64 -1, i8* %1) nounwind 254 %2 = bitcast [100 x i32]* %A.i1 to i8* 255 call void @llvm.lifetime.start(i64 -1, i8* %2) nounwind 256 %3 = bitcast [100 x i32]* %B.i2 to i8* 257 call void @llvm.lifetime.start(i64 -1, i8* %3) nounwind 258 call void @bar([100 x i32]* %A.i1, [100 x i32]* %B.i2) nounwind 259 call void @llvm.lifetime.end(i64 -1, i8* %2) nounwind 260 call void @llvm.lifetime.end(i64 -1, i8* %3) nounwind 261 ret void 262 } 263 264 ;YESCOLOR: subq $272, %rsp 265 ;NOCOLOR: subq $272, %rsp 266 define i32 @func_phi_lifetime(i32 %in, i1 %d) { 267 entry: 268 %a = alloca [17 x i8*], align 8 269 %a2 = alloca [16 x i8*], align 8 270 %b = bitcast [17 x i8*]* %a to i8* 271 %b2 = bitcast [16 x i8*]* %a2 to i8* 272 %t1 = call i32 @foo(i32 %in, i8* %b) 273 %t2 = call i32 @foo(i32 %in, i8* %b) 274 call void @llvm.lifetime.end(i64 -1, i8* %b) 275 br i1 %d, label %bb0, label %bb1 276 277 bb0: 278 %I1 = bitcast [17 x i8*]* %a to i8* 279 br label %bb2 280 281 bb1: 282 %I2 = bitcast [16 x i8*]* %a2 to i8* 283 br label %bb2 284 285 bb2: 286 %split = phi i8* [ %I1, %bb0 ], [ %I2, %bb1 ] 287 call void @llvm.lifetime.start(i64 -1, i8* %split) 288 %t3 = call i32 @foo(i32 %in, i8* %b2) 289 %t4 = call i32 @foo(i32 %in, i8* %b2) 290 %t5 = add i32 %t1, %t2 291 %t6 = add i32 %t3, %t4 292 %t7 = add i32 %t5, %t6 293 call void @llvm.lifetime.end(i64 -1, i8* %split) 294 ret i32 %t7 295 bb3: 296 ret i32 0 297 } 298 299 300 ;YESCOLOR-LABEL: multi_region_bb: 301 ;NOCOLOR-LABEL: multi_region_bb: 302 define void @multi_region_bb() nounwind ssp { 303 entry: 304 %A.i1 = alloca [100 x i32], align 4 305 %B.i2 = alloca [100 x i32], align 4 306 %A.i = alloca [100 x i32], align 4 307 %B.i = alloca [100 x i32], align 4 308 %0 = bitcast [100 x i32]* %A.i to i8* 309 call void @llvm.lifetime.start(i64 -1, i8* %0) nounwind ; <---- start #1 310 %1 = bitcast [100 x i32]* %B.i to i8* 311 call void @llvm.lifetime.start(i64 -1, i8* %1) nounwind 312 call void @bar([100 x i32]* %A.i, [100 x i32]* %B.i) nounwind 313 call void @llvm.lifetime.end(i64 -1, i8* %0) nounwind 314 call void @llvm.lifetime.end(i64 -1, i8* %1) nounwind 315 %2 = bitcast [100 x i32]* %A.i1 to i8* 316 call void @llvm.lifetime.start(i64 -1, i8* %2) nounwind 317 %3 = bitcast [100 x i32]* %B.i2 to i8* 318 call void @llvm.lifetime.start(i64 -1, i8* %3) nounwind 319 call void @llvm.lifetime.start(i64 -1, i8* %0) nounwind ; <---- start #2 320 call void @bar([100 x i32]* %A.i1, [100 x i32]* %B.i2) nounwind 321 call void @llvm.lifetime.end(i64 -1, i8* %2) nounwind 322 call void @llvm.lifetime.end(i64 -1, i8* %0) nounwind 323 call void @llvm.lifetime.end(i64 -1, i8* %3) nounwind 324 ret void 325 } 326 327 328 ;YESCOLOR: subq $272, %rsp 329 ;NOCOLOR: subq $272, %rsp 330 define i32 @myCall_end_before_begin(i32 %in, i1 %d) { 331 entry: 332 %a = alloca [17 x i8*], align 8 333 %a2 = alloca [16 x i8*], align 8 334 %b = bitcast [17 x i8*]* %a to i8* 335 %b2 = bitcast [16 x i8*]* %a2 to i8* 336 %t1 = call i32 @foo(i32 %in, i8* %b) 337 %t2 = call i32 @foo(i32 %in, i8* %b) 338 call void @llvm.lifetime.end(i64 -1, i8* %b) 339 call void @llvm.lifetime.start(i64 -1, i8* %b) 340 br i1 %d, label %bb2, label %bb3 341 bb2: 342 call void @llvm.lifetime.start(i64 -1, i8* %b2) 343 %t3 = call i32 @foo(i32 %in, i8* %b2) 344 %t4 = call i32 @foo(i32 %in, i8* %b2) 345 %t5 = add i32 %t1, %t2 346 %t6 = add i32 %t3, %t4 347 %t7 = add i32 %t5, %t6 348 ret i32 %t7 349 bb3: 350 ret i32 0 351 } 352 353 354 ; Regression test for PR15707. %buf1 and %buf2 should not be merged 355 ; in this test case. 356 ;YESCOLOR-LABEL: myCall_pr15707: 357 ;YESCOLOR: subq $200008, %rsp 358 ;NOCOLOR-LABEL: myCall_pr15707: 359 ;NOCOLOR: subq $200008, %rsp 360 define void @myCall_pr15707() { 361 %buf1 = alloca i8, i32 100000, align 16 362 %buf2 = alloca i8, i32 100000, align 16 363 364 call void @llvm.lifetime.start(i64 -1, i8* %buf1) 365 call void @llvm.lifetime.end(i64 -1, i8* %buf1) 366 367 call void @llvm.lifetime.start(i64 -1, i8* %buf1) 368 call void @llvm.lifetime.start(i64 -1, i8* %buf2) 369 %result1 = call i32 @foo(i32 0, i8* %buf1) 370 %result2 = call i32 @foo(i32 0, i8* %buf2) 371 ret void 372 } 373 374 375 ; Check that we don't assert and crash even when there are allocas 376 ; outside the declared lifetime regions. 377 ;YESCOLOR-LABEL: bad_range: 378 ;NOCOLOR-LABEL: bad_range: 379 define void @bad_range() nounwind ssp { 380 entry: 381 %A.i1 = alloca [100 x i32], align 4 382 %B.i2 = alloca [100 x i32], align 4 383 %A.i = alloca [100 x i32], align 4 384 %B.i = alloca [100 x i32], align 4 385 %0 = bitcast [100 x i32]* %A.i to i8* 386 call void @llvm.lifetime.start(i64 -1, i8* %0) nounwind 387 %1 = bitcast [100 x i32]* %B.i to i8* 388 call void @llvm.lifetime.start(i64 -1, i8* %1) nounwind 389 call void @bar([100 x i32]* %A.i, [100 x i32]* %B.i) nounwind 390 call void @llvm.lifetime.end(i64 -1, i8* %0) nounwind 391 call void @llvm.lifetime.end(i64 -1, i8* %1) nounwind 392 br label %block2 393 394 block2: 395 ; I am used outside the marked lifetime. 396 call void @bar([100 x i32]* %A.i, [100 x i32]* %B.i) nounwind 397 ret void 398 } 399 400 401 ; Check that we don't assert and crash even when there are usages 402 ; of allocas which do not read or write outside the declared lifetime regions. 403 ;YESCOLOR-LABEL: shady_range: 404 ;NOCOLOR-LABEL: shady_range: 405 406 %struct.Klass = type { i32, i32 } 407 408 define i32 @shady_range(i32 %argc, i8** nocapture %argv) uwtable { 409 %a.i = alloca [4 x %struct.Klass], align 16 410 %b.i = alloca [4 x %struct.Klass], align 16 411 %a8 = bitcast [4 x %struct.Klass]* %a.i to i8* 412 %b8 = bitcast [4 x %struct.Klass]* %b.i to i8* 413 ; I am used outside the lifetime zone below: 414 %z2 = getelementptr inbounds [4 x %struct.Klass], [4 x %struct.Klass]* %a.i, i64 0, i64 0, i32 0 415 call void @llvm.lifetime.start(i64 -1, i8* %a8) 416 call void @llvm.lifetime.start(i64 -1, i8* %b8) 417 %z3 = load i32, i32* %z2, align 16 418 %r = call i32 @foo(i32 %z3, i8* %a8) 419 %r2 = call i32 @foo(i32 %z3, i8* %b8) 420 call void @llvm.lifetime.end(i64 -1, i8* %a8) 421 call void @llvm.lifetime.end(i64 -1, i8* %b8) 422 ret i32 9 423 } 424 425 declare void @bar([100 x i32]* , [100 x i32]*) nounwind 426 427 declare void @llvm.lifetime.start(i64, i8* nocapture) nounwind 428 429 declare void @llvm.lifetime.end(i64, i8* nocapture) nounwind 430 431 declare i32 @foo(i32, i8*) 432