Hi Yi-Hong,<br>It looks like you're asking two questions here. First, your stated question. <br><br>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. <br><br>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. <br><br>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.<br><br>Cheers,<br><br>James<br><div class="gmail_quote">On Tue, 10 Feb 2015 at 22:17, Yi-Hong Lyu <<a href="mailto:b95705030@ntu.edu.tw">b95705030@ntu.edu.tw</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello all,<br><br>I have a question related to noduplicate attribute.<br><br>For example, if I have the following source code:<br><br>__attribute__((noduplicate)) __attribute__((always_inline)) void wait () {<br>    // some code<br>    barrier();<br>    // some code<br>}<br><br>__attribute__((noduplicate)) void barrier ();<br><br>void f () {<br>    // some code<br>    wait();<br>    // some code<br>}<br><br>Sometimes I observed a phenomenon that SimplifyCFGPass would transform function f to:<br><br>void f () {<br>    // some code<br>    wait();<div>    // some code<br>critedge:</div><div>    // some code<br>    wait();<br>    // some code<br>}<br><br>After the execution of AlwaysInliner, the function f would be:<br><br>void f () {<br>    // some code<br>    barrier();</div><div>    // some code<br>critedge:<br>    // some code<br></div><div>    barrier();<br>    // some code<br>}<br><br>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?<br><br>Thanks.</div></div>
______________________________<u></u>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvmdev</a><br>
</blockquote></div>