http://llvm.org/bugs/show_bug.cgi?id=16572

            Bug ID: 16572
           Summary: thumb generates mov lr,pc
           Product: new-bugs
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

Created attachment 10841
  --> http://llvm.org/bugs/attachment.cgi?id=10841&action=edit
picojpeg.c code generates this backend problem.

While compiling the open source picojpeg code with llvm 3.3 it generates code
like this

    mov    lr, pc
    bx    r6

In thumb mode, and the code it is calling with the bx has code that uses this

push {...,lr}
pop {...,pc}

Which is just bad form, a bx should be used (pop {rn}; bx rn) not pop {pc}, in
either case the lr does not have the lsbit set, because mov lr,pc does not set
the lsbit (the pc does not have the lsbit set in thumb mode it is stripped by
bl,bx,blx) so when it returns after this combination

    mov    lr, pc
    bx    r6
        ;returns here ideally

which is thumb code, if the processor is a cortex-m then it is game over
because you tried to switch to arm mode (in that case I would hope to see an
exception, but didnt test it there), if it is not a cortex-m then it returns in
arm mode and tries to execute the thumb instructions as arm instructions and
unpredictable results will occur.

Naturally with more code in the project, and llvm-linking the project and
optimizing the whole thing the problem can move around but the attached code
with this makefile generates the mov lr,pc with clang+llvm 3.3


OOPS = -std-compile-opts -strip-debug -disable-simplify-libcalls
LOPS = -Wall -m32 -emit-llvm 
LLCOPS = -march=thumb -disable-simplify-libcalls 

picojpeg.s : picojpeg.c
    clang $(LOPS) -c picojpeg.c -o picojpeg.bc
    opt $(OOPS) picojpeg.bc -o picojpeg.opt.bc
    llc $(LLCOPS) picojpeg.opt.bc -o picojpeg.s

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to