<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 20, 2016 at 11:33 PM, Sanjoy Das <span dir="ltr"><<a href="mailto:sanjoy@playingwithpointers.com" target="_blank">sanjoy@playingwithpointers.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Daniel,<br>
<span class=""><br>
On Thu, Oct 20, 2016 at 2:20 PM, Daniel Berlin via llvm-dev<br>
<<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br>
><br>
><br>
> On Thu, Oct 20, 2016 at 2:05 PM, Michael Kuperstein via llvm-dev<br>
> <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br>
>><br>
>> The fact two IR values are defined the same way doesn't necessarily imply<br>
>> they are actually the same value.<br>
><br>
><br>
> Is this true for anything other than memory (mainly curious) ?<br>
<br>
</span>Memory, and everything we pretend is memory. :) E.g. inline assembly,<br>
IO, @llvm.read_register.<br></blockquote><div><br></div><div>Sure.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class=""><br>
>>As Sanjoy said, though, it should always be legal to optimize all uses of<br>
>> different "freeze(%x)" values to use the same def - this is equivalent to<br>
>> >choosing the same value for all freezes. It's just not necessary to do so.<br>
><br>
> So just to be clear (mainly so i can go back to letting y'all hash this<br>
> out), in value numbering:<br>
><br>
> 1. I can value number all freeze operations on the same operand to the same<br>
> value<br>
>  *as long as*<br>
> 2. I  replace all freeze values of the same operand with a single one.<br>
><br>
> Or am i misunderstanding?<br>
<br>
</span>I have to think a bit more before committing to this, but to merely be<br>
*correct* I think optimizations should be able to pretend the<br>
"implementation" of freeze is:<br>
<br>
freeze(x):<br>
  if x is not poison: ;; This check is actually impossible to write in IR<br>
    return x<br>
  val = load atomic <ty>, <ty>* @global, unordered<br>
  return val<br>
<br>
where @global is not clobbered / written to by anything in the IR (so<br>
no stores/calls etc. alias the location), but is being concurrently<br>
written to by some other thread not visible to LLVM (so every load<br>
from @global is racing with that other thread).'<br></blockquote><div><br></div><div>Right, this is pretty much what i expected.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
This means while two instances of freeze(A) are not guaranteed to<br>
return the same value, they _can_ be CSE'ed (since that only decreases<br>
or "refines" the set of available behaviors).<br></blockquote><div><br></div><div>Right.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
In that respect, freeze is somewhat like a memory operation.<br>
<span class=""><br>
> If i've got it right, the issue i see with #2 is whether i can hoist freezes<br>
> or not.<br>
><br>
> If not, it may not be possible to cover all uses.<br>
><br>
> IE<br>
><br>
> if (a)  {<br>
>   %1 = freeze (%x)<br>
> } else if (b) {<br>
>   %2 = freeze (%x)<br>
> } else if (c){<br>
>   %3 = freeze (%x)<br>
> }<br>
><br>
> I cannot replace these with a single freeze def without placing a freeze<br>
> above the if block.<br>
<br>
</span>I don't think there is any problem with hoisting freezes, so you<br>
should be able to hoist the freeze out and CSE %1, %2 and %3 to the<br>
same instance of freeze.<br>
<br></blockquote><div><br></div><div>SGTM.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
(@Nuno: does that sound right ^?)<br>
<br>
Let me know if that answers your question.<br></blockquote><div><br></div><div>It does, thank you :)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class="HOEnZb"><font color="#888888"><br>
-- Sanjoy<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
> *If* i need to replace them all with the same freeze def in order to be able<br>
> to consider them the same value, either i need to be able to hoist them, or<br>
> i have to assume the freezes have different values, or  this makes value<br>
> numbering much harder (I basically have to make some implicit state explicit<br>
> like we do for memoryssa, where the implicit state is "state of the heap".<br>
> In this case, i would associate each freeze with a version based on the SSA<br>
> renaming algorithm, so i knew which freezes i could *ever* replace with<br>
> other existing freezes).<br>
><br>
> Normally the *value* doesn't depend on the location in the IR, and to the<br>
> degree it does, we try to make that explicit.<br>
><br>
> Again, just trying to understand, mainly so i know if i have to care or not.<br>
><br>
><br>
> On Thu, Oct 20, 2016 at 1:58 PM, Krzysztof Parzyszek via llvm-dev<br>
> <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br>
>><br>
>> In both of these cases, the expression tree in the IR is going to look<br>
>> like<br>
>>   == (freeze(%x), freeze(%x))<br>
>><br>
>> The %a and %b are just labels on values, which are defined in the exact<br>
>> same way. How do you differentiate these two?<br>
>><br>
>> If %a = freeze(%x), is %a+1 == %a+1?<br>
>><br>
>> -Krzysztof<br>
>><br>
>><br>
>><br>
>> On 10/20/2016 3:36 PM, Sanjoy Das wrote:<br>
>>><br>
>>> Hi Krzysztof,<br>
>>><br>
>>> Krzysztof Parzyszek wrote:<br>
>>>><br>
>>>> On 10/18/2016 4:29 PM, Nuno Lopes wrote:<br>
>>>>><br>
>>>>> Even %a and %b might not be the same in "%a = freeze(%x), %b =<br>
>>>>> freeze(%x)" (each freeze returns an arbitrary, but fixed, value).<br>
>>>><br>
>>>><br>
>>>> Assume that %x is known to be a poison value and have:<br>
>>>> %a = freeze(%x)<br>
>>>> %b = freeze(%x)<br>
>>>><br>
>>>> Is %a == %a true?<br>
>>><br>
>>><br>
>>> Yes, %a is always == %a.  It is a normal SSA value with some unspecific<br>
>>> content.<br>
>>><br>
>>>> Is %a == %b true?<br>
>>><br>
>>><br>
>>> Not necessarily; but the compiler can make it true by (consistently)<br>
>>> choosing equal values for %a and %b.<br>
>>><br>
>>> By consistently I mean it can't fold one instance of %a == %b to true<br>
>>> and fold another instance of %a == %b to false.<br>
>>><br>
>>> -- Sanjoy<br>
>><br>
>><br>
>> --<br>
>> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted<br>
>> by The Linux Foundation<br>
>> ______________________________<wbr>_________________<br>
>> LLVM Developers mailing list<br>
>> <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
><br>
><br>
><br>
> ______________________________<wbr>_________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
><br>
><br>
><br>
> ______________________________<wbr>_________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
><br>
</div></div></blockquote></div><br></div></div>