[LLVMbugs] [Bug 7882] New: Fast scheduler does not handle inline assembly clobbers

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Aug 13 07:29:45 PDT 2010


           Summary: Fast scheduler does not handle inline assembly
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Common Code Generator Code
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: amaury.pouly at gmail.com
                CC: llvmbugs at cs.uiuc.edu

The fast scheduler does not look at the clobbers register of inline assembly
instructions. Thus, it can miscompile code if the inline assembly destroys a
physical register like a flag.
Here is an hand written example that exhibit this behaviour, I'm not a very
experienced llvm bitcode written but it exhibit the bug on my computer.

; expected behaviour:
; if main is called with zero or one argument, returns 42, else 13
define i32 @main(i32 %argc, i8** %argv) nounwind
    %res = icmp slt i32 1, %argc
    %tmp = call i32 asm sideeffect alignstack
        "push $$0
         mov $$13, $0", "=r,r,~{memory},~{flags}" (i1 %res)
    %ret = select i1 %res, i32 %tmp, i32 42
    ret i32 %ret

It is built to force the scheduler order: compare THEN inline THEN select.

On X86 for example, the icmp will store the result in eflags, and select will
generate a cmov. But the push;popf will clobber the flags as indicated. The
fast scheduler won't see it and thus the flags will always be destroyed. This
example is for X86 only but the problem is completely general.

For completeness, the problem is located in
ScheduleDAGFast::DelayForLiveRegsBottomUp. The fix is simple and is already
implemented in the other schedulers

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