Issue 234047
Summary [Inliner] byval copy of x86_fp80 is sized with the store size (10 bytes) instead of the allocation size (16 bytes)
Labels miscompilation, llvm:transforms, generated by fuzzer
Assignees
Reporter ChoKyuWon
    ### reproducer
godbolt: https://godbolt.org/z/14a8W5ff7
alive: https://alive2.llvm.org/ce/z/48RY6x

```llvm
define internal i8 @callee(ptr byval(x86_fp80) %p) {
  %q = getelementptr i8, ptr %p, i64 10
 %v = load i8, ptr %q, align 1
  ret i8 %v
}

define i8 @f() {
  %p = alloca [16 x i8], align 16
  %q = getelementptr i8, ptr %p, i64 10
  store i8 -86, ptr %q, align 1
  %r = call i8 @callee(ptr byval(x86_fp80) %p)
 ret i8 %r
}
```

```console
$ opt -passes=inline -S repro.ll | grep -A1 'call void @llvm.memcpy'
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %p1, ptr %p, i64 10, i1 false)
  %q.i = getelementptr i8, ptr %p1, i64 10

$ opt -passes=inline,sroa,instcombine -S repro.ll | grep -A1 'define i8 @f'
define i8 @f() {
  ret i8 undef

# same input with byval([16 x i8]), which has the same allocation size
$ opt -passes=inline,sroa,instcombine -S control.ll | grep -A1 'define i8 @f'
define i8 @f() {
  ret i8 -86

# alive link: @src = "" of control.ll after -passes=inline, @tgt = @f of repro.ll after -passes=inline
$ alive-tv --disable-undef-input --disable-poison-input src-tgt.ll
ERROR: Target is more poisonous than source
Source value: #xaa (170, -86)
Target value: poison
```

### suggested fix
LangRef defines the byval copy as a memcpy of the type's allocation size, but `HandleByValArgumentInit` (InlineFunction.cpp) sizes it with `getTypeStoreSize(ByValType)`, which is smaller for `x86_fp80` and integers such as `i24`.
Use `getTypeAllocSize(ByValType)`, as SelectionDAG call lowering and MemCpyOpt's byval forwarding do.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to