[LLVMdev] Alignments in LLVM IR

Tim Northover t.p.northover at gmail.com
Tue Apr 15 09:06:37 PDT 2014


> - Do alignments provide additional semantics to be obeyed by the compiler or are they just hints that can be ignored?

As John said, hints. You should be able to replace all alignments by
"align 1" without changing the output (assuming the code still
compiles).

> - What is the semantics of alignments from the perspective of an IR analyzer as opposed to an IR emitter?
> - Can you give me an example where wrong alignments lead to undefined behavior?

Well, at runtime some CPUs can be configured to raise an exception if
the access is unaligned. That's pretty undefined.

At compile time, I think we use alignments to convert "add %addr, 3"
into "or %addr, 3" (and so on) in some cases. That wouldn't go well if
the alignment was incorrect.

There are probably other transformations too, any optimisation making
use of that information is a candidate.

Cheers.

Tim.



More information about the llvm-dev mailing list