[LLVMbugs] [Bug 13563] New: miscompile of trivial sret example at -O0

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Aug 8 22:01:16 PDT 2012


             Bug #: 13563
           Summary: miscompile of trivial sret example at -O0
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: nlewycky at google.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

This tiny example:

target datalayout =
target triple = "x86_64-unknown-linux-gnu"

declare i8* @f() nounwind uwtable

define void @g(i8* noalias sret %result) nounwind uwtable {
  %a = alloca i8
  %b = call i8* @f()
  ret void

is miscompiled at llc -O0, but not llc -O2. We produce

g:                                      # @g
        subq    $24, %rsp
        movq    %rdi, 8(%rsp)           # 8-byte Spill
        callq   f
        movq    %rax, (%rsp)            # 8-byte Spill
        addq    $24, %rsp

which does not maintain the ABI guarantee that the value in %rax is the value
we were given in %rdi. Building with llc -O2 however, emits correct code:

g:                                      # @g
        pushq   %rbx
        subq    $16, %rsp
        movq    %rdi, %rbx
        callq   f
        movq    %rbx, %rax
        addq    $16, %rsp
        popq    %rbx

though it could be more optimal via. pushq %rdi / popq %rax and no wrangling
with %rbx at all.

Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list