[LLVMbugs] [Bug 15707] New: StackColoring can wrongly merge stack slots due to incorrect liveness calculation
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Mon Apr 8 21:27:17 PDT 2013
http://llvm.org/bugs/show_bug.cgi?id=15707
Bug ID: 15707
Summary: StackColoring can wrongly merge stack slots due to
incorrect liveness calculation
Product: tools
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: llc
Assignee: unassignedbugs at nondot.org
Reporter: mseaborn at chromium.org
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
StackColoring::calculateLiveIntervals() does not correctly handle the case
where the following sequence occurs in a basic block:
llvm.lifetime.start(%buf)
...
llvm.lifetime.end(%buf)
...
llvm.lifetime.start(%buf)
calculateLiveIntervals() ignores the second lifetime.start() and regards %buf
as not being live after the lifetime.end(). This will cause StackColoring to
merge stack slots that shouldn't be merged.
Example:
declare void @llvm.lifetime.start(i64, i8*)
declare void @llvm.lifetime.end(i64, i8*)
declare void @ext(i8*)
define void @foo() {
%buf1 = alloca i8, i32 10000, align 16
%buf2 = alloca i8, i32 10000, align 16
call void @llvm.lifetime.start(i64 -1, i8* %buf1)
call void @llvm.lifetime.end(i64 -1, i8* %buf1)
call void @llvm.lifetime.start(i64 -1, i8* %buf1)
call void @llvm.lifetime.start(i64 -1, i8* %buf2)
call void @ext(i8* %buf1)
call void @ext(i8* %buf2)
ret void
}
Expected output:
$ llc -mtriple=x86_64-none-gnu llvm_lifetime_bug.ll -O1 -o -
...
subq $20008, %rsp # imm = 0x4E28
.Ltmp1:
.cfi_def_cfa_offset 20016
leaq 10000(%rsp), %rdi
callq ext
leaq (%rsp), %rdi
callq ext
addq $20008, %rsp # imm = 0x4E28
ret
Actual output:
$ llc -mtriple=x86_64-none-gnu llvm_lifetime_bug.ll -O1 -o -
...
subq $10008, %rsp # imm = 0x2718
.Ltmp1:
.cfi_def_cfa_offset 10016
leaq (%rsp), %rdi
callq ext
leaq (%rsp), %rdi
callq ext
addq $10008, %rsp # imm = 0x2718
ret
The following change fixes the bug:
@@ -434,10 +446,8 @@ void StackColoring::calculateLiveIntervals(unsigned
NumSlots) {
if (Alive.any()) {
for (int pos = Alive.find_first(); pos != -1;
pos = Alive.find_next(pos)) {
- if (!Starts[pos].isValid())
- Starts[pos] = Indexes->getMBBStartIdx(MBB);
- if (!Finishes[pos].isValid())
- Finishes[pos] = Indexes->getMBBEndIdx(MBB);
+ Starts[pos] = Indexes->getMBBStartIdx(MBB);
+ Finishes[pos] = Indexes->getMBBEndIdx(MBB);
}
}
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130409/2cf30dd4/attachment.html>
More information about the llvm-bugs
mailing list