<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Sanjay,<div class=""><br class=""></div><div class="">I do not think this change is correct.</div><div class="">I have attached a test case with (before.ll) and without (after.ll) that change and the related C file (test.c).</div><div class="">To reproduce, compile with O1 or more and run the produced executable. The correct behavior is do not assert :).</div><div class=""><br class=""></div><div class="">Please revert or fix it.</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Oct 10, 2014, at 4:00 PM, Sanjay Patel <<a href="mailto:spatel@rotateright.com" class="">spatel@rotateright.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">Author: spatel<br class="">Date: Fri Oct 10 18:00:21 2014<br class="">New Revision: 219542<br class=""><br class="">URL: <a href="http://llvm.org/viewvc/llvm-project?rev=219542&view=rev" class="">http://llvm.org/viewvc/llvm-project?rev=219542&view=rev</a><br class="">Log:<br class="">Return undef on FP <-> Int conversions that overflow (PR21330).<br class=""><br class="">The LLVM Lang Ref states for signed/unsigned int to float conversions:<br class="">"If the value cannot fit in the floating point value, the results are undefined."<br class=""><br class="">And for FP to signed/unsigned int:<br class="">"If the value cannot fit in ty2, the results are undefined."<br class=""><br class="">This matches the C definitions.<br class=""></div></blockquote><div><br class=""></div><div>Yes, this matches the C definitions, but the rules of propagating the undef value are not strictly the same in C and LLVM IR AFAICT.</div><div>Here is an example:</div><div>In (pseudo) C,</div><div>a = undef // a is undef;</div><div>if (something)</div><div> b = val;</div><div>else</div><div> b = a; // b is undef, but it should be the same value as a.</div><div>assert (something || b == a);</div><div><br class=""></div><div>The related (pseudo) IR would be:</div><div>a = undef</div><div>b = select i1 something, val, a</div><div>cmpVal = cmp eq b, a</div><div>assertVal = or something, cmpVal</div><div>call assert(assertVal)</div><div><br class=""></div><div>Now, the actual IR will be, because of constant propagation:</div><div><div>b = select i1 something, val, undef // <— we lose the information that the next two undef are the same value.</div><div>cmpVal = cmp eq b, undef</div><div>assertVal = or something, cmpVal</div><div>call assert(assertVal)</div><div><br class=""></div><div>This is still fine as long as undef are expanded into the same constant.</div><div>However, the LangRef states that the following transformation is valid:</div><div><pre style="overflow-x: auto; overflow-y: hidden; font-family: Consolas, 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace; font-size: 0.95em; line-height: 15.960000038146973px; padding: 0.5em; border: 1px solid rgb(204, 204, 204); background-color: rgb(248, 248, 248);" class=""> <span class="nv" style="color: rgb(187, 96, 213);">%C</span> <span class="p">=</span> <span class="k" style="color: rgb(0, 112, 32); font-weight: bold;">select</span> <span class="nv" style="color: rgb(187, 96, 213);">%X</span><span class="p">,</span> <span class="nv" style="color: rgb(187, 96, 213);">%Y</span><span class="p">,</span> <span class="k" style="color: rgb(0, 112, 32); font-weight: bold;">undef</span>
<span class="nl" style="color: rgb(0, 32, 112); font-weight: bold;">Safe:</span>
<span class="nv" style="color: rgb(187, 96, 213);">%C</span> <span class="p">=</span> <span class="nv" style="color: rgb(187, 96, 213);">%Y</span>
<span class="nl" style="color: rgb(0, 32, 112); font-weight: bold;">Unsafe:</span>
<span class="nv" style="color: rgb(187, 96, 213);">%C</span> <span class="p">=</span> <span class="k" style="color: rgb(0, 112, 32); font-weight: bold;">undef</span></pre><div class="">Therefore, we end up with the following IR:</div></div><div><div>b = val // <— now, the value of b may not be a when ‘something' is false, which is incorrect. </div><div>cmpVal = cmp eq b, undef</div><div>assertVal = or something, cmpVal</div><div>call assert(assertVal)</div></div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">-Quentin</div><div class=""></div></div></div></div></body></html>