One element vectors versus scalars

I am curious as to why LLVM has explicit support for 1 element vectors, for example ‘v1i32’. Are there some contexts where handling a value as a 1 element vector can yield better code quality than the corresponding scalar ‘i32’?

Thanks,

MartinO

From: "Martin J. O'Riordan via llvm-dev" <llvm-dev@lists.llvm.org>
To: "LLVM Developers" <llvm-dev@lists.llvm.org>
Sent: Tuesday, November 10, 2015 6:00:27 AM
Subject: [llvm-dev] One element vectors versus scalars

I am curious as to why LLVM has explicit support for 1 element
vectors, for example ‘ v1i32 ’. Are there some contexts where
handling a value as a 1 element vector can yield better code quality
than the corresponding scalar ‘ i32 ’?

Hi Martin,

No, but I see two reasons we support 1-element vectors:

1. Having 1-element vectors makes a lot of the SDAG legalization code simpler, allowing us to separate the code that splits vector types from the code that transforms 1-element vectors into scalars.

2. On some platforms, there are ABI differences between the two types. (e.g. i128 and <1 x i128> are passed in different registers across function-call boundaries).

-Hal

Thanks Hal. In our case the ABI issue doesn't arise, but I'll have to think about the legalization to see if maybe we could write our type definitions better.

  MartinO