architecture-specific builtins and OpenCL

I'm trying to ascertain whether or not it is possible to use architecture-specific builtins (LLVM3.4.2) in OpenCL:

This compiles cleanly for my target when it has a .c extension:

void fred(unsigned long* in, unsigned long* where)
{
    *where = __builtin_coge_reverse(*in);
}

But this variant crashes very early when it is a .cl file:
void kernel fred(unsigned long *in, unsigned long* where)
{
    *where = __builtin_coge_reverse(*in);
}

I'm not even sure how to go about determining the source of problem - it crashes before generating any IR (-mllvm -print-after-all)

clang: /localspace/rcgorton/svn/Compiler/trunk/LLVM3_4/llvm-3.4.2.src/lib/IR/Instructions.cpp:2352: static llvm::CastInst* llvm::CastInst::Create(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, const llvm::Twine&, llvm::Instruction*): Assertion `castIsValid(op, S, Ty) && "Invalid cast!"' failed.

Is there a document somewhere which describes how to use various front-end-dumping switches? Is there a better way to attack this?

Thanks in advance,

  Richard
  rcgorton@cog-e.com

I originally posted this to llvmdev,but it strikes me that this might be a better place to make the query.

I originally posted this to llvmdev,but it strikes me that this might be a better place to make the query.

> I'm trying to ascertain whether or not it is possible to use architecture-specific builtins (LLVM3.4.2) in OpenCL:
>
> This compiles cleanly for my target when it has a .c extension:
>
> void fred(unsigned long* in, unsigned long* where)
> {
> *where = __builtin_coge_reverse(*in);
> }
>
> But this variant crashes very early when it is a .cl file:
> void kernel fred(unsigned long *in, unsigned long* where)
> {
> *where = __builtin_coge_reverse(*in);
> }
>

What is the input type does __builtin_coge_reverse() expect?

-Tom

I originally posted this to llvmdev,but it strikes me that this might be a better place to make the query.

> I'm trying to ascertain whether or not it is possible to use architecture-specific builtins (LLVM3.4.2) in OpenCL:
>
> This compiles cleanly for my target when it has a .c extension:
>
> void fred(unsigned long* in, unsigned long* where)
> {
> *where = __builtin_coge_reverse(*in);
> }
>
> But this variant crashes very early when it is a .cl file:
> void kernel fred(unsigned long *in, unsigned long* where)
> {

I just realized you are passing private pointers to your kernel. This is
not allowed in OpenCL. Does it work if you drop the kernel attribute?

-Tom

grep reverse ./include/llvm/IR/IntrinsicsCogE.td ./tools/clang/include/clang/Basic/BuiltinsCogE.def
./include/llvm/IR/IntrinsicsCogE.td:def int_coge_reverse: GCCBuiltin<"__builtin_coge_reverse">,
./tools/clang/include/clang/Basic/BuiltinsCogE.def:BUILTIN(__builtin_coge_reverse, "ULLiULLi", "nc")

unsigned long (uint64_t) as the input and result. Removing the 'kernel' keyword does not improve matters; the following .cl file also crashes
void fred(unsigned long *in, unsigned long* where, int id)
{
    where[id] = __builtin_coge_reverse(in[id]);
}

(I did not use any of the #pragmas or include <CL/cl.h>)

Regards,
  Richard
  rcgorton@cog-e.com

grep reverse ./include/llvm/IR/IntrinsicsCogE.td ./tools/clang/include/clang/Basic/BuiltinsCogE.def
./include/llvm/IR/IntrinsicsCogE.td:def int_coge_reverse: GCCBuiltin<"__builtin_coge_reverse">,
./tools/clang/include/clang/Basic/BuiltinsCogE.def:BUILTIN(__builtin_coge_reverse, "ULLiULLi", "nc")

unsigned long (uint64_t) as the input and result. Removing the 'kernel' keyword does not improve matters; the following .cl file also crashes

Does it still crash in the same place?

-Tom

grep reverse ./include/llvm/IR/IntrinsicsCogE.td ./tools/clang/include/clang/Basic/BuiltinsCogE.def
./include/llvm/IR/IntrinsicsCogE.td:def int_coge_reverse: GCCBuiltin<"__builtin_coge_reverse">,
./tools/clang/include/clang/Basic/BuiltinsCogE.def:BUILTIN(__builtin_coge_reverse, "ULLiULLi", "nc")

unsigned long (uint64_t) as the input and result. Removing the 'kernel' keyword does not improve matters; the following .cl file also crashes

Does it still crash in the same place?

-Tom

This crash looks vaguely familiar. The builtins don’t understand address spaces, and I remember in an older version clang would accept the implicit address space cast to a builtin, and 3.4 stopped allowing bitcast to be used. The clang problem was probably fixed later than that

Yes - something to do with the ::BITCAST op, but I can't figure out how to look at what is being fed in to build the IR.
Hmmm - I added __builtin_ia32_reverse() to -target x86_64, and when I compile that as a .cl function, I get "cannot compile this builtin function yet".

  Regards,
    Richard