[LLVMdev] Use of 'ldrd' instructions with unaligned addresses on armv7 (Major bug in LLVM optimizer?)

Joerg Sonnenberger joerg at britannica.bec.de
Tue Jan 24 09:29:20 PST 2012


BTW as the question was asked on IRC: it is possible to force LLVM to
forget about the natural alignment of pointers. Examples are the packed
attribute on structures or using the align attribute on pointers.
consider the attached example for the latter. Notice the significant
difference in code size...

Joerg
-------------- next part --------------
A non-text attachment was scrubbed...
Name: unalignedptr.c
Type: text/x-csrc
Size: 106 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120124/5cfbce64/attachment.c>
-------------- next part --------------
	.syntax unified
	.eabi_attribute 20, 1
	.eabi_attribute 21, 1
	.eabi_attribute 23, 3
	.eabi_attribute 24, 1
	.eabi_attribute 25, 1
	.file	"unalignedptr.c"
	.text
	.globl	foo
	.align	2
	.type	foo,%function
foo:
	ldr	r0, .LCPI0_0
	ldrb	r1, [r0]
	ldrb	r2, [r0, #1]
	ldrb	r3, [r0, #2]
	ldrb	r0, [r0, #3]
	orr	r0, r3, r0, lsl #8
	orr	r1, r1, r2, lsl #8
	orr	r0, r1, r0, lsl #16
	ldr	r0, [r0]
	bx	lr
	.align	2
.LCPI0_0:
	.long	f
.Ltmp0:
	.size	foo, .Ltmp0-foo

	.globl	foo2
	.align	2
	.type	foo2,%function
foo2:
	ldr	r0, .LCPI1_0
	ldr	r0, [r0]
	ldr	r0, [r0]
	bx	lr
	.align	2
.LCPI1_0:
	.long	g
.Ltmp1:
	.size	foo2, .Ltmp1-foo2

	.type	f,%object
	.comm	f,4,4
	.type	g,%object
	.comm	g,4,4



More information about the llvm-dev mailing list