Should we add noduplicate attribute on the function which contains a noduplicate function call?

Hello all,

I have a question related to noduplicate attribute.

For example, if I have the following source code:

attribute((noduplicate)) attribute((always_inline)) void wait () {
// some code
barrier();
// some code
}

attribute((noduplicate)) void barrier ();

void f () {
// some code
wait();
// some code
}

Sometimes I observed a phenomenon that SimplifyCFGPass would transform function f to:

void f () {
// some code
wait();
// some code
critedge:
// some code
wait();
// some code
}

After the execution of AlwaysInliner, the function f would be:

void f () {
// some code
barrier();
// some code
critedge:
// some code

barrier();
// some code
}

It seems that barrier call is duplicated in function f. I am wondering whether it is a bug of LLVM. Should we add noduplicate attribute on the function which contains a noduplicate function call?

Thanks.

Hi Yi-Hong,
It looks like you’re asking two questions here. First, your stated question.

The short answer is that LLVM’s noduplicate attribute is not semantically equivalent to OpenCL barriers. It was implemented to help support barriers, but it has LLVM defined semantics. Specifically, it is explicitly not transitive. The transitivity property was debated when I added the attribute, and due to its viral nature was rejected.

The recommended approach to building an OpenCL like compiler was to create a pass yourself that marked the transitive closure of callers of a noduplicate function as noduplicate. I believe this is still the advice. I recommend you dig up the original discussions between me and Chris Lattner about this for more context, if you need it.

Second, your example. In your example you have marked the function ‘wait’ with noduplicate, and simplifycfg is apparently duplicating it. This would be a bug in LLVM.

Cheers,

James

Hello James,

Thanks for your reply.

My apologies that I mark the function ‘wait’ with noduplicate in the above example. In fact I didn’t use attribute((noduplicate)) with function ‘wait’ in my implementation so there is no bug in LLVM. I would dig up the original discussions between you and Chris Lattner for more context.

Thanks.

Hello,

According to the previous conclusion, LLVM’s noduplicate attribute is not semantically equivalent to OpenCL barriers. I am wondering whether it would be an potential issue for Clang to translate OpenCL to SPIR. If so, is it valuable to develop a specific LLVM pass that ‘marked the transitive closure of callers of a noduplicate function as noduplicate’ and push it into the mainline?

Thanks.