Expand vector type

Hello,

My input language has support for 3 and 4 element vectors but my target only has support for the latter. The language defines vec3 with the same storage space as vec4 so from a backend perspective they are both the same. I’d really like if I could have LLVM treat vec3 as vec4 but I haven’t found out how.

Currently the target has emulated support for vec3 through LLVM. Loads are already widened by LLVM to a vec4. Stores are kind of funny. By default LLVM sets the action to ‘widen’ but in GenWidenVectorStores what ends up happening is an 2:1 split of the vector that’s less efficient in this case than actually widening the vector. The reason is that at this point the call to FindMemType assumes that stores can never be widened to a bigger type and so those types are not considered. The call sequence I’m looking at is WidenVectorOperand() → WidenVecOp_STORE() → GenWidenVectorStores() → FindMemType(). I’ve made a very small modification to enable support for widening stores to a larger type.

Before spending more time on working on a generic solution I have a couple of questions:

  • Is there a way to setup LLVM to automatically convert vec3s to vec4s?

  • Is there interest in adding support for widened vector stores to a larger type?

Thanks,

Javier

Hi,

  • Is there a way to setup LLVM to automatically convert vec3s to vec4s?

Yes, if you specify v3i16 and friends as “promote” instead of “legal”, llvm will promote it to a v4i16. The ARM NEON backend does this already. I’m surprised you haven’t got this happening already as you mention that LLVM widens your loads to 4-element vectors… (this should happen during DAG type legalization, by the way).

Cheers,

James

James,

Thanks for your response. I’m working in LLVM 2.7 (I know, it’s old) and the default behavior is already promote. This means that for example a call to DAGTypeLegalizer::getTypeAction(v3i32) in my case and I presume in ARM NEON returns TypeWidenVector. From here legalization calls WidenVectorOperand() to process the STORE node and follows the call chain I have on my original email to FindMemType().

If my analysis is correct then your v316 STOREs are being broken into multiple ones depending on ARM NEON support. Can you please confirm?

Thanks,

Javier

I still haven’t received any feedback on me adding support for widening of stores. Is there interest?

Thanks,

Javier

Hi Javier,

I still haven’t received any feedback on me adding support for widening of
stores. Is there interest?

did you try LLVM 3.0?

Ciao, Duncan.

Hi Duncan,

I somehow missed your reply. I didn't try 3.0 but looking at the code in the truck the behavior is the same. The original email has the call sequence I expect in 3.0. The value returned from FindMemType() is the same in 2.7 and 3.0 a vec2 if that's a legal type for the target.

I'm my opinion it's the target that should be in charge of deciding how the types are converted but in this case the value returned by TLI.getTypeToTransformTo() is not the one used.

Thanks,
Javier