[llvm-dev] Vectors in Sparc

James Y Knight via llvm-dev llvm-dev at lists.llvm.org
Fri Jan 29 10:28:38 PST 2016


Aha, thanks for the report.

This looks like a bug resulting from the work to support i64 on sparcv8.
The SparcV8 backend marks v2i32 as a legal type, in order to implement
64bit load/store. (It couldn't use i64, because marking an integral type
legal which doesn't have arithmetic legal causes a BUNCH of issues in the
ISel framework. Using v2i32 was much less problematic -- handling of
function calls and return values being essentially the only complication.)

Anyhow, it appears I missed one thing: to transform the result type back
from the two split-apart return registers, into a single v2i32 value. That
is, in the "Copy all of the result registers" loop at the end of
SparcTargetLowering::LowerCall_32, it needs to reconstruct a v2i32 from the
two RVLocs, just like the code in ARMTargetLowering::LowerCallResult does.

If you don't fix it yourself, could you open a bug report so I don't forget?

On Thu, Jan 28, 2016 at 6:25 PM, Chris.Dewhurst <Chris.Dewhurst at lero.ie>
wrote:

> Apologies. I had cut too much out from the file. The full file is as
> follows:
>
> typedef char vec8 __attribute__((vector_size(4)));
> typedef short vec16 __attribute__((vector_size(4)));
>
> extern vec8 foo1_8(void);
> extern vec8 foo2_8(void);
>
> vec8 fun8(void)
> {
>   return foo1_8 () & foo2_8 ();
> }
>
> extern vec16 foo1_16(void);
> extern vec16 foo2_16(void);
>
> vec16 fun16(void)
> {
>   return foo1_16 () & foo1_16 ();
> }
>
>
> I'm trying to get this working for Sparc v8. I tried the command-lines
> that you referred to James. The v8 one fails as I had before on the latest
> I had (not quite up-to-date with the trunk, but only about a week old). The
> v9 works, which I hadn't noticed before as I'm focussed on the v8 back-end.
>
> Chris.
> ------------------------------
> *From:* James Y Knight [jyknight at google.com]
> *Sent:* 28 January 2016 20:55
> *To:* Chris.Dewhurst
> *Cc:* llvm-dev at lists.llvm.org
> *Subject:* Re: [llvm-dev] Vectors in Sparc
>
> That test does not crash for me on trunk, neither with "clang -S -o -
> -target sparc test-sparc.c" nor "clang -S -o - -target sparcv9
> test-sparc.c" (I'm not sure which you meant). So, maybe it's been fixed, or
> maybe I'm not using the same commandline as you are.
>
> However, even if it doesn't crash, Clang certainly isn't implementing a
> correct ABI for vector types on SPARC. So don't expect interoperability
> with other compilers for functions that have vector params or returns.
>
> On Thu, Jan 28, 2016 at 2:22 PM, Chris.Dewhurst via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
>
>> The following code is causing me problems in the Sparc back-end and I
>> believe it's related to a lot of issues that I have, so I'd love to work
>> out what I need to do to resolve this. I'm currently not making much
>> headway into it. I'm going to try to simplify this to the core problem I
>> can see and hope I haven't missed anything relevant.
>>
>> The original code I have is as follows:
>>
>> typedef char vec8 __attribute__((vector_size(4)));
>>
>> extern vec8 foo1_8(void);
>> extern vec8 foo2_8(void);
>>
>> vec8 fun8(void)
>> {
>>   return foo1_8 () & foo2_8 ();
>> }
>>
>>
>> On x86, this compiles into this IR:
>>
>> ; Function Attrs: nounwind uwtable
>> define i32 @fun8() #0 !dbg !4 {
>>   %1 = tail call i32 @foo1_8() #2, !dbg !23
>>   %2 = tail call i32 @foo2_8() #2, !dbg !24
>>   %3 = and i32 %2, %1, !dbg !26
>>   ret i32 %3, !dbg !27
>> }
>>
>>
>> On Sparc, this compiles into this IR:
>>
>>
>> ; Function Attrs: nounwind
>> define <4 x i8> @fun8() #0 !dbg !4 {
>>   %1 = tail call <4 x i8> @foo1_8() #2, !dbg !23
>>   %2 = tail call <4 x i8> @foo2_8() #2, !dbg !24
>>   %3 = and <4 x i8> %2, %1, !dbg !26
>>   ret <4 x i8> %3, !dbg !27
>> }
>>
>>
>> When I try to compile this down to an object file using llc, I get this
>> error for Sparc (none for x86):
>>
>>    LowerCall didn't emit the correct number of values!
>>
>> It appears that the Sparc system doesn't know how to lower calls using
>> vectors. I need to either be able to (1) Work out how to get clang to
>> compile the Sparc code into something more similar to the x86 code, or (2)
>> to work out how to get the llc backend for sparc to know how to lower calls
>> containing vectors.
>>
>> I'd prefer to do the first of these and get the vectors represented as
>> registers. This seems more efficient.
>>
>> Any help pointing me in the right direction will be greatly appreciated.
>> I don't suppose there's anything as simple a a clang command-line flag that
>> will do this???
>>
>> Chris Dewhurst,
>> LERO, The Irish Software Research Centre,
>> University of Limerick.
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160129/af8da579/attachment-0001.html>


More information about the llvm-dev mailing list