Issue 132085
Summary [StackColoring] Incorrect slot merging due to stackcoloring-lifetime-start-on-first-use
Labels llvm:codegen, miscompilation
Assignees
Reporter tmiasko
    In the program below, the allocation `a` and allocation `b` have overlapping
live ranges, so it should be impossible to observe them having the same
address. Nevertheless StackColoring merges stack slots for `a` and `b`.  This
is incorrect since addresses of those allocations might be captured by `g`.

```llvm
define void @f() {
start:
  %a = alloca [1000 x i8], align 1
  %b = alloca [1000 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 1000, ptr %a)
  call void @llvm.lifetime.start.p0(i64 1000, ptr %b)
  call void @g(ptr %a)
  call void @llvm.lifetime.end.p0(i64 1000, ptr %a)
  call void @g(ptr %b)
  call void @llvm.lifetime.end.p0(i64 1000, ptr %b)
  ret void
}
declare void @g(ptr %n)
```

```console
$ llc-21 a.ll -print-before=stack-coloring -print-after=stack-coloring
# Machine code for function f: IsSSA, TracksLiveness
Frame Objects:
  fi#0: size=1000, align=1, at location [SP+8]
  fi#1: size=1000, align=1, at location [SP+8]
<snip>
# *** IR Dump After Merge disjoint stack slots (stack-coloring) ***:
# Machine code for function f: IsSSA, TracksLiveness
Frame Objects:
  fi#0: size=1000, align=1, at location [SP+8]
  fi#1: dead
<snip>
```

This is caused by stackcoloring-lifetime-start-on-first-use (the default) where
stack coloring shrinks live range towards first use.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to