[Libclc-dev] Adding fabs to libclc

Peter Collingbourne peter at pcc.me.uk
Sat Mar 10 10:38:22 PST 2012


On Thu, Mar 01, 2012 at 11:43:32AM +0100, Gabriel Rodríguez wrote:
> Dear all, 
> 
> 
> I have been trying to add support for fabs() to libclc and later to the LLVM-PTX backend. 
> This looked simple enough, but I am having trouble starting with the libclc part. I have added 
> the following files: 
[snip]
> I find that the 
> definition is already different in LLVM IR: 
> 
> 
> 
> declare ptx_device double @llvm.fabs.f64(double) 
> declare double @llvm.sqrt.f64(double) nounwind readonly 
> 
> 
> Since I am unable to get LLVM to lower calls to llvm.fabs as "abs" instructions rather than 
> "call.uni", I suspect the declaration differences to be (at least in part) the culprit. Could someone 
> point me out in the right direction? 

Hi Gabriel,

It looks like LLVM does not currently have an llvm.fabs intrinsic.
The backend does seem to recognise certain patterns which it then uses
to emit FABS instructions, but I don't think we should rely on them
(for example, one of them assumes the presence of a full C standard
library).  You may want to look into what would be required to add
this intrinsic to LLVM.

Then the next step would be to teach the PTX backend about the abs
instruction (I grepped lib/Target/PTX for 'abs' but didn't get any
useful results, which would seem to suggest to me that it doesn't
have such support yet).  This shouldn't be too hard if you follow
the pattern given for cos and sin, etc.

Thanks,
-- 
Peter




More information about the Libclc-dev mailing list