[llvm-dev] Adding libcall support for Rust's new vector math library

93 views
Skip to first unread message

Jacob Lifshay via llvm-dev

unread,
Jun 7, 2021, 10:19:35 PM6/7/21
to llvm-dev, Jubilee Young
We're writing a vector math library for use with Rust's Project Portable SIMD, where we would like to have fast architecture-independent implementations of functions like vectorized cos that are available from Rust's `core` library, where the requirement is that it can't depend on system libraries such as libc or libm. In order to have Rust code run as fast as possible, we want to have the Rust compiler generate calls to LLVM intrinsics such as llvm.cos.v4f32 allowing LLVM to optimize those intrinsics and generate native instructions where available, otherwise generating calls to the Rust vector math library functions that implement the appropriate functions.

Tracking issue for vector math library with more details:

WIP vector math library:

What all is required to get LLVM to generate libcalls to our vector math library? Does this sound like a good plan?

Also, there are some math functions that don't currently have generic LLVM intrinsics, that several different architectures support, such as sinpi which is supported by AMDGPU (multiply input by 0.5 then use the `sin` instruction), OpenCL-flavored SPIR-V, Libre-SOC's SimpleV (not in LLVM yet), and probably others too.

Jacob Lifshay

Sjoerd Meijer via llvm-dev

unread,
Jun 8, 2021, 5:48:48 AM6/8/21
to llvm-dev, Jacob Lifshay, Jubilee Young
Sounds like a good plan to me, but perhaps others know more/better. 
Clang option -fveclib=​ can be used to specify a vector library, so I think the infrastructure is there and you'll just need to plumb in support for yours.   

Cheers.

From: llvm-dev <llvm-dev...@lists.llvm.org> on behalf of Jacob Lifshay via llvm-dev <llvm...@lists.llvm.org>
Sent: 08 June 2021 03:19
To: llvm-dev <llvm...@lists.llvm.org>
Cc: Jubilee Young <working...@gmail.com>
Subject: [llvm-dev] Adding libcall support for Rust's new vector math library
 

Jacob Lifshay via llvm-dev

unread,
Jun 9, 2021, 1:53:13 PM6/9/21
to Sjoerd Meijer, llvm-dev, Jubilee Young
On Tue, Jun 8, 2021, 02:48 Sjoerd Meijer <Sjoerd...@arm.com> wrote:
Sounds like a good plan to me, but perhaps others know more/better.

Thanks!
 
Clang option -fveclib=​ can be used to specify a vector library, so I think the infrastructure is there and you'll just need to plumb in support for yours.

Yeah, I'm aware the infrastructure already exists, I'm just not sure how I should add the new code -- which classes should I subclass/modify?

Jacob

Sjoerd Meijer via llvm-dev

unread,
Jun 10, 2021, 11:47:14 AM6/10/21
to Jacob Lifshay, llvm-dev, Jubilee Young

Yeah, I'm aware the infrastructure already exists, I'm just not sure how I should add the new code -- which classes should I subclass/modify?

I think you could do this by example. There is a front-end part, e.g. https://reviews.llvm.org/D53928, and there is back-end part, e.g. https://reviews.llvm.org/D53927.


From: Jacob Lifshay <program...@gmail.com>
Sent: 09 June 2021 18:52
To: Sjoerd Meijer <Sjoerd...@arm.com>
Cc: llvm-dev <llvm...@lists.llvm.org>; Jubilee Young <working...@gmail.com>
Subject: Re: [llvm-dev] Adding libcall support for Rust's new vector math library
 

Jacob Lifshay via llvm-dev

unread,
Jun 11, 2021, 2:39:33 AM6/11/21
to Sjoerd Meijer, llvm-dev, Jubilee Young
On Thu, Jun 10, 2021 at 8:47 AM Sjoerd Meijer <Sjoerd...@arm.com> wrote:
>
>
> > Yeah, I'm aware the infrastructure already exists, I'm just not sure how I should add the new code -- which classes should I subclass/modify?
>
> I think you could do this by example. There is a front-end part, e.g. https://reviews.llvm.org/D53928, and there is back-end part, e.g. https://reviews.llvm.org/D53927.

Thanks for the links!

Would we have to add support to clang in order to merge our patches,
or can we get away with just adding support to llvm and rustc for now
since the vector math library is going to be mostly used just through
rustc?

Jacob
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

Neil Henning via llvm-dev

unread,
Jun 14, 2021, 4:49:08 AM6/14/21
to llvm-dev
Not sure if I fully understand the question - but for our Burst HPC# compiler we just:
  • create our own TargetLibraryInfo
  • use `targetLibraryInfo.addVectorizableFunctions(descriptors);` to add scalar -> vector mappings
  • profit?
I can say that this has let us teach LLVM how to vectorize calls to math functions that don't have matching LLVM intrinsics (like acos/asin/etc).

-Neil.
--
Neil Henning
Senior Software Engineer Compiler

Jacob Lifshay via llvm-dev

unread,
Jun 21, 2021, 10:58:30 PM6/21/21
to Neil Henning, llvm-dev, Jubilee Young
On Mon, Jun 14, 2021 at 1:49 AM Neil Henning via llvm-dev <llvm...@lists.llvm.org> wrote:
Not sure if I fully understand the question - but for our Burst HPC# compiler we just:
  • create our own TargetLibraryInfo
From what I can see in D53927, we'd probably want to modify the existing TargetLibraryInfo rather than create a new one, since we are trying to get support into upstream LLVM rather than having to cram more stuff into rustc's LLVM glue code (which we're trying to upstream to LLVM as much as possible) and modifying the existing TargetLibraryInfo looks like what would work best.

Thanks everyone!

Jacob
Reply all
Reply to author
Forward
0 new messages