llvm.org GIT mirror llvm / c22cdb7
Fix miscompile due to StackColoring incorrectly merging stack slots (PR15707) IR optimisation passes can result in a basic block that contains: llvm.lifetime.start(%buf) ... llvm.lifetime.end(%buf) ... llvm.lifetime.start(%buf) Before this change, calculateLiveIntervals() was ignoring the second lifetime.start() and was regarding %buf as being dead from the lifetime.end() through to the end of the basic block. This can cause StackColoring to incorrectly merge %buf with another stack slot. Fix by removing the incorrect Starts[pos].isValid() and Finishes[pos].isValid() checks. Just doing: Starts[pos] = Indexes->getMBBStartIdx(MBB); Finishes[pos] = Indexes->getMBBEndIdx(MBB); unconditionally would be enough to fix the bug, but it causes some test failures due to stack slots not being merged when they were before. So, in order to keep the existing tests passing, treat LiveIn and LiveOut separately rather than approximating the live ranges by merging LiveIn and LiveOut. This fixes PR15707. Patch by Mark Seaborn. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181922 91177308-0d34-0410-b5e6-96231b3b80d8 Derek Schuff 6 years ago
2 changed file(s) with 30 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
428428 }
429429
430430 // Create the interval of the blocks that we previously found to be 'alive'.
431 BitVector Alive = BlockLiveness[MBB].LiveIn;
432 Alive |= BlockLiveness[MBB].LiveOut;
433
434 if (Alive.any()) {
435 for (int pos = Alive.find_first(); pos != -1;
436 pos = Alive.find_next(pos)) {
437 if (!Starts[pos].isValid())
438 Starts[pos] = Indexes->getMBBStartIdx(MBB);
439 if (!Finishes[pos].isValid())
440 Finishes[pos] = Indexes->getMBBEndIdx(MBB);
441 }
431 BlockLifetimeInfo &MBBLiveness = BlockLiveness[MBB];
432 for (int pos = MBBLiveness.LiveIn.find_first(); pos != -1;
433 pos = MBBLiveness.LiveIn.find_next(pos)) {
434 Starts[pos] = Indexes->getMBBStartIdx(MBB);
435 }
436 for (int pos = MBBLiveness.LiveOut.find_first(); pos != -1;
437 pos = MBBLiveness.LiveOut.find_next(pos)) {
438 Finishes[pos] = Indexes->getMBBEndIdx(MBB);
442439 }
443440
444441 for (unsigned i = 0; i < NumSlots; ++i) {
349349 ret i32 0
350350 }
351351
352
353 ; Regression test for PR15707. %buf1 and %buf2 should not be merged
354 ; in this test case.
355 ;YESCOLOR: myCall_pr15707
356 ;YESCOLOR: subq $200008, %rsp
357 ;NOCOLOR: myCall_pr15707
358 ;NOCOLOR: subq $200008, %rsp
359 define void @myCall_pr15707() {
360 %buf1 = alloca i8, i32 100000, align 16
361 %buf2 = alloca i8, i32 100000, align 16
362
363 call void @llvm.lifetime.start(i64 -1, i8* %buf1)
364 call void @llvm.lifetime.end(i64 -1, i8* %buf1)
365
366 call void @llvm.lifetime.start(i64 -1, i8* %buf1)
367 call void @llvm.lifetime.start(i64 -1, i8* %buf2)
368 %result1 = call i32 @foo(i32 0, i8* %buf1)
369 %result2 = call i32 @foo(i32 0, i8* %buf2)
370 ret void
371 }
372
373
352374 ; Check that we don't assert and crash even when there are allocas
353375 ; outside the declared lifetime regions.
354376 ;YESCOLOR: bad_range