[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:15:36 PST 2012


On Tue, Jan 24, 2012 at 08:36:17AM -0800, Esperanza de Escobar wrote:
> No one is arguing that there aren't ABI specs or LLVM design
> guidelines that say that unaligned accesses "should not", "could not"
> or "aren't guaranteed to" work, because it's besides the point.

No, it is the core of the issue. Standard C gives the compiler certain
garantees and one of them is correct alignment of pointers to whatever
the platform wants. For some architectures, this is normally not enforced
(x86, ppc), on some violating results in traps (SPARC), on some it
results in unexpected behavior. Early ARM generations for example fall
into the last category.

> This introduces a stealth crash into Apple-only code that was bug-free
> under gcc. And realizing what's going on requires familiarity with ARM
> assembly. With a bit of googling you'll find other support board posts
> asking "Why is my code suddenly crashing after upgrading Xcode?"

Your code is buggy. Stop justifying it by saying that GCC doesn't
utilise optimisation potential. It has been proven over and over again,
that half of the cases where GCC misoptimises code turned out to be
completely broken assumptions by the code in question. Never versions of
GCC tended to expose new bugs. It's not a problem in the compiler. I
wouldn't be surprised if you get the same behavior with a recent GCC,
too.

> You can measure its damage pretty significantly, though. We've already
> spent a lot of hours tracking down unaligned accesses and wrapping
> them in assembly macros. Which of course ends up disabling other,
> actually useful optimizations. And with a large codebase, we can't be
> sure we've found every last one yet.

There is a warning about casts that change the alignment for a reason.
Sorry, but I have absolute no sympathy for case.

Joerg



More information about the llvm-dev mailing list