<br><br><div class="gmail_quote">2009/8/28 Kenneth Uildriks <span dir="ltr"><<a href="mailto:kennethuil@gmail.com">kennethuil@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

Suppose I have some LLVM assembly like this:<br>
<br>
declare i8* @CreateDistinctItem() nounwind<br>
<br>
declare void @dumpBoolean(i1 %val)<br>
<br>
define i32 @main()<br>
{<br>
 %var1 = call i8* CreateDistinctItem()<br>
 %var2 = call i8* CreateDistinctItem()<br>
 %isEqual = icmp eq i8* %val1, %val2<br>
 call void @dumpBoolean(i1 %isEqual)<br>
 ret i32 0<br>
}<br>
<br>
So far so good.  But if I take out the "call @dumpBoolean", the<br>
optimizer still leaves me with two calls to CreateDistinctItem,<br>
because it assumes that CreateDistinctItem might have side-effects.<br>
<br>
Now if I add the "readonly" flag to CreateDistinctItem and put back<br>
the "call @dumpBoolean", the optimizer now assumes that<br>
CreateDistinctItem always returns the *same* item, and optimizes the<br>
whole body of main down to:<br>
<br>
define i32 @main()<br>
{<br>
 tail call void @dumpBoolean(i1 true)<br>
 ret i32 0<br>
}<br>
<br>
which is totally wrong.<br>
<br>
This is by design, of course, (CreateDistinctItem does not return the<br>
same value given the same caller-visible global state) but I see no<br>
way to declare a function that:<br>
<br>
1. Returns a distinct item each time it's called,</blockquote><div><br>Attach a 'noalias' attribute to the return type in your function declaration. See <a href="http://llvm.org/docs/LangRef.html#paramattrs">http://llvm.org/docs/LangRef.html#paramattrs</a><br>

 </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
2. Doesn't need to be called at all if its return value from that call<br>
isn't used, and<br>
3. Doesn't even need to be declared if its return value is *never* used.</blockquote><div><br>Thus far these still need a custom pass. It shouldn't be too hard though. See <a href="http://wiki.llvm.org/HowTo:_Find_all_call_sites_of_a_function">http://wiki.llvm.org/HowTo:_Find_all_call_sites_of_a_function</a><br>

<br>You're the second user I know of to ask for this. We should probably come up with a general solution of some sort.<br><br>Nick<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">


If I happen to know about CreateDistinctItem at build time, I can<br>
write a custom pass, of course, but I was wondering if there was an<br>
easier way to get the standard optimizers to recognize it, or if y'all<br>
think it's worthwhile to add an easier way.<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">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/mailman/listinfo/llvmdev</a><br>
</blockquote></div><br>