[LLVMbugs] [Bug 16572] New: thumb generates mov lr,pc
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Tue Jul 9 07:49:10 PDT 2013
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: unassignedbugs at nondot.org
Reporter: dwelch at dwelch.com
CC: llvmbugs at cs.uiuc.edu
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130709/1e4997b9/attachment.html>
More information about the llvm-bugs
mailing list