Adding fabs to libclc

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:

generic/include/clc/math/fabs.h ---------------------------

#undef fabs
#define fabs __clc_fabs

#define FUNCTION __clc_fabs
#define INTRINSIC “llvm.fabs”
#include <clc/math/unary_intrin.inc>

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,