[llvm-commits] [PATCH] x86: Always emit displacements when parentheses are present

Nick Lewycky nicholas at mxc.ca
Fri Sep 30 00:41:39 PDT 2011


Kaelyn Uhrain wrote:
> Hi,
>
> In X86AsmPrinter::printLeaMemReference, immediate displacements for
> memory references currently are not being emitted if the memory
> reference has parentheses and the displacement is zero. This breaks
> inline assembly code that adds a constant to the displacement, e.g.:
> "leal 128+%0, %%edx" where %0 is a memory reference. Currently the
> emitted code would look like "leal 128+(%esp)" which triggers a warning
> (that an operand is missing and zero is being assumed) with GNU as and
> is not accepted at all by llvm-mc. With this patch "leal 128+0(%esp)" is
> emitted, which is happily accepted by both gas and llvm-mc.

Thanks for writing this! :)

+; Make sure we generate acceptable memory references for things like 
(in C):
+;    void test8(char *tmp) {
+;        __asm__ volatile(
+;    "	leal 128+%0,%%edx\n\t"
+;    	:
+;    	:"m"(tmp)
+;    	:"memory","%edx");
+;    }
+; CHECK: leal 128+0(%esp),%edx
+define void @test8(i8* %tmp) nounwind {

Also add "+; CHECK: test8" first, to make it clear that we can't match 
any leal earlier in the file.

Nick



More information about the llvm-commits mailing list