[llvm-dev] MCRegisterClass mandatory vs preferred alignment?

Matthias Braun via llvm-dev llvm-dev at lists.llvm.org
Mon Aug 31 15:59:26 PDT 2015

Looks to me like the alignment is specified in tablegen. From Target.td:

class RegisterClass<string namespace, list<ValueType> regTypes, int alignment,
                    dag regList, RegAltNameIndex idx = NoRegAltName>


def VR256 : RegisterClass<"X86", [v32i8, v16i16, v8i32, v4i64, v8f32, v4f64],
                          256, (sequence "YMM%u", 0, 15)>;
def VR256X : RegisterClass<"X86", [v32i8, v16i16, v8i32, v4i64, v8f32, v4f64],
                          256, (sequence "YMM%u", 0, 31)>;

Seems to be 256bits/32bytes.

I don't know why the alignment was specified the way it is. My guess would be because memory accesses are faster that way (because they do not cross cache lines for example).

- Matthias

> On Aug 31, 2015, at 3:21 PM, Philip Reames via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> Looking around today, it appears that TargetRegisterClass and MCRegisterClass only includes a single alignment.  This is documented as being the minimum legal alignment, but it appears to often be greater than this in practice.  For instance, on x86 the alignment of %ymm0 is listed as 32, not 1.  Does anyone know why this is?
> Additionally, where are these alignments actually defined?  I don't seem them appearing in the X86RegisterInfo.td files as I would naively expect.
> The background for my question is that I'm looking into adding a function attribute which uses unaligned loads and stores for register spilling on x86 to avoid the need for dynamic frame realignment.  (see the previous thread "Aligned vector spills and variably sized stack frames")  The key difference w.r.t. to the existing "no-realign-stack" attribute is that situations which *require* a stack realignment will generate a fatal_error rather than silently miscompiling.  The current mechanism works by essentially ignoring the alignment criteria and just hoping everything works out in practice.
> Philip
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

More information about the llvm-dev mailing list